2007-06-10 22:13:12 +02:00
|
|
|
{ntp, modprobe, glibc, writeText, servers}:
|
2006-12-22 00:43:17 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
stateDir = "/var/lib/ntp";
|
|
|
|
|
|
|
|
ntpUser = "ntp";
|
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
config = writeText "ntp.conf" ''
|
2009-03-11 16:01:13 +01: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-22 00:43:17 +01:00
|
|
|
|
|
|
|
${toString (map (server: "server " + server + "\n") servers)}
|
2008-03-20 15:38:49 +01:00
|
|
|
'';
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2006-12-22 20:29:18 +01:00
|
|
|
ntpFlags = "-c ${config} -u ${ntpUser}:nogroup -i ${stateDir}";
|
2006-12-22 20:23:19 +01:00
|
|
|
|
2006-12-22 00:43:17 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "ntpd";
|
|
|
|
|
2007-06-08 17:41:12 +02:00
|
|
|
users = [
|
|
|
|
{ name = ntpUser;
|
|
|
|
uid = (import ../system/ids.nix).uids.ntp;
|
|
|
|
description = "NTP daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
job = ''
|
|
|
|
description "NTP daemon"
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
start on ip-up
|
|
|
|
stop on ip-down
|
|
|
|
stop on shutdown
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
start script
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${ntpUser} ${stateDir}
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
# Needed to run ntpd as an unprivileged user.
|
|
|
|
${modprobe}/sbin/modprobe capability || true
|
2006-12-22 20:23:19 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
${ntp}/bin/ntpd -q -g ${ntpFlags}
|
2006-12-22 00:43:17 +01:00
|
|
|
|
2008-03-20 15:38:49 +01:00
|
|
|
end script
|
|
|
|
|
|
|
|
respawn ${ntp}/bin/ntpd -n ${ntpFlags}
|
|
|
|
'';
|
2006-12-22 00:43:17 +01:00
|
|
|
|
|
|
|
}
|