2018-07-20 20:56:59 +00:00
|
|
|
{ config, lib, ... }:
|
2015-04-19 19:05:12 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2016-12-14 22:49:14 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2019-11-20 05:57:02 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
example = ''
|
|
|
|
PollIntervalMaxSec=180
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra config options for systemd-timesyncd. See
|
|
|
|
<link xlink:href="https://www.freedesktop.org/software/systemd/man/timesyncd.conf.html">
|
|
|
|
timesyncd.conf(5)</link> for available options.
|
|
|
|
'';
|
|
|
|
};
|
2015-04-19 19:05:12 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.services.timesyncd.enable {
|
|
|
|
|
2015-04-19 19:11:14 +00:00
|
|
|
systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ];
|
|
|
|
|
2015-04-19 19:05:12 +00:00
|
|
|
systemd.services.systemd-timesyncd = {
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
2020-05-19 09:06:32 +00:00
|
|
|
aliases = [ "dbus-org.freedesktop.timesync1.service" ];
|
2015-04-19 19:05:12 +00:00
|
|
|
restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."systemd/timesyncd.conf".text = ''
|
|
|
|
[Time]
|
2018-05-24 22:44:04 +00:00
|
|
|
NTP=${concatStringsSep " " config.services.timesyncd.servers}
|
2019-11-20 05:57:02 +00:00
|
|
|
${config.services.timesyncd.extraConfig}
|
2015-04-19 19:05:12 +00:00
|
|
|
'';
|
|
|
|
|
2019-11-24 21:46:49 +00:00
|
|
|
users.users.systemd-timesync = {
|
|
|
|
uid = config.ids.uids.systemd-timesync;
|
|
|
|
group = "systemd-timesync";
|
|
|
|
};
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.systemd-timesync.gid = config.ids.gids.systemd-timesync;
|
2015-04-19 19:05:12 +00:00
|
|
|
|
2019-05-15 09:05:37 +00:00
|
|
|
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
|
|
|
|
'';
|
2015-04-19 19:05:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|