diff --git a/system/options.nix b/system/options.nix index f952be1ddb1d..31dc9c60443c 100644 --- a/system/options.nix +++ b/system/options.nix @@ -480,29 +480,6 @@ in }; - 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. - "; - }; - - }; - portmap = { enable = mkOption { @@ -1565,6 +1542,7 @@ in (import ../upstart-jobs/dhcpd.nix) (import ../upstart-jobs/sshd.nix) (import ../upstart-jobs/lshd.nix) # GNU lshd SSH2 deamon (TODO: does neither start nor generate seed file ?) + (import ../upstart-jobs/ntpd.nix) # nix (import ../upstart-jobs/nix.nix) # nix options and daemon diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 0d8d2987d2ce..b912fbee5a28 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -148,14 +148,6 @@ let gnunetConfig = config.services.gnunet; }) - # NTP daemon. - ++ optional config.services.ntp.enable - (import ../upstart-jobs/ntpd.nix { - inherit modprobe; - inherit (pkgs) ntp glibc writeText; - servers = config.services.ntp.servers; - }) - # portmap daemon. ++ optional config.services.portmap.enable (import ../upstart-jobs/portmap.nix { diff --git a/upstart-jobs/ntpd.nix b/upstart-jobs/ntpd.nix index 4bfcfe115cbb..9716ce3f308d 100644 --- a/upstart-jobs/ntpd.nix +++ b/upstart-jobs/ntpd.nix @@ -1,52 +1,101 @@ -{ntp, modprobe, glibc, writeText, servers}: +{pkgs, config, ...}: + +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + 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. + "; + }; + + }; + }; + }; +in + +###### implementation let + inherit (pkgs) writeText ntp; + stateDir = "/var/lib/ntp"; ntpUser = "ntp"; - config = writeText "ntp.conf" '' + servers = config.services.ntp.servers; + + modprobe = config.system.sbin.modprobe; + + configFile = writeText "ntp.conf" '' driftfile ${stateDir}/ntp.drift ${toString (map (server: "server " + server + "\n") servers)} ''; - ntpFlags = "-c ${config} -u ${ntpUser}:nogroup -i ${stateDir}"; + ntpFlags = "-c ${configFile} -u ${ntpUser}:nogroup -i ${stateDir}"; in -{ - name = "ntpd"; - - users = [ - { name = ntpUser; - uid = (import ../system/ids.nix).uids.ntp; - description = "NTP daemon user"; - home = stateDir; - } + +mkIf config.services.ntp.enable { + require = [ + options ]; - - job = '' - description "NTP daemon" - start on ip-up - stop on ip-down - stop on shutdown + services = { + extraJobs = [{ - start script + name = "ntpd"; + + users = [ + { name = ntpUser; + uid = (import ../system/ids.nix).uids.ntp; + description = "NTP daemon user"; + home = stateDir; + } + ]; + + job = '' + description "NTP daemon" - mkdir -m 0755 -p ${stateDir} - chown ${ntpUser} ${stateDir} + start on ip-up + stop on ip-down + stop on shutdown - # Needed to run ntpd as an unprivileged user. - ${modprobe}/sbin/modprobe capability || true + start script - ${ntp}/bin/ntpd -q -g ${ntpFlags} + mkdir -m 0755 -p ${stateDir} + chown ${ntpUser} ${stateDir} - end script + # Needed to run ntpd as an unprivileged user. + ${modprobe}/sbin/modprobe capability || true - respawn ${ntp}/bin/ntpd -n ${ntpFlags} - ''; - + ${ntp}/bin/ntpd -q -g ${ntpFlags} + + end script + + respawn ${ntp}/bin/ntpd -n ${ntpFlags} + ''; + }]; + }; }