1 { lib, config, pkgs, ... }:
4 cfg = config.services.ntpd-rs;
5 format = pkgs.formats.toml { };
6 configFile = format.generate "ntpd-rs.toml" cfg.settings;
9 options.services.ntpd-rs = {
10 enable = lib.mkEnableOption "Network Time Service (ntpd-rs)";
11 metrics.enable = lib.mkEnableOption "ntpd-rs Prometheus Metrics Exporter";
13 package = lib.mkPackageOption pkgs "ntpd-rs" { };
15 useNetworkingTimeServers = lib.mkOption {
16 type = lib.types.bool;
19 Use source time servers from {var}`networking.timeServers` in config.
23 settings = lib.mkOption {
24 type = lib.types.submodule {
25 freeformType = format.type;
29 Settings to write to {file}`ntp.toml`
31 See <https://docs.ntpd-rs.pendulum-project.org/man/ntp.toml.5>
32 for more information about available options.
37 config = lib.mkIf cfg.enable {
40 assertion = !config.services.timesyncd.enable;
42 `ntpd-rs` is not compatible with `services.timesyncd`. Please disable one of them.
47 environment.systemPackages = [ cfg.package ];
48 systemd.packages = [ cfg.package ];
50 services.timesyncd.enable = false;
51 systemd.services.systemd-timedated.environment = {
52 SYSTEMD_TIMEDATED_NTP_SERVICES = "ntpd-rs.service";
55 services.ntpd-rs.settings = {
57 observation-path = lib.mkDefault "/var/run/ntpd-rs/observe";
59 source = lib.mkIf cfg.useNetworkingTimeServers (map
64 config.networking.timeServers);
67 systemd.services.ntpd-rs = {
68 wantedBy = [ "multi-user.target" ];
73 ExecStart = [ "" "${lib.makeBinPath [ cfg.package ]}/ntp-daemon --config=${configFile}" ];
77 systemd.services.ntpd-rs-metrics = lib.mkIf cfg.metrics.enable {
78 wantedBy = [ "multi-user.target" ];
83 ExecStart = [ "" "${lib.makeBinPath [ cfg.package ]}/ntp-metrics-exporter --config=${configFile}" ];
88 meta.maintainers = with lib.maintainers; [ fpletz ];