From b4cd57870dc9ec1da8757148c79a491ed2bf2e90 Mon Sep 17 00:00:00 2001 From: datafoo <34766150+datafoo@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:59:22 +0200 Subject: [PATCH] nixos/timesyncd: allow null for option servers 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. --- nixos/modules/system/boot/timesyncd.nix | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix index b75a413fa58e..d54ed687c8e7 100644 --- a/nixos/modules/system/boot/timesyncd.nix +++ b/nixos/modules/system/boot/timesyncd.nix @@ -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 { @@ -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;