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