From 76949450416e196b1ac261e569d5b8018bdf031c Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Tue, 24 Nov 2026 08:40:57 +0000 Subject: [PATCH] nixos/containers: Hash rendered nspawn file The container restart trigger hashed the whole `systemd.nspawn.` 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 --- nixos/modules/containers.nix | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nixos/modules/containers.nix b/nixos/modules/containers.nix index 223a772..2c21c79 100644 --- a/nixos/modules/containers.nix +++ b/nixos/modules/containers.nix @@ -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 = ''