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.
This commit is contained in:
nikstur
2026-02-20 19:15:11 +01:00
parent e0e1338ba4
commit ba8e154742
+25
View File
@@ -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);