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 | 763021ac0d2cb5830477e0751cab19eb5c9ed3c1 (patch) | |
| tree | cf6fddde01c246e51a5ba7f64ae6bd75291d08cd | |
| parent | 3a8a4a048c5f6b55954d4af60d14d4735df875da (diff) | |
krops.nix: keep enstate submissions in /run/enstate/krops
Next to enstate's views, by channel name, and kept after a deploy, so
the next one sends only what changed (rsync --checksum; --delete for a
channel that's gone). They get stamped when moved into the incoming
directory, still only after the build.
| -rw-r--r-- | krops.nix | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -173,14 +173,17 @@ rec { # Delivering the host's enstate submissions: each channel's, from the # host's enstate.sourceLists as this host evaluates them, gets packed - # here, goes to the target's memory, and from there to enstate's incoming - # directory. + # 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. enstateSteps = let target' = lib.mkTarget target; - pending = "/run/krops-enstate"; + run = "/run/enstate/krops"; + pending = "${run}/pending"; stateDir = "/var/lib/enstate"; in { - # In a subshell, so its trap leaves the caller's alone. + # In a subshell, so its trap leaves the caller's alone. By channel + # name, so the same state packs the same. packAndCopy = /* sh */ '' ( submissions=$( @@ -188,29 +191,26 @@ rec { mktemp -d --tmpdir ${name}-enstate.XXXXXXXX ) trap 'rm -fR "$submissions"' EXIT - stamp=$(date -u +%Y%m%dT%H%M%SZ)-$$ ${lib.concatStrings (lib.mapAttrsToList (channel: sourceList: /* sh */ '' ${local.pkgs.enstate}/bin/enstate \ --pack ${pkgs.writers.writeJSON "${name}-enstate-${channel}.json" sourceList} \ - --out "$submissions"/"$stamp"-${channel} + --out "$submissions"/${channel} '') sourceLists)} - ${pkgs.rsync}/bin/rsync -a --no-owner --no-group --chmod=D0700,F0600 \ + ${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 ${pending} && rsync"} \ + --rsync-path=${lib.escapeShellArg "mkdir -m 0700 -p ${run} ${pending} && rsync"} \ "$submissions"/ ${lib.escapeShellArg "${target'.host}:${pending}/"} ) ''; - forgetPending = /* sh */ '' - trap 'rm -fR ${pending}' EXIT - ''; # 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 */ '' mkdir -p -m 0700 ${stateDir} ${stateDir}/incoming + stamp=$(date -u +%Y%m%dT%H%M%SZ)-$$ find ${pending} -mindepth 1 -maxdepth 1 -printf '%f\n' | - while read -r submission; do - cp -a ${pending}/"$submission" ${stateDir}/incoming/."$submission" - mv ${stateDir}/incoming/."$submission" ${stateDir}/incoming/"$submission" + while read -r channel; do + cp -a ${pending}/"$channel" ${stateDir}/incoming/."$stamp-$channel" + mv ${stateDir}/incoming/."$stamp-$channel" ${stateDir}/incoming/"$stamp-$channel" done ''; }; @@ -224,7 +224,6 @@ rec { ${enstateSteps.packAndCopy} ${pkgs.krops.runShell (lib.mkTarget target) {} /* sh */ '' set -efu - ${enstateSteps.forgetPending} ${enstateSteps.movePending} /run/current-system/sw/bin/enstate --migrate ''} @@ -237,7 +236,6 @@ rec { # the switch, whose check plans them, and which takes them. submit = deploy-action == "deploy" && sourceLists != {}; packAndCopy = lib.optionalString submit enstateSteps.packAndCopy; - forgetPending = lib.optionalString submit enstateSteps.forgetPending; movePending = lib.optionalString submit enstateSteps.movePending; # Without a switch, nothing takes what waits: take it now. takeNow = lib.optionalString submit /* sh */ '' @@ -250,7 +248,6 @@ rec { ${packAndCopy} ${pkgs.krops.runShell target' { allocateTTY = true; } /* sh */ '' set -efu - ${forgetPending} system=$( export NIX_PATH=${lib.escapeShellArg target'.path} ${builtins.getAttr build-method { @@ -620,7 +617,7 @@ rec { # Without prune: the rest of the target's /var/src stays. ${pkgs.populate { source = targetSource; target = target'; }} ${lib.optionalString submit enstateSteps.packAndCopy} - ${onTarget (lib.optionalString submit (enstateSteps.forgetPending + enstateSteps.movePending) + activate)} + ${onTarget (lib.optionalString submit enstateSteps.movePending + activate)} ''; diff = /* sh */ '' old_drv=$(${onTarget /* sh */ '' |
