blob: 3589dc483b32e24a2f1cc80e2b31d0ea0f39f7e3 (
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
|
#!/usr/bin/env bash
set -euo pipefail
top=$(dirname "$(realpath "$0")")
hostDir="$top/hosts/$HOSTNAME"
if [ ! -d "$hostDir" ]; then
echo "aborting: host directory $hostDir doesn't exist"
exit 1
fi
# Make the configuration repository's commit available to the NixOS module.
export NIXOS_CONFIG_REVISION
NIXOS_CONFIG_REVISION=$(git -C "$top" rev-parse --verify HEAD)
if [[ -n $(git -C "$top" status --porcelain) ]]; then
NIXOS_CONFIG_REVISION+="-dirty"
fi
(
# 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 "$hostDir" &&
exec nixos-rebuild "$@" --file "$top/default.nix" --attr "configurations.$HOSTNAME"
)
|