2009-10-12 17:09:38 +00:00
|
|
|
{ config, pkgs, ... }:
|
2006-12-21 23:43:17 +00:00
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
with pkgs.lib;
|
2009-03-06 12:26:19 +00:00
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
let
|
2009-03-06 12:26:19 +00:00
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
inherit (pkgs) ntp;
|
2006-12-21 23:43:17 +00:00
|
|
|
|
|
|
|
stateDir = "/var/lib/ntp";
|
|
|
|
|
|
|
|
ntpUser = "ntp";
|
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
configFile = pkgs.writeText "ntp.conf" ''
|
2009-03-11 15:01:13 +00:00
|
|
|
# Keep the drift file in ${stateDir}/ntp.drift. However, since we
|
|
|
|
# chroot to ${stateDir}, we have to specify it as /ntp.drift.
|
|
|
|
driftfile /ntp.drift
|
2006-12-21 23:43:17 +00:00
|
|
|
|
2012-03-17 17:26:17 +00:00
|
|
|
${toString (map (server: "server " + server + " iburst\n") config.services.ntp.servers)}
|
2008-03-20 14:38:49 +00:00
|
|
|
'';
|
2006-12-21 23:43:17 +00:00
|
|
|
|
2009-03-06 12:26:19 +00:00
|
|
|
ntpFlags = "-c ${configFile} -u ${ntpUser}:nogroup -i ${stateDir}";
|
2006-12-22 19:23:19 +00:00
|
|
|
|
2006-12-21 23:43:17 +00:00
|
|
|
in
|
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
services.ntp = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to synchronise your machine's time using the NTP
|
|
|
|
protocol.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
servers = mkOption {
|
|
|
|
default = [
|
|
|
|
"0.pool.ntp.org"
|
|
|
|
"1.pool.ntp.org"
|
|
|
|
"2.pool.ntp.org"
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
The set of NTP servers from which to synchronise.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
2009-03-06 12:26:19 +00:00
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
config = mkIf config.services.ntp.enable {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-07-15 11:34:55 +00:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = ntpUser;
|
|
|
|
uid = config.ids.uids.ntp;
|
|
|
|
description = "NTP daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
2006-12-21 23:43:17 +00:00
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.ntpd =
|
2013-01-10 12:59:41 +00:00
|
|
|
{ description = "NTP Daemon";
|
2006-12-21 23:43:17 +00:00
|
|
|
|
2012-08-15 19:38:52 +00:00
|
|
|
wantedBy = [ "ip-up.target" ];
|
|
|
|
partOf = [ "ip-up.target" ];
|
2006-12-22 19:23:19 +00:00
|
|
|
|
2011-11-25 16:32:54 +00:00
|
|
|
path = [ ntp ];
|
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
preStart =
|
|
|
|
''
|
2009-03-06 12:26:19 +00:00
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${ntpUser} ${stateDir}
|
2009-10-12 17:09:38 +00:00
|
|
|
'';
|
2009-03-06 12:26:19 +00:00
|
|
|
|
2011-11-25 16:32:54 +00:00
|
|
|
exec = "ntpd -g -n ${ntpFlags}";
|
2009-10-12 17:09:38 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-03-06 12:26:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2006-12-21 23:43:17 +00:00
|
|
|
}
|