diff options
| author | tv <tv@krebsco.de> | 2026-11-30 18:05:23 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 22:03:11 +0000 |
| commit | 2df89c5ff9bb32dab96a504116206ccce1045ccf (patch) | |
| tree | 9c74466dce57a83aad923b8501254c0aadbe6f92 /nix/module.nix | |
| parent | b74359e97643be0f43034c3aeab533a2389a939f (diff) | |
nix: the switch serves the views when there is something to serve
enstate.service reruns on a switch when the schema changes. A unit of
its own, enstate-switch.service, takes what waits otherwise: a
submission in incomingDir, or one staged. switch-to-configuration
restarts sysinit-reactivation.target on every switch, which starts it,
and triggering conditions keep it from running when nothing waits. The
check before a switch uses the new generation's enstate, schema and
configuration, and runs on a host without enstate, too: its first
switch's state can wait in incomingDir. Subtests of the VM test: staged
under an unchanged schema, brought by the switch (without the warning
the activation-restart-list gives); a waiting submission taken by the
switch that needs it; one refused refusing it.
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" ''; }; }; |
