summaryrefslogtreecommitdiffstats
path: root/krops.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 04:21:09 +0000
committertv <tv@krebsco.de>2026-12-01 04:21:09 +0000
commitc9dbdcf175d0a7849ae3782ec7c162563dd4044b (patch)
treefff4116f6e8acfc5f7df574e670a998acdeb0f93 /krops.nix
parent763021ac0d2cb5830477e0751cab19eb5c9ed3c1 (diff)
krops.nix: deliver enstate submissions by populate
A pipe source with directory = true, whose command packs into the directory populate gives it, in a populate run of its own with the target's /run/enstate/krops as target path, instead of mktemp, rsync and ssh by hand. It needs krops' populate at 9cbe2fa or later.
Diffstat (limited to 'krops.nix')
-rw-r--r--krops.nix40
1 files changed, 19 insertions, 21 deletions
diff --git a/krops.nix b/krops.nix
index 8a05b744..62ca1cc4 100644
--- a/krops.nix
+++ b/krops.nix
@@ -175,33 +175,31 @@ rec {
# host's enstate.sourceLists as this host evaluates them, gets packed
# here, goes to the target's memory, next to enstate's views, and from
# there to enstate's incoming directory. What went last stays there, so
- # rsync sends only what changed.
+ # populate sends only what changed.
enstateSteps = let
target' = lib.mkTarget target;
run = "/run/enstate/krops";
pending = "${run}/pending";
stateDir = "/var/lib/enstate";
in {
- # In a subshell, so its trap leaves the caller's alone. By channel
- # name, so the same state packs the same.
- packAndCopy = /* sh */ ''
- (
- submissions=$(
- TMPDIR=''${XDG_RUNTIME_DIR:-''${TMPDIR:-/tmp}} \
- mktemp -d --tmpdir ${name}-enstate.XXXXXXXX
- )
- trap 'rm -fR "$submissions"' EXIT
- ${lib.concatStrings (lib.mapAttrsToList (channel: sourceList: /* sh */ ''
- ${local.pkgs.enstate}/bin/enstate \
- --pack ${pkgs.writers.writeJSON "${name}-enstate-${channel}.json" sourceList} \
- --out "$submissions"/${channel}
- '') sourceLists)}
- ${pkgs.rsync}/bin/rsync -a --checksum --delete --no-owner --no-group --chmod=D0700,F0600 \
- -e ${lib.escapeShellArg (lib.concatStringsSep " " ([ "ssh" ] ++ lib.mkUserPortSSHOpts target'))} \
- --rsync-path=${lib.escapeShellArg "mkdir -m 0700 -p ${run} ${pending} && rsync"} \
- "$submissions"/ ${lib.escapeShellArg "${target'.host}:${pending}/"}
- )
- '';
+ # By channel name, so the same state packs the same.
+ packAndCopy = pkgs.populate {
+ source = lib.evalSource [{
+ pending.pipe = {
+ directory = true;
+ command = toString (pkgs.writers.writeDash "${name}-enstate-pack" ''
+ set -efu
+ ${lib.concatStrings (lib.mapAttrsToList (channel: sourceList: /* sh */ ''
+ ${local.pkgs.enstate}/bin/enstate \
+ --pack ${pkgs.writers.writeJSON "${name}-enstate-${channel}.json" sourceList} \
+ --out "$1"/${channel}
+ '') sourceLists)}
+ '');
+ };
+ }];
+ target = target' // { path = run; };
+ force = true;
+ };
# Copied under a dot name, which enstate skips, and renamed: from memory
# to disk, mv would copy, and enstate could see half a submission.
movePending = /* sh */ ''