From e0e1338ba48c7d2f64a61eb59daa06a0b78915f3 Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 18 Feb 2026 17:13:38 +0100 Subject: [PATCH 1/2] nixos/tests/systemd: pkgs.systemd -> nodes.machine.systemd.package This makes it easier to tests changes from staging without having to rebuild the whole world and instead just supplying a new systemd package via the module system. --- nixos/tests/systemd.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix index f0bbdef76c61..98cc88a0326f 100644 --- a/nixos/tests/systemd.nix +++ b/nixos/tests/systemd.nix @@ -109,10 +109,10 @@ machine.wait_for_unit("first-boot-complete.target") machine.succeed( - "journalctl --system -o cat --grep 'systemd ${lib.escapeRegex pkgs.systemd.version} running'" + "journalctl --system -o cat --grep 'systemd ${lib.escapeRegex nodes.machine.systemd.package.version} running'" ) - assert "systemd ${lib.versions.major pkgs.systemd.version} (${pkgs.systemd.version})" in machine.succeed( + assert "systemd ${lib.versions.major nodes.machine.systemd.package.version} (${nodes.machine.systemd.package.version})" in machine.succeed( "systemctl --version" ) From ba8e1547428a49d64453905d12a7d812ea53f3c7 Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 18 Feb 2026 17:11:11 +0100 Subject: [PATCH 2/2] nixos/systemd: point various systemd daemons to /etc/static This is done to prepare the removal of 0006-hostnamed-localed-timedated-disable-methods-that-cha.patch from systemd. Pointing the daemon to /etc/static will make imperative changes to these files (e.g. via hostnamectl) fail because systemd cannot edit them. --- nixos/modules/system/boot/systemd.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 4b7bb1271392..8bfd2a784f47 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -807,6 +807,31 @@ in # Don't bother with certain units in containers. systemd.services.systemd-remount-fs.unitConfig.ConditionVirtualization = "!container"; + # When using the classic /etc mechanism, we set certain paths in /etc to + # /etc/static so that systemd cannot change them (as they are symlinks to + # the read-only Nix Store). This is only done so that these services cannot + # change the values. All other parts of systemd should read them from their + # canonical locations. + # + # If you use the overlay mechanism to manage /etc, this is unnecessary + # because either the overlay is mutable (and users can legitimately change + # values without them being overridden) or it is immutable and systemd will + # suggest to only make runtime changes. + systemd.services."systemd-localed".environment = lib.mkIf (!config.system.etc.overlay.enable) { + SYSTEMD_ETC_LOCALE_CONF = "/etc/static/locale.conf"; + SYSTEMD_ETC_VCONSOLE_CONF = "/etc/static/vconsole.conf"; + }; + systemd.services."systemd-timedated".environment = + lib.mkIf (!config.system.etc.overlay.enable && config.time.timeZone != null) + { + SYSTEMD_ETC_LOCALTIME = "/etc/static/localtime"; + SYSTEMD_ETC_ADJTIME = "/etc/static/adjtime"; + }; + systemd.services."systemd-hostnamed".environment = lib.mkIf (!config.system.etc.overlay.enable) { + SYSTEMD_ETC_HOSTNAME = "/etc/static/hostname"; + SYSTEMD_ETC_MACHINE_INFO = "/etc/static/machine-info"; + }; + # Increase numeric PID range (set directly instead of copying a one-line file from systemd) # https://github.com/systemd/systemd/pull/12226 boot.kernel.sysctl."kernel.pid_max" = mkIf pkgs.stdenv.hostPlatform.is64bit (lib.mkDefault 4194304);