diff options
| -rw-r--r-- | krops.nix | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -74,6 +74,11 @@ let }) (builtins.filter (item: item != "") (lib.splitString "," checkouts))); + # hrm, as this host has it: its package set, and the host's enstate + # source lists, as evaluated here. + local = import ./. {}; + sourceLists = local.legacy.nixosConfigurations.${name}.config.enstate.sourceLists; + # A source pinned in sources.json, fetched with git. gitSource = source: let entry = (lib.importJSON ./sources.json).${source}; @@ -156,6 +161,8 @@ 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 @@ -166,12 +173,49 @@ rec { mkTargetBuildAction = build-method: deploy-action: let target' = lib.mkTarget target; name' = "${name}-deploy-${build-method}-${deploy-action}"; + # The host's enstate.sourceLists, as this host evaluates them: each + # channel's submission gets packed here, goes to the target's memory, and + # once the system is built, to where it waits for the switch, whose + # check plans it, and which takes it. + submit = deploy-action == "deploy" && sourceLists != {}; + pending = "/run/krops-enstate"; + stateDir = "/var/lib/enstate"; + packAndCopy = lib.optionalString submit /* sh */ '' + 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}/"} + ''; + forgetPending = lib.optionalString submit /* sh */ '' + trap 'rm -fR ${pending}' EXIT + ''; + movePending = lib.optionalString submit /* sh */ '' + mkdir -p -m 0700 ${stateDir} ${stateDir}/incoming + find ${pending} -mindepth 1 -maxdepth 1 -exec mv -t ${stateDir}/incoming {} + + ''; + # Without a switch, nothing takes what waits: take it now. + takeNow = lib.optionalString submit /* sh */ '' + "$system"/sw/bin/enstate --migrate + ''; in pkgs.writers.writeDash name' /* sh */ '' set -efu ${pkgs.populate { source = source; target = target'; }} + ${packAndCopy} ${pkgs.krops.runShell target' { allocateTTY = true; } /* sh */ '' set -efu + ${forgetPending} system=$( export NIX_PATH=${lib.escapeShellArg target'.path} ${builtins.getAttr build-method { @@ -191,6 +235,7 @@ rec { ''; }} ) + ${movePending} ${builtins.getAttr deploy-action { deploy = let setAndSwitch = /* sh */ '' @@ -204,6 +249,7 @@ rec { nix-env -p /nix/var/nix/profiles/system --set "$system" "$system"/bin/switch-to-configuration ${switch} else + ${takeNow} echo 'Configuration is already up to date' >&2 fi ''; |
