diff options
Diffstat (limited to 'nix/module.nix')
| -rw-r--r-- | nix/module.nix | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/nix/module.nix b/nix/module.nix index f81bea9..d2f54c8 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -265,13 +265,26 @@ in description = "Views made by renderers."; }; + incomingDir = mkOption { + type = types.str; + readOnly = true; + default = "${cfg.stateDir}/incoming"; + defaultText = lib.literalExpression ''"''${config.enstate.stateDir}/incoming"''; + description = '' + Where submissions wait for the next switch, each a directory of its own, taken + in the order of their names: planned against the new generation's schema + before switching, which a refused one refuses, and applied by the switch. + ''; + }; + checkBeforeSwitch = mkOption { type = types.bool; default = true; description = '' Whether a switch to a generation whose required slots the state can't fill, - even by migrating, is refused before switching. Not checked when the running - system has no enstate, nor for `boot` and `dry-activate`. + even by migrating and with the submissions waiting in `incomingDir`, or for + which a waiting submission is refused, is refused before switching. Not + checked for `boot` and `dry-activate`. ''; }; }; @@ -310,7 +323,7 @@ in environment.etc."enstate/schema.json".source = schemaFile; environment.etc."enstate/config.json".source = settings; - # At boot and after a switch that changes the schema: the views of this + # At boot, and after a switch that changes the schema: the views of this # generation, from the snapshots, and the reactions of those that changed. systemd.services.enstate = { description = "enstate: the views of this generation"; @@ -324,16 +337,41 @@ in }; }; + # After a switch whose schema didn't change, with a submission waiting in + # incomingDir or staged (--stage leaves a marker, which --migrate removes): + # switch-to-configuration restarts sysinit-reactivation.target on every switch, + # which starts this, and the conditions keep it from running otherwise. After a + # switch whose schema changed, enstate.service has taken them already. + systemd.services.enstate-switch = { + description = "enstate: what waits for the switch"; + wantedBy = [ "sysinit-reactivation.target" ]; + after = [ "local-fs.target" ]; + before = [ + "sysinit-reactivation.target" + "shutdown.target" + ]; + conflicts = [ "shutdown.target" ]; + unitConfig = { + DefaultDependencies = false; + # Either ("|"). + ConditionDirectoryNotEmpty = "|${cfg.incomingDir}"; + ConditionPathExists = "|${cfg.stateDir}/migrate-due"; + }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${enstate} --migrate"; + }; + }; + + # With the new generation's enstate, schema and configuration; on a host without + # enstate yet, too: its first switch needs its state, which can wait in + # incomingDir. system.preSwitchChecks = lib.mkIf cfg.checkBeforeSwitch { enstate = '' case "''${2-}" in boot|dry-activate) exit 0 ;; esac - if [ ! -e /etc/enstate/schema.json ]; then - echo "enstate: the running system has none, not checking" - exit 0 - fi - ${enstate} --migrate --dry-run --schema "$1/etc/enstate/schema.json" + ${enstate} --migrate --dry-run --schema "$1/etc/enstate/schema.json" --config "$1/etc/enstate/config.json" ''; }; }; |
