diff options
Diffstat (limited to 'nixpkgs/nixos/modules/system/boot/timesyncd.nix')
-rw-r--r-- | nixpkgs/nixos/modules/system/boot/timesyncd.nix | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/system/boot/timesyncd.nix b/nixpkgs/nixos/modules/system/boot/timesyncd.nix new file mode 100644 index 000000000000..8282cdd6f3aa --- /dev/null +++ b/nixpkgs/nixos/modules/system/boot/timesyncd.nix @@ -0,0 +1,54 @@ +{ config, lib, ... }: + +with lib; + +{ + + options = { + + services.timesyncd = { + enable = mkOption { + default = !config.boot.isContainer; + type = types.bool; + description = '' + Enables the systemd NTP client daemon. + ''; + }; + servers = mkOption { + default = config.networking.timeServers; + description = '' + The set of NTP servers from which to synchronise. + ''; + }; + }; + }; + + config = mkIf config.services.timesyncd.enable { + + systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ]; + + systemd.services.systemd-timesyncd = { + wantedBy = [ "sysinit.target" ]; + restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ]; + }; + + environment.etc."systemd/timesyncd.conf".text = '' + [Time] + NTP=${concatStringsSep " " config.services.timesyncd.servers} + ''; + + users.users.systemd-timesync.uid = config.ids.uids.systemd-timesync; + users.groups.systemd-timesync.gid = config.ids.gids.systemd-timesync; + + system.activationScripts.systemd-timesyncd-migration = mkIf (versionOlder config.system.stateVersion "19.09") '' + # workaround an issue of systemd-timesyncd not starting due to upstream systemd reverting their dynamic users changes + # - https://github.com/NixOS/nixpkgs/pull/61321#issuecomment-492423742 + # - https://github.com/systemd/systemd/issues/12131 + if [ -L /var/lib/systemd/timesync ]; then + rm /var/lib/systemd/timesync + mv /var/lib/private/systemd/timesync /var/lib/systemd/timesync + fi + ''; + }; + +} |