ntpd-rs
Memory-safe implementation of IETF time standards including NTPv5 and NTS
Declared in: projects/ntpd-rs/default.nix
Try the service in a VM
-
Install Nix
- Bash
-
$ apt install --yes curl git jq nix
- Bash
-
$ apt install --yes curl git jq nix
- Bash
-
$ pacman --sync --refresh --noconfirm curl git jq nix
-
Download a configuration file
# default.nix { ngipkgs ? import (fetchTarball "https://github.com/ngi-nix/ngipkgs/tarball/main") { }, }: ngipkgs.demo-vm ( { lib, ... }: { services.timesyncd.enable = lib.mkForce false; services.ntpd-rs = { enable = true; useNetworkingTimeServers = false; settings = { synchronization.minimum-agreeing-sources = 1; source = [ { mode = "server"; address = "time.cloudflare.com"; } ]; }; }; } )
-
Enable binary substituters
- Bash
-
$ export NIX_CONFIG='substituters = https://cache.nixos.org/ https://ngi.cachix.org/ trusted-public-keys = cache.nixos.org-1:6nchdd59x431o0gwypbmraurkbj16zpmqfgspcdshjy= ngi.cachix.org-1:n+cal72roc3qqulxihpv+tw5t42whxmmhpragkrsrow='
-
Build and run a virtual machine
- Bash
-
$ nix-build ./default.nix && ./result
- Bash
-
$ nix-build ./default.nix && ./result
- Bash
-
$ rev=$(nix-instantiate --eval --attr sources.nixpkgs.rev https://github.com/ngi-nix/ngipkgs/archive/master.tar.gz | jq --raw-output)$ nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz --packages nix --run "nix-build ./default.nix && ./result"
- Bash
-
$ nix-build ./default.nix && ./result
-
Usage Instructions
-
To use
ntpd-rs, you need to first disable systemd-timesyncd (the default NTP client on NixOS). -
Then pick your time sources and configure them as described in the documentation.
-
The default
synchronization.minimum-agreeing-sourcesis 3, override it to a lower value if have fewer sources. If you startntpd-rsin client mode and having less sources than the configured value, the service will exit with an error. To check the synchronization status, usentp-ctl status.
-
Options
services.ntpd-rs
-
Whether to enable Network Time Service (ntpd-rs).
- Type:
boolean- Default:
false- Declared in:
- nixos/modules/services/networking/ntp/ntpd-rs.nix
-
Whether to enable ntpd-rs Prometheus Metrics Exporter.
- Type:
boolean- Default:
false- Declared in:
- nixos/modules/services/networking/ntp/ntpd-rs.nix
-
The ntpd-rs package to use.
- Type:
package- Default:
pkgs.ntpd-rs- Declared in:
- nixos/modules/services/networking/ntp/ntpd-rs.nix
-
Settings to write to {file}
ntp.tomlSee https://docs.ntpd-rs.pendulum-project.org/man/ntp.toml.5 for more information about available options.
- Type:
open submodule of (TOML value)- Default:
{ }- Declared in:
- nixos/modules/services/networking/ntp/ntpd-rs.nix
-
Use source time servers from {var}
networking.timeServersin config.- Type:
boolean- Default:
true- Declared in:
- nixos/modules/services/networking/ntp/ntpd-rs.nix
services.ntpd-rs.enable
services.ntpd-rs.metrics.enable
services.ntpd-rs.package
services.ntpd-rs.settings
services.ntpd-rs.useNetworkingTimeServers
Examples
Replace the default `timesyncd` service with `ntpd-rs`
{ lib, ... }: { services.timesyncd.enable = lib.mkForce false; services.ntpd-rs = { enable = true; useNetworkingTimeServers = false; settings = { synchronization.minimum-agreeing-sources = 1; source = [ { mode = "server"; address = "time.cloudflare.com"; } ]; }; }; }
Declared in: projects/ntpd-rs/examples/basic.nix
Run `ntpd-rs` in server mode with observability features
# example extracted from official NixOS test # https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/ntpd-rs.nix { networking.firewall = { allowedTCPPorts = [ 9975 ]; allowedUDPPorts = [ 123 ]; }; services.ntpd-rs = { enable = true; metrics.enable = true; settings = { observability.metrics-exporter-listen = "[::]:9975"; server = [ { listen = "[::]:123"; } ]; }; }; }
Declared in: projects/ntpd-rs/examples/server.nix
Use NTS (Network Time Security) servers instead with `ntpd-rs`
{ lib, ... }: { services.timesyncd.enable = lib.mkForce false; services.ntpd-rs = { enable = true; useNetworkingTimeServers = false; settings.source = ( map (s: { mode = "nts"; address = s; }) [ "brazil.time.system76.com" "ohio.time.system76.com" "oregon.time.system76.com" "paris.time.system76.com" "virginia.time.system76.com" ] ); }; }
Declared in: projects/ntpd-rs/examples/nts.nix
This project is funded by NLnet through these subgrants:
- Entrust
- ntpd-rs
Related links: