services.*ntp*: Add time-sync.target to ntp clients (#15714)

See: https://www.freedesktop.org/software/systemd/man/systemd.special.html#time-sync.target

authored by

Alexander Ried and committed by
Franz Pletz
8fbdb40e a2f21a54

+8 -3
+4 -2
nixos/modules/services/networking/chrony.nix
··· 64 64 65 65 ###### implementation 66 66 67 - config = mkIf config.services.chrony.enable { 67 + config = mkIf cfg.enable { 68 68 69 69 # Make chronyc available in the system path 70 70 environment.systemPackages = [ pkgs.chrony ]; ··· 101 101 home = stateDir; 102 102 }; 103 103 104 - systemd.services.ntpd.enable = false; 104 + systemd.services.ntpd.enable = mkForce false; 105 105 106 106 systemd.services.chronyd = 107 107 { description = "chrony NTP daemon"; 108 108 109 109 wantedBy = [ "multi-user.target" ]; 110 + wants = [ "time-sync.target" ]; 111 + before = [ "time-sync.target" ]; 110 112 after = [ "network.target" ]; 111 113 conflicts = [ "ntpd.service" "systemd-timesyncd.service" ]; 112 114
+2
nixos/modules/services/networking/ntpd.nix
··· 82 82 { description = "NTP Daemon"; 83 83 84 84 wantedBy = [ "multi-user.target" ]; 85 + wants = [ "time-sync.target" ]; 86 + before = [ "time-sync.target" ]; 85 87 86 88 preStart = 87 89 ''
+2 -1
nixos/modules/services/networking/openntpd.nix
··· 64 64 systemd.services.openntpd = { 65 65 description = "OpenNTP Server"; 66 66 wantedBy = [ "multi-user.target" ]; 67 - wants = [ "network-online.target" ]; 67 + wants = [ "network-online.target" "time-sync.target" ]; 68 + before = [ "time-sync.target" ]; 68 69 after = [ "dnsmasq.service" "bind.service" "network-online.target" ]; 69 70 serviceConfig.ExecStart = "${package}/sbin/ntpd -d -f ${cfgFile} ${cfg.extraOptions}"; 70 71 };