scripts/deploy: separate eval and build phases to decrease maximum ram requirements

This commit is contained in:
2024-09-08 20:36:54 +00:00
parent bb18f65ed2
commit 1067bc9215

View File

@@ -154,10 +154,16 @@ deployOneHost() {
local host="$1"
local variant="$2"
info "building $host$variant ..."
destructive nix-build -A "hosts.$host$variant.toplevel" --out-link "./build/result-$host$variant" "${nixArgs[@]}" || return 1
storePath="$(readlink ./build/result-$host$variant)"
info "build $host$variant -> $storePath"
# `nix-build -A foo` evals and then realizes foo, but it never unloads the memory used to eval foo.
# my exprs are heavyweight, we need that memory for building, so do the evals separately from the realizations:
info "evaluating $host$variant..."
local drvPath=$(nix eval --raw -f . "hosts.$host$variant.toplevel.drvPath")
info "building $host$variant ($drvPath)"
local storePath=$(destructive nix-store --realize "$drvPath" "${nixArgs[@]}")
if [ -z "$storePath" ]; then
return 1
fi
info "built $host$variant -> $storePath"
# mimic `nixos-rebuild --target-host`, in effect:
# - nix-copy-closure ...