Skip to content

Commit

Permalink
nixos/localtimed: set time.timeZone to null to avoid silent overriding
Browse files Browse the repository at this point in the history
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]: <https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/tzupdate.nix#L24>
  • Loading branch information
guanarrana committed Oct 8, 2024
1 parent f6f24b0 commit 1c5727c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,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.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.

## Detailed migration information {#sec-release-24.11-migration}

### `sound` options removal {#sec-release-24.11-migration-sound}
Expand Down
9 changes: 9 additions & 0 deletions nixos/modules/services/system/localtimed.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ in {
Enable `localtimed`, a simple daemon for keeping the
system timezone up-to-date based on the current location. It uses
geoclue2 to determine the current location.
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 "localtime" { };
Expand All @@ -24,6 +29,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;

services.geoclue2.appConfig.localtimed = {
isAllowed = true;
isSystem = true;
Expand Down

0 comments on commit 1c5727c

Please sign in to comment.