Persist nix channel state

This commit is contained in:
Loic Nageleisen 2023-03-13 12:28:29 +01:00
parent b581ef9912
commit cab8bbd2d5
Signed by: lloeki
GPG key ID: D05DAEE6889F94C2
3 changed files with 70 additions and 1 deletions

View file

@ -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

1
nix.channel Normal file
View file

@ -0,0 +1 @@
https://github.com/NixOS/nixpkgs/archive/14d9b465c71.tar.gz

69
nix.sh Executable file
View file

@ -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 <nixpkgs> {}).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