summaryrefslogtreecommitdiffstats
path: root/krops.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-24 05:19:43 +0000
committertv <tv@krebsco.de>2026-11-24 05:37:16 +0000
commit633d477ca424f3c56cc338d1820eb9d8adfca1a8 (patch)
tree7c3d0092bdd09cbbf2be0f82a18951d1615912a2 /krops.nix
parentaa7aa8eef42738ba7dcaaa270a4762433433595c (diff)
krops.nix: keep builders' GC roots only while deploying
Diffstat (limited to 'krops.nix')
-rw-r--r--krops.nix27
1 files changed, 17 insertions, 10 deletions
diff --git a/krops.nix b/krops.nix
index bc5ef8f2..2273ef8d 100644
--- a/krops.nix
+++ b/krops.nix
@@ -22,9 +22,9 @@
# $HOST_CACHEDIR/src/HOSTNAME (default: ~/tmp/cache/hrm;
# git sources as symlinks to this host's checkouts of the same name at
# the same revision, else shallow clones),
-# and built on the first builder that answers. The builder keeps a GC
-# root in PATH/HOSTNAME/system (as the user it's logged in as, not
-# necessarily root) and copies the system to the target
+# and built on the first builder that answers. While deploying, the
+# builder keeps a GC root in PATH/HOSTNAME (as the user it's logged in
+# as, not necessarily root) and copies the system to the target
# (or, with copyVia = "deployer", the deploying host copies it from the
# builder).
# The target gets only its secrets, and activates. A record of each such
@@ -172,7 +172,8 @@ rec {
lib.optionalString (target'.port != null) "-p ${target'.port}";
targetURL = "${spec.targetStore}://${targetDest}";
# The builders, as targets like populate's, [USER@]HOST[:PORT]/PATH:
- # PATH is where a builder keeps the GC roots of the systems it built.
+ # PATH is where a builder keeps the GC roots of the systems it builds,
+ # while deploying them.
builders = map (s: let
t = lib.mkTarget s;
in
@@ -270,7 +271,11 @@ rec {
if builder_state=$(ssh -o BatchMode=yes -o ConnectTimeout=5 \
${b.sshOpts} ${q b.dest} "$builder_probe")
then
- builder=${q b.dest} builder_ssh_opts=${q b.sshOpts} builder_roots=${q b.path}
+ # *_quoted are quoted for the builder's shell, which parses the
+ # commands ssh passes it.
+ builder=${q b.dest} builder_ssh_opts=${q b.sshOpts} \
+ builder_roots_quoted=${q (q b.path)} \
+ builder_root_quoted=${q (q "${b.path}/${name}")}
else
echo "$name: builder "${q b.dest}" doesn't answer" >&2
fi
@@ -284,17 +289,19 @@ rec {
builder_load=$1 builder_cpus=$2 builder_mem=$3 builder_disk=$4
#
- # Build on the builder, into its store, and keep it there.
+ # Build on the builder, into its store, with a GC root there for as
+ # long as this script runs, so the system stays until it's copied.
#
echo "$name: building on $builder..." >&2
build_start=$(date +%s)
NIX_SSHOPTS=$builder_ssh_opts \
${nix} copy --no-check-sigs --derivation --to ssh-ng://"$builder" "$drv"
- system=$(NIX_SSHOPTS=$builder_ssh_opts \
- nix-store --store ssh-ng://"$builder" --realise "$drv")
+ trap 'ssh $builder_ssh_opts "$builder" "rm -f -- $builder_root_quoted"' EXIT
+ trap 'exit 1' INT TERM
+ system=$(ssh $builder_ssh_opts "$builder" "mkdir -p -- $builder_roots_quoted &&
+ nix-store --realise $drv --add-root $builder_root_quoted >/dev/null &&
+ readlink -- $builder_root_quoted")
build_end=$(date +%s)
- ssh $builder_ssh_opts "$builder" "mkdir -p $builder_roots/$name &&
- nix-store --realise $system --add-root $builder_roots/$name/system >/dev/null"
#
# Copy the system to the target.