2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-05-23 03:07:49 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-05-23 03:07:49 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs) chrony;
|
|
|
|
|
|
|
|
stateDir = "/var/lib/chrony";
|
|
|
|
|
2015-07-12 06:13:04 +01:00
|
|
|
keyFile = "/etc/chrony.keys";
|
2013-05-23 03:07:49 +01:00
|
|
|
|
2013-05-23 04:00:09 +01:00
|
|
|
cfg = config.services.chrony;
|
|
|
|
|
2013-05-23 03:07:49 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.chrony = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to synchronise your machine's time using chrony.
|
|
|
|
Make sure you disable NTP if you enable this service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
servers = mkOption {
|
2015-07-12 05:01:41 +01:00
|
|
|
default = config.services.ntp.servers;
|
2013-05-23 03:07:49 +01:00
|
|
|
description = ''
|
|
|
|
The set of NTP servers from which to synchronise.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-05-23 04:00:09 +01:00
|
|
|
initstepslew = mkOption {
|
|
|
|
default = {
|
|
|
|
enabled = true;
|
|
|
|
threshold = 1000; # by default, same threshold as 'ntpd -g' (1000s)
|
|
|
|
servers = cfg.servers;
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Allow chronyd to make a rapid measurement of the system clock error at
|
|
|
|
boot time, and to correct the system clock by stepping before normal
|
|
|
|
operation begins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2016-10-23 18:33:41 +01:00
|
|
|
type = types.lines;
|
2013-05-23 04:00:09 +01:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration directives that should be added to
|
|
|
|
<literal>chrony.conf</literal>
|
|
|
|
'';
|
|
|
|
};
|
2013-05-23 03:07:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2016-05-26 15:25:36 +01:00
|
|
|
config = mkIf cfg.enable {
|
2013-05-23 03:07:49 +01:00
|
|
|
|
|
|
|
# Make chronyc available in the system path
|
|
|
|
environment.systemPackages = [ pkgs.chrony ];
|
|
|
|
|
2015-07-12 06:13:04 +01:00
|
|
|
environment.etc."chrony.conf".text =
|
|
|
|
''
|
|
|
|
${concatMapStringsSep "\n" (server: "server " + server) cfg.servers}
|
|
|
|
|
|
|
|
${optionalString
|
|
|
|
cfg.initstepslew.enabled
|
|
|
|
"initstepslew ${toString cfg.initstepslew.threshold} ${concatStringsSep " " cfg.initstepslew.servers}"
|
|
|
|
}
|
|
|
|
|
|
|
|
driftfile ${stateDir}/chrony.drift
|
|
|
|
|
|
|
|
keyfile ${keyFile}
|
|
|
|
generatecommandkey
|
|
|
|
|
|
|
|
${optionalString (!config.time.hardwareClockInLocalTime) "rtconutc"}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "chrony";
|
|
|
|
gid = config.ids.gids.chrony;
|
|
|
|
};
|
2015-07-12 05:01:41 +01:00
|
|
|
|
2013-05-23 03:07:49 +01:00
|
|
|
users.extraUsers = singleton
|
2015-07-12 06:13:04 +01:00
|
|
|
{ name = "chrony";
|
2013-05-23 03:07:49 +01:00
|
|
|
uid = config.ids.uids.chrony;
|
2015-07-12 06:13:04 +01:00
|
|
|
group = "chrony";
|
2013-05-23 03:07:49 +01:00
|
|
|
description = "chrony daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2016-05-26 15:25:36 +01:00
|
|
|
systemd.services.ntpd.enable = mkForce false;
|
2015-07-12 06:13:04 +01:00
|
|
|
|
|
|
|
systemd.services.chronyd =
|
|
|
|
{ description = "chrony NTP daemon";
|
2013-05-23 03:07:49 +01:00
|
|
|
|
2014-11-26 19:19:31 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-05-26 15:25:36 +01:00
|
|
|
wants = [ "time-sync.target" ];
|
|
|
|
before = [ "time-sync.target" ];
|
2014-11-26 19:19:31 +00:00
|
|
|
after = [ "network.target" ];
|
2015-07-12 05:01:41 +01:00
|
|
|
conflicts = [ "ntpd.service" "systemd-timesyncd.service" ];
|
2013-05-23 03:07:49 +01:00
|
|
|
|
2015-07-12 06:13:04 +01:00
|
|
|
path = [ pkgs.chrony ];
|
2013-05-23 03:07:49 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
2015-07-12 06:13:04 +01:00
|
|
|
touch ${keyFile}
|
|
|
|
chmod 0640 ${keyFile}
|
|
|
|
chown chrony:chrony ${stateDir} ${keyFile}
|
2013-05-23 03:07:49 +01:00
|
|
|
'';
|
|
|
|
|
2015-07-12 06:13:04 +01:00
|
|
|
serviceConfig =
|
|
|
|
{ ExecStart = "${pkgs.chrony}/bin/chronyd -n -m -u chrony";
|
|
|
|
};
|
2013-05-23 03:07:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|