diff --git a/nix b/nix.attrs similarity index 59% rename from nix rename to nix.attrs index 1b52b6a..2af3efc 100644 --- a/nix +++ b/nix.attrs @@ -1,4 +1,3 @@ -# cat nix | grep -v '^#' | while read -r drv; do nix-env -q "${drv%%_*}" || nix-env -iA nixpkgs."${drv}"; done bat borgbackup ccache diff --git a/nix.channel b/nix.channel new file mode 100644 index 0000000..01d8880 --- /dev/null +++ b/nix.channel @@ -0,0 +1 @@ +https://github.com/NixOS/nixpkgs/archive/14d9b465c71.tar.gz diff --git a/nix.sh b/nix.sh new file mode 100755 index 0000000..32b1489 --- /dev/null +++ b/nix.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +function setup() { + if grep -e 'experimental-features' /etc/nix/nix.conf; then + : + else + echo 'experimental-features = nix-command flakes' | sudo tee -a /etc/nix/nix.conf + fi +} + +function save() { + commit=$(nix-instantiate --eval -E '(import {}).lib.version' | perl -n -e '/".*\.([a-z0-9]+)"/ and print "$1\n"') + channel="https://github.com/NixOS/nixpkgs/archive/${commit}.tar.gz" + echo "saving: ${channel}" + echo "${channel}" > nix.channel +} + +function install() { + channel="$(cat nix.channel)" + echo "using: ${channel}" + + declare -a attrs=() + while IFS='' read -r line || [[ -n "${line}" ]]; do + attrs+=("${line}") + done < nix.attrs + + declare -a args=() + for attr in "${attrs[@]}"; do + args+=("-A" "${attr}") + done + + nix-env -f "${channel}" -i "${args[@]}" +} + +function update() { + nix-channel --update + save + install +} + +function usage() { + echo 'usage: nix.sh [setup|save|install|update]' 1>&2 + exit 1 +} + +case "${1:-}" in + setup) + setup + ;; + save) + save + ;; + install) + install + ;; + update) + update + ;; + upgrade) + upgrade + ;; + *) + usage + ;; +esac