9 cfg = config.services.ntpd-rs;
10 format = pkgs.formats.toml { };
11 configFile = format.generate "ntpd-rs.toml" cfg.settings;
14 options.services.ntpd-rs = {
15 enable = lib.mkEnableOption "Network Time Service (ntpd-rs)";
16 metrics.enable = lib.mkEnableOption "ntpd-rs Prometheus Metrics Exporter";
18 package = lib.mkPackageOption pkgs "ntpd-rs" { };
20 useNetworkingTimeServers = lib.mkOption {
21 type = lib.types.bool;
24 Use source time servers from {var}`networking.timeServers` in config.
28 settings = lib.mkOption {
29 type = lib.types.submodule {
30 freeformType = format.type;
34 Settings to write to {file}`ntp.toml`
36 See <https://docs.ntpd-rs.pendulum-project.org/man/ntp.toml.5>
37 for more information about available options.
42 config = lib.mkIf cfg.enable {
45 assertion = !config.services.timesyncd.enable;
47 `ntpd-rs` is not compatible with `services.timesyncd`. Please disable one of them.
52 environment.systemPackages = [ cfg.package ];
53 systemd.packages = [ cfg.package ];
55 services.timesyncd.enable = false;
56 systemd.services.systemd-timedated.environment = {
57 SYSTEMD_TIMEDATED_NTP_SERVICES = "ntpd-rs.service";
60 services.ntpd-rs.settings = {
62 observation-path = lib.mkDefault "/var/run/ntpd-rs/observe";
64 source = lib.mkIf cfg.useNetworkingTimeServers (
68 }) config.networking.timeServers
72 systemd.services.ntpd-rs = {
73 wantedBy = [ "multi-user.target" ];
80 "${lib.makeBinPath [ cfg.package ]}/ntp-daemon --config=${configFile}"
85 systemd.services.ntpd-rs-metrics = lib.mkIf cfg.metrics.enable {
86 wantedBy = [ "multi-user.target" ];
93 "${lib.makeBinPath [ cfg.package ]}/ntp-metrics-exporter --config=${configFile}"
99 meta.maintainers = with lib.maintainers; [ fpletz ];