nixos/containers: Hash rendered nspawn file
The container restart trigger hashed the whole `systemd.nspawn.<name>` option value. Newer NixOS adds a `warnings` list to it, which embeds module source paths. With lazy trees those paths change on every evaluation, so the toplevel differed between `nix build` and `nix eval` and CI failed to push `system-kelder`. Hash the rendered `.nspawn` text instead, so containers restart exactly when the file systemd reads changes. Older NixOS renders all units into one directory, so fall back to the JSON hash there until 26.11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fabbb43fbf
commit
7694945041
1 file changed
+13
-3
@@ -10,6 +10,18 @@ let
|
||||
devVMKeyPath = "/run/dev.key";
|
||||
ctrProfiles = n: "/nix/var/nix/profiles/per-container/${n}";
|
||||
|
||||
# Restart a container when its rendered .nspawn file changes
|
||||
# TODO: Drop the fallback when 26.11 is stable. Older NixOS renders all .nspawn files into one directory.
|
||||
nspawnTrigger = n:
|
||||
let
|
||||
hash = hashString "sha256" (
|
||||
if options.systemd.nspawn.type.getSubOptions [ ] ? settings
|
||||
then config.environment.etc."systemd/nspawn/${n}.nspawn".text
|
||||
else toJSON config.systemd.nspawn."${n}"
|
||||
);
|
||||
in
|
||||
"${n}.nspawn:${hash}";
|
||||
|
||||
dummyReady = pkgs.runCommandCC "dummy-sd-ready" {
|
||||
buildInputs = [ pkgs.systemd ];
|
||||
passAsFile = [ "code" ];
|
||||
@@ -188,9 +200,7 @@ in
|
||||
# Without this, systemd-nspawn will do cgroupsv1
|
||||
SYSTEMD_NSPAWN_UNIFIED_HIERARCHY = "1";
|
||||
};
|
||||
restartTriggers = [
|
||||
(''${n}.nspawn:${hashString "sha256" (toJSON config.systemd.nspawn."${n}")}'')
|
||||
];
|
||||
restartTriggers = [ (nspawnTrigger n) ];
|
||||
|
||||
preStart =
|
||||
''
|
||||
|
||||
Reference in new issue
Block a user