NTP

From NixOS Wiki
Revision as of 18:30, 10 September 2018 by imported>Symphorien (mention a trick to get the default value of an option, applied to ntp servers.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

NTP is a protocol to synchronise time and date information through a network. It is used to set the clock of your system automatically when your computer is connected to the internet.

NTP servers

To choose which servers to ask for time information to, use the networking.timeServers option. If you simply want to add a server to the default list, you can retrieve the default value of the option under the name options.networking.timeServers.default. Make sure to have options in the arguments at the beginning of the file:

/etc/nixos/configuration.nix
{ pkgs, lib, options, ...}
{
  networking.timeServers = options.networking.timeServers.default ++ [ "ntp.example.com" ]; 
}


NTP daemon

Different NTP daemons are available on NixOS. The default one is systemd-timesyncd. To switch to another implementation:

  • for ntpd, use services.ntp.enable = true;
  • for openntpd, use services.openntpd.enable = true;
  • for chrony, use services.chrony.enable = true;