Skip to content

Commit

Permalink
nixos/timesyncd: allow null for option servers
Browse files Browse the repository at this point in the history
This gives the ability to not write `NTP=` to the `timesyncd.conf` file
(servers = null) as opposed to writing `NTP=` (servers = []) which is
interpreted slightly differently by systemd:

> When the empty string is assigned, the list of NTP servers is reset,
and all prior assignments will have no effect.
  • Loading branch information
datafoo committed Sep 4, 2024
1 parent 34efcf8 commit b4cd578
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions nixos/modules/system/boot/timesyncd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ in
servers = mkOption {
default = config.networking.timeServers;
defaultText = literalExpression "config.networking.timeServers";
type = listOf str;
type = nullOr (listOf str);
description = ''
The set of NTP servers from which to synchronise.
Note if this is set to an empty list, the defaults systemd itself is
compiled with ({0..4}.nixos.pool.ntp.org) apply,
In case you want to disable timesyncd altogether, use the `enable` option.
Setting this option to an empty list will write `NTP=` to the
`timesyncd.conf` file as opposed to setting this option to null which
will remove `NTP=` entirely.
See man:timesyncd.conf(5) for details.
'';
};
extraConfig = mkOption {
Expand Down Expand Up @@ -85,9 +88,11 @@ in

environment.etc."systemd/timesyncd.conf".text = ''
[Time]
''
+ optionalString (cfg.servers != null) ''
NTP=${concatStringsSep " " cfg.servers}
${cfg.extraConfig}
'';
''
+ cfg.extraConfig;

users.users.systemd-timesync = {
uid = config.ids.uids.systemd-timesync;
Expand Down

0 comments on commit b4cd578

Please sign in to comment.