Rebuild: Separate evaluation

This commit is contained in:
Geoffrey Frogeye 2025-01-23 18:17:01 +01:00
parent fafc4d45b7
commit cd4536c53b
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
2 changed files with 9 additions and 5 deletions

View file

@ -153,6 +153,7 @@
runtimeInputs = with pkgs; [
nix-output-monitor
nixos-rebuild
jq
];
text = builtins.readFile ./os/rebuild.sh;
}

View file

@ -24,12 +24,15 @@ then
exit 2
fi
info "Building"
tmpdir="$(mktemp -d)"
info "Evaluating"
# Evaluating can take a lot of memory, and Nix doesn't free it until the program ends,
# which can be limiting on memory-constrained devices. Hence the build step is separate.
# nix eval doesn't use the eval cache, so we do a nix build --dry-run
# sudo so the eval cache is shared with nixos-rebuild
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
toplevel="$(readlink -f "$tmpdir/toplevel")"
rm -rf "$tmpdir"
toplevel=$(time sudo nix build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" --dry-run --json | jq '.[0].outputs.out' -r)
info "Building"
sudo nom build "$toplevel" --no-link "$@"
info "Showing diff"
nvd diff "$(readlink -f /nix/var/nix/profiles/system)" "$toplevel"