blob: 9e62b336d9ae814234f0ac7cdce758e965d18bd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#!/usr/bin/env bash
set -euo pipefail
top=$(dirname "$(realpath "$0")")
configPath="$top/hosts/$HOSTNAME/default.nix"
if [ ! -f $configPath ]; then
echo "aborting: $configPath doesn't exist"
exit 1
fi
nixpkgsPath=$(
cd "$top" &&
nix-instantiate --eval --raw \
--argstr host "$HOSTNAME" \
--expr '
{ host }:
let
toml = builtins.readFile ./hosts/${host}/metadata.toml;
channel = (builtins.fromTOML toml).channel;
in
(import ./npins).${channel}.outPath
'
)
(
# The result symlink created in the current directory is registered as a root of the Nix
# garbage collector, so it's important that we call nixos-rebuild from the host directory.
# (nix-build has an --out-link option but that option cannot be set via nixos-rebuild).
cd $top/hosts/$HOSTNAME &&
# nixos-rebuild always reads Nixpkgs from the NIX_PATH,
# so we need to set it explicitly to our pinned version
exec nixos-rebuild "$@" -I nixpkgs="$nixpkgsPath" -I nixos-config="$configPath" -I top="$top"
)
|