diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index a2862a6d609b..045eb469de94 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -231,6 +231,7 @@ ./services/networking/ntpd.nix ./services/networking/oidentd.nix ./services/networking/openfire.nix + ./services/networking/openntpd.nix ./services/networking/openvpn.nix ./services/networking/polipo.nix ./services/networking/prayer.nix diff --git a/nixos/modules/services/networking/openntpd.nix b/nixos/modules/services/networking/openntpd.nix new file mode 100644 index 000000000000..bd8a7a04a2af --- /dev/null +++ b/nixos/modules/services/networking/openntpd.nix @@ -0,0 +1,49 @@ +{ pkgs, lib, config, options, ... }: + +with lib; + +let + cfg = config.services.openntpd; + + package = pkgs.openntpd.override { + privsepUser = "ntp"; + privsepPath = "/var/empty"; + }; + + cfgFile = pkgs.writeText "openntpd.conf" '' + ${concatStringsSep "\n" (map (s: "server ${s}") cfg.servers)} + ''; +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; + }; + }; + + ###### implementation + + config = mkIf cfg.enable { + services.ntp.enable = mkForce false; + + users.extraUsers = singleton { + name = "ntp"; + uid = config.ids.uids.ntp; + description = "OpenNTP daemon user"; + home = "/var/empty"; + }; + + systemd.services.openntpd = { + description = "OpenNTP Server"; + wantedBy = [ "ip-up.target" ]; + partOf = [ "ip-up.target" ]; + serviceConfig.ExecStart = "${package}/sbin/ntpd -d -f ${cfgFile}"; + }; + }; +}