summaryrefslogtreecommitdiff
path: root/nixos/rebuild
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2024-11-29 07:38:10 +0100
committerMartin Fischer <martin@push-f.com>2024-12-11 08:37:49 +0100
commitb2bd12c7c0039c33b81e1e88b825e1606ee899e2 (patch)
tree086e64c980ea2da3b555f2a3cd8e2d4fcde29f6f /nixos/rebuild
parentdfb73342a094871a54185d90841430be087e109c (diff)
refactor: enable host-specific configuration
Diffstat (limited to 'nixos/rebuild')
-rwxr-xr-xnixos/rebuild28
1 files changed, 24 insertions, 4 deletions
diff --git a/nixos/rebuild b/nixos/rebuild
index 98101c1..3cb086e 100755
--- a/nixos/rebuild
+++ b/nixos/rebuild
@@ -1,10 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
-# nix-instantiate --eval has no raw mode yet
-nixpkgsPath=$(nix-instantiate --eval --read-write-mode nixpkgs/path.nix | tr -d \")
-# Get the ./configuration.nix relative to this script
-configPath=$(realpath -- "$(dirname -- "${BASH_SOURCE[0]}")/configuration.nix")
+# Enable all future paths in this script to be relative to the directory containing the script.
+cd "$(dirname -- "${BASH_SOURCE[0]}")"
+
+configPath=$(realpath -- "$HOSTNAME-configuration.nix")
+
+if [ ! -f $configPath ]; then
+ echo "aborting: $configPath doesn't exist"
+ exit 1
+fi
+
+firstLine=$(head -n1 "$configPath")
+
+if ! echo "$firstLine" | grep -E ^"# channel *=" > /dev/null; then
+ echo "aborting: $configPath doesn't start with \`# channel=\"...\"\`, where ... is a pin from sources.json"
+ exit 1
+fi
+
+nix-eval() {
+ nix-instantiate --eval --read-write-mode "$@" \
+ | tr -d \" # nix-instantiate has no raw output yet (like the experimental nix eval)
+}
+
+channel=$(nix-eval --argstr line "$(echo $firstLine | tr -d \#)" --expr '{line}: (builtins.fromTOML line).channel')
+nixpkgsPath=$(nix-eval --argstr channel "$channel" --expr '{channel}: (import ./npins).${channel}.outPath')
# nixos-rebuild always reads Nixpkgs from the NIX_PATH,
# so we need to set it explicitly to our pinned version