at 15.09-beta 1.7 kB view raw
1{ pkgs, lib, config, options, ... }: 2 3with lib; 4 5let 6 cfg = config.services.openntpd; 7 8 package = pkgs.openntpd_nixos; 9 10 cfgFile = pkgs.writeText "openntpd.conf" '' 11 ${concatStringsSep "\n" (map (s: "server ${s}") cfg.servers)} 12 ${cfg.extraConfig} 13 ''; 14in 15{ 16 ###### interface 17 18 options.services.openntpd = { 19 enable = mkEnableOption "OpenNTP time synchronization server"; 20 21 servers = mkOption { 22 default = config.services.ntp.servers; 23 type = types.listOf types.str; 24 inherit (options.services.ntp.servers) description; 25 }; 26 27 extraConfig = mkOption { 28 type = with types; lines; 29 default = ""; 30 example = '' 31 listen on 127.0.0.1 32 listen on ::1 33 ''; 34 description = '' 35 Additional text appended to <filename>openntpd.conf</filename>. 36 ''; 37 }; 38 39 extraOptions = mkOption { 40 type = with types; string; 41 default = ""; 42 example = "-s"; 43 description = '' 44 Extra options used when launching openntpd. 45 ''; 46 }; 47 }; 48 49 ###### implementation 50 51 config = mkIf cfg.enable { 52 services.ntp.enable = mkForce false; 53 54 # Add ntpctl to the environment for status checking 55 environment.systemPackages = [ package ]; 56 57 users.extraUsers = singleton { 58 name = "ntp"; 59 uid = config.ids.uids.ntp; 60 description = "OpenNTP daemon user"; 61 home = "/var/empty"; 62 }; 63 64 systemd.services.openntpd = { 65 description = "OpenNTP Server"; 66 wantedBy = [ "multi-user.target" ]; 67 wants = [ "network-online.target" ]; 68 after = [ "dnsmasq.service" "bind.service" "network-online.target" ]; 69 serviceConfig.ExecStart = "${package}/sbin/ntpd -d -f ${cfgFile} ${cfg.extraOptions}"; 70 }; 71 }; 72}