From c9dbdcf175d0a7849ae3782ec7c162563dd4044b Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 1 Dec 2026 04:21:09 +0000 Subject: 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. --- krops.nix | 40 +++++++++++++++++++--------------------- 1 file 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 */ '' -- cgit v1.3.1