diff options
| -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 */ '' |
