2018-07-20 22:56:59 +02:00
|
|
|
{ config, lib, ... }:
|
2015-04-19 21:05:12 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2016-12-14 23:49:14 +01: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.
|
|
|
|
'';
|
|
|
|
};
|
2015-04-19 21:05:12 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.services.timesyncd.enable {
|
|
|
|
|
2015-04-19 21:11:14 +02:00
|
|
|
systemd.additionalUpstreamSystemUnits = [ "systemd-timesyncd.service" ];
|
|
|
|
|
2015-04-19 21:05:12 +02:00
|
|
|
systemd.services.systemd-timesyncd = {
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
|
|
|
restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."systemd/timesyncd.conf".text = ''
|
|
|
|
[Time]
|
2018-05-25 00:44:04 +02:00
|
|
|
NTP=${concatStringsSep " " config.services.timesyncd.servers}
|
2015-04-19 21:05:12 +02:00
|
|
|
'';
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.systemd-timesync.uid = config.ids.uids.systemd-timesync;
|
|
|
|
users.groups.systemd-timesync.gid = config.ids.gids.systemd-timesync;
|
2015-04-19 21:05:12 +02:00
|
|
|
|
2019-05-15 11:05:37 +02: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 21:05:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|