summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-24 03:58:38 +0000
committertv <tv@krebsco.de>2026-11-24 05:47:09 +0100
commit0ebca2123b67c5329bd39324ba8471e5fbcabfbf (patch)
tree19696eeb46326986ce055160bf80014242d5ad90
parentf7087241307ce9f3e0273d59576a3f3d7b21795e (diff)
krops.nix: builders as targets, with the path for their GC roots
-rw-r--r--krops.nix65
-rw-r--r--systems/oxi/spec.nix2
2 files changed, 45 insertions, 22 deletions
diff --git a/krops.nix b/krops.nix
index 0ab65cdd..bc5ef8f2 100644
--- a/krops.nix
+++ b/krops.nix
@@ -16,13 +16,15 @@
# or test (no new generation)
#
# REMOTE BUILDS
-# A host whose spec.nix lists builders (ssh destinations, e.g.
-# [ "root@zu.r" ]) gets evaluated on the deploying host, from sources
-# populated into $HOST_CACHEDIR/src/HOSTNAME (default: ~/tmp/cache/hrm;
+# A host whose spec.nix lists builders (targets like populate's,
+# [USER@]HOST[:PORT]/PATH, e.g. [ "tv@zu.r/home/tv/tmp/cache/hrm/roots" ])
+# gets evaluated on the deploying host, from sources populated into
+# $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 /var/hrm/HOSTNAME/system and copies the system to the target
+# root in PATH/HOSTNAME/system (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
@@ -169,6 +171,21 @@ rec {
targetSSHOpts =
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.
+ builders = map (s: let
+ t = lib.mkTarget s;
+ in
+ assert lib.assertMsg (lib.hasInfix "/" s)
+ "${name}: builder ${s} needs a path for its GC roots";
+ assert lib.assertMsg
+ (spec.copyVia != "deployer" || t.port == null || target'.port == null)
+ "${name}: copyVia = \"deployer\" can't use ports for both ${s} and the target";
+ {
+ dest = lib.optionalString (t.user != null) "${t.user}@" + t.host;
+ sshOpts = lib.optionalString (t.port != null) "-p ${t.port}";
+ inherit (t) path;
+ }) spec.builders;
targetSource = lib.evalSource [ targetSources ];
# Sources for evaluating here, in a directory of this host, populated as
# onto a target: everything but targetSources. Git sources link to this
@@ -244,18 +261,21 @@ rec {
#
# Choose the first builder that answers, and note its state.
#
+ builder_probe='printf "%s %s %s %s\n" "$(cut -d" " -f1 /proc/loadavg)" "$(nproc)" \
+ "$(awk "/^MemAvailable:/{print \$2*1024}" /proc/meminfo)" \
+ "$(df -B1 --output=avail /nix | tail -n 1)"'
builder=
- for candidate in ${lib.concatMapStringsSep " " q spec.builders}; do
- if builder_state=$(ssh -o BatchMode=yes -o ConnectTimeout=5 "$candidate" \
- 'printf "%s %s %s %s\n" "$(cut -d" " -f1 /proc/loadavg)" "$(nproc)" \
- "$(awk "/^MemAvailable:/{print \$2*1024}" /proc/meminfo)" \
- "$(df -B1 --output=avail /nix | tail -n 1)"')
- then
- builder=$candidate
- break
+ ${lib.concatMapStrings (b: /* sh */ ''
+ if test -z "$builder"; then
+ 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}
+ else
+ echo "$name: builder "${q b.dest}" doesn't answer" >&2
+ fi
fi
- echo "$name: builder $candidate doesn't answer" >&2
- done
+ '') builders}
if test -z "$builder"; then
echo "$name: error: no builder answers: "${q (toString spec.builders)} >&2
exit 1
@@ -268,11 +288,13 @@ rec {
#
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-store --store ssh-ng://"$builder" --realise "$drv")
+ system=$(NIX_SSHOPTS=$builder_ssh_opts \
+ nix-store --store ssh-ng://"$builder" --realise "$drv")
build_end=$(date +%s)
- ssh "$builder" "mkdir -p /var/hrm/$name &&
- nix-store --realise $system --add-root /var/hrm/$name/system >/dev/null"
+ 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.
@@ -284,7 +306,7 @@ rec {
${nix} copy --no-check-sigs \
--from ssh-ng://"$builder" --to ${q targetURL} "$system"
'' else /* sh */ ''
- if ! check=$(ssh "$builder" ssh -o BatchMode=yes -o ConnectTimeout=10 \
+ if ! check=$(ssh $builder_ssh_opts "$builder" ssh -o BatchMode=yes -o ConnectTimeout=10 \
${targetSSHOpts} ${q targetDest} true 2>&1)
then
echo "$name: error: $builder can't log in to "${q targetDest}":" >&2
@@ -297,7 +319,7 @@ rec {
*'Permission denied'*)
echo "$name: the target doesn't accept $builder's key; add it to" \
"the target's authorized keys:" >&2
- ssh "$builder" 'cat ~/.ssh/id_*.pub' >&2 || :
+ ssh $builder_ssh_opts "$builder" 'cat ~/.ssh/id_*.pub' >&2 || :
;;
*)
echo "$name: check the network between $builder and the target." >&2
@@ -306,7 +328,7 @@ rec {
exit 1
fi
echo "$name: copying from $builder..." >&2
- ssh "$builder" "NIX_SSHOPTS='${targetSSHOpts}' ${nix} copy --no-check-sigs \
+ ssh $builder_ssh_opts "$builder" "NIX_SSHOPTS='${targetSSHOpts}' ${nix} copy --no-check-sigs \
--to ${targetURL} $system"
''}
copy_end=$(date +%s)
@@ -314,7 +336,8 @@ rec {
#
# Note what happened, for choosing builders later.
#
- closure_size=$(${nix} path-info --store ssh-ng://"$builder" -S "$system" | cut -f2)
+ closure_size=$(NIX_SSHOPTS=$builder_ssh_opts \
+ ${nix} path-info --store ssh-ng://"$builder" -S "$system" | cut -f2)
${jq} -nc \
--arg host "$name" --arg action ${q deploy-action} \
--arg deployer "$(cat /etc/hostname)" --arg builder "$builder" \
diff --git a/systems/oxi/spec.nix b/systems/oxi/spec.nix
index 48ca1a01..1d1387fe 100644
--- a/systems/oxi/spec.nix
+++ b/systems/oxi/spec.nix
@@ -1,5 +1,5 @@
{
system = "x86_64-linux";
target = "root@oxi.i/var/src";
- builders = [ "root@zu.r" ];
+ builders = [ "tv@zu.r/home/tv/tmp/cache/hrm" ];
}