1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-14 08:34:50 +00:00
nixpkgs/modules/services/networking/ntpd.nix
Eelco Dolstra 102a1e15ba * Use the "iburst" flag. This makes ntpd synchronise in a few seconds rather than
a few minutes by sending an initial burst of messages to the time servers.

svn path=/nixos/trunk/; revision=24119
2010-10-06 16:03:37 +00:00

100 lines
2.1 KiB
Nix

{ config, pkgs, ... }:
with pkgs.lib;
let
inherit (pkgs) ntp;
stateDir = "/var/lib/ntp";
ntpUser = "ntp";
servers = config.services.ntp.servers;
modprobe = config.system.sbin.modprobe;
configFile = pkgs.writeText "ntp.conf" ''
driftfile ${stateDir}/ntp.drift
# 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 + " iburst\n") servers)}
'';
ntpFlags = "-c ${configFile} -u ${ntpUser}:nogroup -i ${stateDir}";
in
{
###### interface
options = {
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
config = mkIf config.services.ntp.enable {
users.extraUsers = singleton
{ name = ntpUser;
uid = config.ids.uids.ntp;
description = "NTP daemon user";
home = stateDir;
};
jobs.ntpd =
{ description = "NTP daemon";
startOn = "ip-up";
preStart =
''
mkdir -m 0755 -p ${stateDir}
chown ${ntpUser} ${stateDir}
# Needed to run ntpd as an unprivileged user.
${modprobe}/sbin/modprobe --quiet capability || true
# !!! This can hang indefinitely if the network is down or
# the servers are unreachable. This is particularly bad
# because Upstart cannot kill jobs stuck in the start
# phase. Thus a hanging ntpd job can block system
# shutdown.
# ${ntp}/bin/ntpd -q -g ${ntpFlags}
'';
exec = "${ntp}/bin/ntpd -g -n ${ntpFlags}";
};
};
}