From 45c0d047355a8b847fb1606072c6a60b2887116d Mon Sep 17 00:00:00 2001 From: datafoo <34766150+datafoo@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:26:12 +0200 Subject: [PATCH 1/4] nixos/timesyncd: minor refactoring --- nixos/modules/system/boot/timesyncd.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix index f93064569bf68..82e3b8c15759a 100644 --- a/nixos/modules/system/boot/timesyncd.nix +++ b/nixos/modules/system/boot/timesyncd.nix @@ -2,6 +2,9 @@ with lib; +let + cfg = config.services.timesyncd; +in { options = { @@ -41,7 +44,7 @@ with lib; }; }; - config = mkIf config.services.timesyncd.enable { + config = mkIf cfg.enable { systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ]; @@ -82,8 +85,8 @@ with lib; environment.etc."systemd/timesyncd.conf".text = '' [Time] - NTP=${concatStringsSep " " config.services.timesyncd.servers} - ${config.services.timesyncd.extraConfig} + NTP=${concatStringsSep " " cfg.servers} + ${cfg.extraConfig} ''; users.users.systemd-timesync = { From 34efcf8aef8682eb4fa0cce2f590f877ce52d06f Mon Sep 17 00:00:00 2001 From: datafoo <34766150+datafoo@users.noreply.github.com> Date: Fri, 23 Aug 2024 14:42:27 +0200 Subject: [PATCH 2/4] nixos/timesyncd: minor refactoring --- nixos/modules/system/boot/timesyncd.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix index 82e3b8c15759a..b75a413fa58ef 100644 --- a/nixos/modules/system/boot/timesyncd.nix +++ b/nixos/modules/system/boot/timesyncd.nix @@ -9,11 +9,11 @@ in options = { - services.timesyncd = { + services.timesyncd = with types; { enable = mkOption { default = !config.boot.isContainer; defaultText = literalExpression "!config.boot.isContainer"; - type = types.bool; + type = bool; description = '' Enables the systemd NTP client daemon. ''; @@ -21,7 +21,7 @@ in servers = mkOption { default = config.networking.timeServers; defaultText = literalExpression "config.networking.timeServers"; - type = types.listOf types.str; + type = 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 @@ -31,7 +31,7 @@ in }; extraConfig = mkOption { default = ""; - type = types.lines; + type = lines; example = '' PollIntervalMaxSec=180 ''; 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 3/4] 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 b75a413fa58ef..d54ed687c8e7b 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; From 24e08d0e9b74392bd40689e016a1af8274ee7108 Mon Sep 17 00:00:00 2001 From: datafoo <34766150+datafoo@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:56:01 +0200 Subject: [PATCH 4/4] nixos/timesyncd: allow NTP servers advertised by DHCP to be used - add option `fallbackServers` with default to `networking.timeServers` - option `servers` now default to null Fix #335050 --- .../manual/release-notes/rl-2411.section.md | 4 ++++ nixos/modules/system/boot/timesyncd.nix | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index a2fd124765cd1..2f89c8a42e509 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -448,6 +448,10 @@ - The hooks `yarnConfigHook` and `yarnBuildHook` were added. These should replace `yarn2nix.mkYarnPackage` and other `yarn2nix` related tools. The motivation to get rid of `yarn2nix` tools is the fact that they are too complex and hard to maintain, and they rely upon too much Nix evaluation which is problematic if import-from-derivation is not allowed (see more details at [#296856](https://github.com/NixOS/nixpkgs/issues/296856). The transition from `mkYarnPackage` to `yarn{Config,Build}Hook` is tracked at [#324246](https://github.com/NixOS/nixpkgs/issues/324246). +- `services.timesyncd.servers` now defaults to `null`, allowing systemd-timesyncd to use NTP servers advertised by DHCP. + +- `services.timesyncd.fallbackServers` was added and defaults to `networking.timeServers`. + - Cinnamon has been updated to 6.2, please check [upstream announcement](https://www.linuxmint.com/rel_wilma_whatsnew.php) for more details. Following Mint 22 defaults, the Cinnamon module no longer ships geary and hexchat by default. diff --git a/nixos/modules/system/boot/timesyncd.nix b/nixos/modules/system/boot/timesyncd.nix index d54ed687c8e7b..117ced1f59ddc 100644 --- a/nixos/modules/system/boot/timesyncd.nix +++ b/nixos/modules/system/boot/timesyncd.nix @@ -19,8 +19,7 @@ in ''; }; servers = mkOption { - default = config.networking.timeServers; - defaultText = literalExpression "config.networking.timeServers"; + default = null; type = nullOr (listOf str); description = '' The set of NTP servers from which to synchronise. @@ -32,6 +31,20 @@ in See man:timesyncd.conf(5) for details. ''; }; + fallbackServers = mkOption { + default = config.networking.timeServers; + defaultText = literalExpression "config.networking.timeServers"; + type = nullOr (listOf str); + description = '' + The set of fallback NTP servers from which to synchronise. + + Setting this option to an empty list will write `FallbackNTP=` to the + `timesyncd.conf` file as opposed to setting this option to null which + will remove `FallbackNTP=` entirely. + + See man:timesyncd.conf(5) for details. + ''; + }; extraConfig = mkOption { default = ""; type = lines; @@ -92,6 +105,9 @@ in + optionalString (cfg.servers != null) '' NTP=${concatStringsSep " " cfg.servers} '' + + optionalString (cfg.fallbackServers != null) '' + FallbackNTP=${concatStringsSep " " cfg.fallbackServers} + '' + cfg.extraConfig; users.users.systemd-timesync = {