2014-09-01 14:14:00 +01:00
|
|
|
{ pkgs, lib, config, options, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.openntpd;
|
|
|
|
|
2015-02-05 01:30:22 +00:00
|
|
|
package = pkgs.openntpd_nixos;
|
2014-09-01 14:14:00 +01:00
|
|
|
|
2018-03-03 23:30:00 +00:00
|
|
|
configFile = ''
|
2014-09-01 14:14:00 +01:00
|
|
|
${concatStringsSep "\n" (map (s: "server ${s}") cfg.servers)}
|
2015-01-23 15:15:20 +00:00
|
|
|
${cfg.extraConfig}
|
2014-09-01 14:14:00 +01:00
|
|
|
'';
|
2017-02-16 23:08:06 +00:00
|
|
|
|
|
|
|
pidFile = "/run/openntpd.pid";
|
|
|
|
|
2014-09-01 14:14:00 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.openntpd = {
|
|
|
|
enable = mkEnableOption "OpenNTP time synchronization server";
|
|
|
|
|
|
|
|
servers = mkOption {
|
|
|
|
default = config.services.ntp.servers;
|
|
|
|
type = types.listOf types.str;
|
|
|
|
inherit (options.services.ntp.servers) description;
|
|
|
|
};
|
2015-01-23 15:15:20 +00:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = with types; lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
2018-03-03 23:30:00 +00:00
|
|
|
listen on 127.0.0.1
|
|
|
|
listen on ::1
|
2015-01-23 15:15:20 +00:00
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Additional text appended to <filename>openntpd.conf</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = with types; string;
|
|
|
|
default = "";
|
|
|
|
example = "-s";
|
|
|
|
description = ''
|
|
|
|
Extra options used when launching openntpd.
|
|
|
|
'';
|
|
|
|
};
|
2014-09-01 14:14:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2016-12-14 22:49:14 +00:00
|
|
|
services.timesyncd.enable = mkForce false;
|
2014-09-01 14:14:00 +01:00
|
|
|
|
2015-02-05 01:26:52 +00:00
|
|
|
# Add ntpctl to the environment for status checking
|
2015-02-05 01:30:22 +00:00
|
|
|
environment.systemPackages = [ package ];
|
2015-02-05 01:26:52 +00:00
|
|
|
|
2018-03-03 23:30:00 +00:00
|
|
|
environment.etc."ntpd.conf".text = configFile;
|
|
|
|
|
2014-09-01 14:14:00 +01:00
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "ntp";
|
|
|
|
uid = config.ids.uids.ntp;
|
|
|
|
description = "OpenNTP daemon user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.openntpd = {
|
|
|
|
description = "OpenNTP Server";
|
2014-11-26 19:19:31 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-05-26 15:25:36 +01:00
|
|
|
wants = [ "network-online.target" "time-sync.target" ];
|
|
|
|
before = [ "time-sync.target" ];
|
2015-02-06 22:45:41 +00:00
|
|
|
after = [ "dnsmasq.service" "bind.service" "network-online.target" ];
|
2017-02-16 23:08:06 +00:00
|
|
|
serviceConfig = {
|
2018-03-03 23:30:00 +00:00
|
|
|
ExecStart = "${package}/sbin/ntpd -p ${pidFile} ${cfg.extraOptions}";
|
2017-02-16 23:08:06 +00:00
|
|
|
Type = "forking";
|
|
|
|
PIDFile = pidFile;
|
|
|
|
};
|
2014-09-01 14:14:00 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|