mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-22 05:33:23 +00:00
f037f6fbd4
* ntpd: start on ip-up, not when the network interfaces are up, otherwise it will fail because it can't find any servers right away. svn path=/nixos/trunk/; revision=7461
47 lines
752 B
Nix
47 lines
752 B
Nix
{ntp, glibc, pwdutils, writeText, servers}:
|
|
|
|
let
|
|
|
|
stateDir = "/var/lib/ntp";
|
|
|
|
ntpUser = "ntp";
|
|
|
|
config = writeText "ntp.conf" "
|
|
driftfile ${stateDir}/ntp.drift
|
|
|
|
${toString (map (server: "server " + server + "\n") servers)}
|
|
";
|
|
|
|
in
|
|
|
|
{
|
|
name = "ntpd";
|
|
|
|
job = "
|
|
description \"NTP daemon\"
|
|
|
|
start on ip-up
|
|
stop on ip-down
|
|
stop on shutdown
|
|
|
|
start script
|
|
|
|
if ! ${glibc}/bin/getent passwd ${ntpUser} > /dev/null; then
|
|
${pwdutils}/sbin/useradd -g nogroup -d ${stateDir} -s /noshell \\
|
|
-c 'NTP daemon user' ${ntpUser}
|
|
fi
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
chown ${ntpUser} ${stateDir}
|
|
|
|
date
|
|
${ntp}/bin/ntpd -c ${config} -q -g
|
|
date
|
|
|
|
end script
|
|
|
|
respawn ${ntp}/bin/ntpd -n -c ${config}
|
|
";
|
|
|
|
}
|