From 8a277a6abf9abef6ac2f85f64ef2ff9cea760ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Zavala=20Villag=C3=B3mez?= Date: Mon, 7 Oct 2024 22:34:11 -0400 Subject: [PATCH] nixos/automatic-timezoned: set time.timeZone to null to avoid silent overriding Currently if a timezone was selected explicitly, the service will silently override the value, essentially ignoring what is meant to be a a deliberate choice of option. This may cause confusion as to why the option is not doing anything when this service is enabled, particularly in more complex set-ups after some time. This will simply make the choice deliberate from the user's part, either by having to remove the option or lowering its priority as a recognition that it may be ignored. This change was inspired by the `services.tzupdate` module, which does the same. [1]: --- nixos/doc/manual/release-notes/rl-2411.section.md | 3 +++ nixos/modules/services/system/automatic-timezoned.nix | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index e802470e7a04..22e49f6f66a4 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -678,6 +678,9 @@ - ZFS now imports its pools in `postResumeCommands` rather than `postDeviceCommands`. If you had `postDeviceCommands` scripts that depended on ZFS pools being imported, those now need to be in `postResumeCommands`. +- `services.automatic-timezoned.enable = true` will now set `time.timeZone = null`. + This is to avoid silently shadowing a user's explicitly defined timezone without recognition on the user's part. + - `services.localtimed.enable = true` will now set `time.timeZone = null`. This is to avoid silently shadowing a user's explicitly defined timezone without recognition on the user's part. diff --git a/nixos/modules/services/system/automatic-timezoned.nix b/nixos/modules/services/system/automatic-timezoned.nix index 6150aa22cfbd..50f84f39af7d 100644 --- a/nixos/modules/services/system/automatic-timezoned.nix +++ b/nixos/modules/services/system/automatic-timezoned.nix @@ -16,6 +16,11 @@ in timezone up-to-date based on the current location. It uses geoclue2 to determine the current location and systemd-timedated to actually set the timezone. + + To avoid silent overriding by the service, if you have explicitly set a + timezone, either remove it or ensure that it is set with a lower priority + than the default value using `lib.mkDefault` or `lib.mkOverride`. This is + to make the choice deliberate. An error will be presented otherwise. ''; }; package = mkPackageOption pkgs "automatic-timezoned" { }; @@ -23,6 +28,10 @@ in }; config = mkIf cfg.enable { + # This will give users an error if they have set an explicit time + # zone, rather than having the service silently override it. + time.timeZone = null; + security.polkit.extraConfig = '' polkit.addRule(function(action, subject) { if (action.id == "org.freedesktop.timedate1.set-timezone"