Convert "ntp" daemon

svn path=/nixos/branches/fix-style/; revision=14374
This commit is contained in:
Marc Weber 2009-03-06 12:26:19 +00:00
parent b5f963bb8b
commit 2e93c3cdb9
3 changed files with 78 additions and 59 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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}
'';
}];
};
}