summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--krops.nix55
1 files changed, 33 insertions, 22 deletions
diff --git a/krops.nix b/krops.nix
index ba5a1d51..88f8eee8 100644
--- a/krops.nix
+++ b/krops.nix
@@ -42,7 +42,8 @@
# as, not necessarily root) and copies the system to the target
# (or, with copyVia = "deployer", the deploying host copies it from the
# builder).
-# The target gets only its secrets, and activates. A record of each such
+# The target gets only its secrets and enstate submissions, and
+# activates. A record of each such
# build goes to $PORTABLE_CACHEDIR/builds.jsonl (default:
# ~/shared-tmp/cache/hrm), the evaluated derivation's GC root to
# $HOST_CACHEDIR/roots/HOSTNAME.drv.
@@ -163,8 +164,6 @@ rec {
pkgs.writers.writeDash "${name}-${action}" (remoteBuildScript action);
mkAction = build-method: deploy-action:
- assert lib.assertMsg (spec.builders == [] || sourceLists == {})
- "${name}: enstate submissions need a build on the target, for now";
if spec.builders == [] then
mkTargetBuildAction build-method deploy-action
else
@@ -181,22 +180,25 @@ rec {
pending = "/run/krops-enstate";
stateDir = "/var/lib/enstate";
in {
+ # In a subshell, so its trap leaves the caller's alone.
packAndCopy = /* sh */ ''
- submissions=$(
- TMPDIR=''${XDG_RUNTIME_DIR:-''${TMPDIR:-/tmp}} \
- mktemp -d --tmpdir ${name}-enstate.XXXXXXXX
+ (
+ submissions=$(
+ TMPDIR=''${XDG_RUNTIME_DIR:-''${TMPDIR:-/tmp}} \
+ 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}
+ '') sourceLists)}
+ ${pkgs.rsync}/bin/rsync -a --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"} \
+ "$submissions"/ ${lib.escapeShellArg "${target'.host}:${pending}/"}
)
- 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}
- '') sourceLists)}
- ${pkgs.rsync}/bin/rsync -a --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"} \
- "$submissions"/ ${lib.escapeShellArg "${target'.host}:${pending}/"}
'';
forgetPending = /* sh */ ''
trap 'rm -fR ${pending}' EXIT
@@ -577,6 +579,9 @@ rec {
${builtins.getAttr action {
deploy = let
+ # The submissions wait for the switch, whose check plans them, and
+ # which takes them.
+ submit = sourceLists != {};
setAndSwitch = /* sh */ ''
old_gen=$(readlink -f /nix/var/nix/profiles/system)
new_gen=$(readlink -f "$system")
@@ -590,20 +595,26 @@ rec {
--setenv=NIXOS_NO_CHECK="''${NIXOS_NO_CHECK-}" \
"$system"/bin/switch-to-configuration ${switch}
else
+ ${lib.optionalString submit /* sh */ ''
+ # Without a switch, nothing takes what waits: take it now.
+ "$system"/sw/bin/enstate --migrate
+ ''}
echo 'Configuration is already up to date' >&2
fi
'';
- in /* sh */ ''
- # Without prune: the rest of the target's /var/src stays.
- ${pkgs.populate { source = targetSource; target = target'; }}
- ${onTarget (builtins.getAttr switch {
+ activate = builtins.getAttr switch {
switch = setAndSwitch;
boot = setAndSwitch;
test = /* sh */ ''
systemd-run --pipe --wait --collect --quiet \
"$system"/bin/switch-to-configuration test
'';
- })}
+ };
+ in /* sh */ ''
+ # 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)}
'';
diff = /* sh */ ''
old_drv=$(${onTarget /* sh */ ''