diff options
| author | tv <tv@krebsco.de> | 2026-12-01 04:21:09 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 04:21:09 +0000 |
| commit | c9dbdcf175d0a7849ae3782ec7c162563dd4044b (patch) | |
| tree | fff4116f6e8acfc5f7df574e670a998acdeb0f93 | |
| parent | 763021ac0d2cb5830477e0751cab19eb5c9ed3c1 (diff) | |
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.
| -rw-r--r-- | krops.nix | 40 |
1 files changed, 19 insertions, 21 deletions
@@ -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 */ '' |
