nixpkgs/upstart-jobs/ntpd.nix
Eelco Dolstra 28567c4565 * ntpd: make the drift detection actually work when running in a chroot.
svn path=/nixos/trunk/; revision=14506
2009-03-11 15:01:13 +00:00

55 lines
1 KiB
Nix

{ntp, modprobe, glibc, writeText, servers}:
let
stateDir = "/var/lib/ntp";
ntpUser = "ntp";
config = writeText "ntp.conf" ''
# 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
${toString (map (server: "server " + server + "\n") servers)}
'';
ntpFlags = "-c ${config} -u ${ntpUser}:nogroup -i ${stateDir}";
in
{
name = "ntpd";
users = [
{ name = ntpUser;
uid = (import ../system/ids.nix).uids.ntp;
description = "NTP daemon user";
home = stateDir;
}
];
job = ''
description "NTP daemon"
start on ip-up
stop on ip-down
stop on shutdown
start script
mkdir -m 0755 -p ${stateDir}
chown ${ntpUser} ${stateDir}
# Needed to run ntpd as an unprivileged user.
${modprobe}/sbin/modprobe capability || true
${ntp}/bin/ntpd -q -g ${ntpFlags}
end script
respawn ${ntp}/bin/ntpd -n ${ntpFlags}
'';
}