mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
nixos/timesyncd: migrate to RFC 42-style settings
Replace `services.timesyncd.extraConfig` with a freeform `services.timesyncd.settings.Time` submodule, rendered via `utils.systemdUtils.lib.settingsToSections`. `extraConfig` is removed via `mkRemovedOptionModule`. `servers` and `fallbackServers` are kept as typed wrappers; they now bridge into `settings.Time.NTP` / `settings.Time.FallbackNTP` via `mkDefault` so users can still override them through `settings.Time`. Adds `nixos/tests/systemd-timesyncd` to assert the rendered `timesyncd.conf` contents.
This commit is contained in:
parent
29d672498f
commit
1460350c4c
5 changed files with 70 additions and 22 deletions
|
|
@ -23,6 +23,8 @@
|
|||
no longer sets `programs.pqos-wrapper.enable = true`
|
||||
as the corresponding module has been deleted.
|
||||
|
||||
- `services.timesyncd.extraConfig` has been removed in favor of the structured [](#opt-services.timesyncd.settings.Time) option. Use `services.timesyncd.settings.Time` to set any `timesyncd.conf(5)` option directly. For example, replace `services.timesyncd.extraConfig = "PollIntervalMaxSec=180";` with `services.timesyncd.settings.Time.PollIntervalMaxSec = 180;`.
|
||||
|
||||
## Other Notable Changes {#sec-release-26.11-notable-changes}
|
||||
|
||||
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
|
||||
|
|
|
|||
|
|
@ -1,10 +1,23 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
utils,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.services.timesyncd;
|
||||
in
|
||||
{
|
||||
|
||||
imports = [
|
||||
(lib.mkRemovedOptionModule [
|
||||
"services"
|
||||
"timesyncd"
|
||||
"extraConfig"
|
||||
] "Use services.timesyncd.settings.Time instead.")
|
||||
];
|
||||
|
||||
options = {
|
||||
|
||||
services.timesyncd = {
|
||||
|
|
@ -43,15 +56,17 @@ in
|
|||
See {manpage}`timesyncd.conf(5)` for details.
|
||||
'';
|
||||
};
|
||||
extraConfig = lib.mkOption {
|
||||
default = "";
|
||||
type = lib.types.lines;
|
||||
example = ''
|
||||
PollIntervalMaxSec=180
|
||||
'';
|
||||
settings.Time = lib.mkOption {
|
||||
default = { };
|
||||
type = lib.types.submodule {
|
||||
freeformType = lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption;
|
||||
};
|
||||
example = {
|
||||
PollIntervalMaxSec = 180;
|
||||
};
|
||||
description = ''
|
||||
Extra config options for systemd-timesyncd. See
|
||||
{manpage}`timesyncd.conf(5)` for available options.
|
||||
Settings for systemd-timesyncd. See {manpage}`timesyncd.conf(5)` for
|
||||
available options.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
@ -74,16 +89,17 @@ in
|
|||
environment.LD_LIBRARY_PATH = config.system.nssModules.path;
|
||||
};
|
||||
|
||||
environment.etc."systemd/timesyncd.conf".text = ''
|
||||
[Time]
|
||||
''
|
||||
+ lib.optionalString (cfg.servers != null) ''
|
||||
NTP=${lib.concatStringsSep " " cfg.servers}
|
||||
''
|
||||
+ lib.optionalString (cfg.fallbackServers != null) ''
|
||||
FallbackNTP=${lib.concatStringsSep " " cfg.fallbackServers}
|
||||
''
|
||||
+ cfg.extraConfig;
|
||||
services.timesyncd.settings.Time = lib.mkMerge [
|
||||
(lib.mkIf (cfg.servers != null) {
|
||||
NTP = lib.mkDefault (lib.concatStringsSep " " cfg.servers);
|
||||
})
|
||||
(lib.mkIf (cfg.fallbackServers != null) {
|
||||
FallbackNTP = lib.mkDefault (lib.concatStringsSep " " cfg.fallbackServers);
|
||||
})
|
||||
];
|
||||
|
||||
environment.etc."systemd/timesyncd.conf".text =
|
||||
utils.systemdUtils.lib.settingsToSections cfg.settings;
|
||||
|
||||
users.users.systemd-timesync = {
|
||||
uid = config.ids.uids.systemd-timesync;
|
||||
|
|
|
|||
|
|
@ -1653,6 +1653,7 @@ in
|
|||
systemd-sysusers-immutable = runTest ./systemd-sysusers-immutable.nix;
|
||||
systemd-sysusers-mutable = runTest ./systemd-sysusers-mutable.nix;
|
||||
systemd-sysusers-password-option-override-ordering = runTest ./systemd-sysusers-password-option-override-ordering.nix;
|
||||
systemd-timesyncd = runTest ./systemd-timesyncd.nix;
|
||||
systemd-timesyncd-nscd-dnssec = runTest ./systemd-timesyncd-nscd-dnssec.nix;
|
||||
systemd-user-linger = runTest ./systemd-user-linger.nix;
|
||||
systemd-user-linger-purge = runTest ./systemd-user-linger-purge.nix;
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ in
|
|||
# Configure systemd-timesyncd to use our NTP hostname
|
||||
services.timesyncd.enable = lib.mkForce true;
|
||||
services.timesyncd.servers = [ ntpHostname ];
|
||||
services.timesyncd.extraConfig = ''
|
||||
FallbackNTP=${ntpHostname}
|
||||
'';
|
||||
services.timesyncd.settings.Time.FallbackNTP = ntpHostname;
|
||||
|
||||
# The debug output is necessary to determine whether systemd-timesyncd successfully resolves our NTP hostname or not
|
||||
systemd.services.systemd-timesyncd.environment.SYSTEMD_LOG_LEVEL = "debug";
|
||||
|
|
|
|||
31
nixos/tests/systemd-timesyncd.nix
Normal file
31
nixos/tests/systemd-timesyncd.nix
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
name = "systemd-timesyncd";
|
||||
meta = {
|
||||
maintainers = [ ];
|
||||
};
|
||||
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
{
|
||||
services.timesyncd = {
|
||||
enable = lib.mkForce true;
|
||||
servers = [ "ntp.example.com" ];
|
||||
fallbackServers = [ "fallback.example.com" ];
|
||||
settings.Time = {
|
||||
PollIntervalMaxSec = "180";
|
||||
RootDistanceMaxSec = "5";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
with subtest("settings.Time renders timesyncd.conf"):
|
||||
machine.succeed("grep -F '[Time]' /etc/systemd/timesyncd.conf")
|
||||
machine.succeed("grep -F 'NTP=ntp.example.com' /etc/systemd/timesyncd.conf")
|
||||
machine.succeed("grep -F 'FallbackNTP=fallback.example.com' /etc/systemd/timesyncd.conf")
|
||||
machine.succeed("grep -F 'PollIntervalMaxSec=180' /etc/systemd/timesyncd.conf")
|
||||
machine.succeed("grep -F 'RootDistanceMaxSec=5' /etc/systemd/timesyncd.conf")
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue