Convert "ntp" daemon
svn path=/nixos/branches/fix-style/; revision=14374
This commit is contained in:
parent
b5f963bb8b
commit
2e93c3cdb9
@ -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 = {
|
portmap = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
@ -1565,6 +1542,7 @@ in
|
|||||||
(import ../upstart-jobs/dhcpd.nix)
|
(import ../upstart-jobs/dhcpd.nix)
|
||||||
(import ../upstart-jobs/sshd.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/lshd.nix) # GNU lshd SSH2 deamon (TODO: does neither start nor generate seed file ?)
|
||||||
|
(import ../upstart-jobs/ntpd.nix)
|
||||||
|
|
||||||
# nix
|
# nix
|
||||||
(import ../upstart-jobs/nix.nix) # nix options and daemon
|
(import ../upstart-jobs/nix.nix) # nix options and daemon
|
||||||
|
@ -148,14 +148,6 @@ let
|
|||||||
gnunetConfig = config.services.gnunet;
|
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.
|
# portmap daemon.
|
||||||
++ optional config.services.portmap.enable
|
++ optional config.services.portmap.enable
|
||||||
(import ../upstart-jobs/portmap.nix {
|
(import ../upstart-jobs/portmap.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
|
let
|
||||||
|
|
||||||
|
inherit (pkgs) writeText ntp;
|
||||||
|
|
||||||
stateDir = "/var/lib/ntp";
|
stateDir = "/var/lib/ntp";
|
||||||
|
|
||||||
ntpUser = "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
|
driftfile ${stateDir}/ntp.drift
|
||||||
|
|
||||||
${toString (map (server: "server " + server + "\n") servers)}
|
${toString (map (server: "server " + server + "\n") servers)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
ntpFlags = "-c ${config} -u ${ntpUser}:nogroup -i ${stateDir}";
|
ntpFlags = "-c ${configFile} -u ${ntpUser}:nogroup -i ${stateDir}";
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
|
||||||
name = "ntpd";
|
|
||||||
|
|
||||||
users = [
|
mkIf config.services.ntp.enable {
|
||||||
{ name = ntpUser;
|
require = [
|
||||||
uid = (import ../system/ids.nix).uids.ntp;
|
options
|
||||||
description = "NTP daemon user";
|
|
||||||
home = stateDir;
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
job = ''
|
services = {
|
||||||
description "NTP daemon"
|
extraJobs = [{
|
||||||
|
|
||||||
start on ip-up
|
name = "ntpd";
|
||||||
stop on ip-down
|
|
||||||
stop on shutdown
|
|
||||||
|
|
||||||
start script
|
users = [
|
||||||
|
{ name = ntpUser;
|
||||||
|
uid = (import ../system/ids.nix).uids.ntp;
|
||||||
|
description = "NTP daemon user";
|
||||||
|
home = stateDir;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
mkdir -m 0755 -p ${stateDir}
|
job = ''
|
||||||
chown ${ntpUser} ${stateDir}
|
description "NTP daemon"
|
||||||
|
|
||||||
# Needed to run ntpd as an unprivileged user.
|
start on ip-up
|
||||||
${modprobe}/sbin/modprobe capability || true
|
stop on ip-down
|
||||||
|
stop on shutdown
|
||||||
|
|
||||||
${ntp}/bin/ntpd -q -g ${ntpFlags}
|
start script
|
||||||
|
|
||||||
end script
|
mkdir -m 0755 -p ${stateDir}
|
||||||
|
chown ${ntpUser} ${stateDir}
|
||||||
|
|
||||||
respawn ${ntp}/bin/ntpd -n ${ntpFlags}
|
# 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}
|
||||||
|
'';
|
||||||
|
}];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user