NTP: Difference between revisions

imported>Tobias.bora
NTP and DHCP
imported>Tobias.bora
No edit summary
Line 59: Line 59:
The procedure depends on how you configure internet. By default (if you have not installed network manager…) the [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/tasks/network-interfaces-scripted.nix module <code>network-interfaces-scripted</code>] will be used… unfortunately as far as I know this script cannot deal with NTP.
The procedure depends on how you configure internet. By default (if you have not installed network manager…) the [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/tasks/network-interfaces-scripted.nix module <code>network-interfaces-scripted</code>] will be used… unfortunately as far as I know this script cannot deal with NTP.


If you use <code>systemd-networkd</code>, then it should automatically use the right NTP… However if you want the configuration to be automatic you want to use <code>networking.useNetworkd = true;</code> instead of <code>systemd.network.enable</code> (this last option requires further configuration), and <code>networking.useNetworkd</code> is apparently experimental now (2022) according to its documentation.
If you use <code>systemd-networkd</code>, then it should automatically use the right NTP… However if you want the configuration to be automatic you want to use <code>networking.useNetworkd = true;</code> instead of <code>systemd.network.enable</code> (this last option requires further configuration), and <code>networking.useNetworkd</code> is apparently experimental now (2022) according to its documentation. As far as I understand you can also '''disable''' the default behavior using:
<syntaxHighlight lang=nix>
systemd.network.config = {
  dhcpV4Config = { UseNTP = false; };
  dhcpV6Config = { UseNTP = false; };
}
</syntaxHighlight>
but I have not tested it.


If you use Network Manager, then Network Manager cannot (in 2022) automatically configure the NTP as-it… but you can use this trick to fake it, by automatically creating a new connection-specific NTP configuration every time the connection changes and restarting <code>systemd-timesyncd.service</code>:
If you use Network Manager, then Network Manager cannot (in 2022) automatically configure the NTP as-it… but you can use this trick to fake it, by automatically creating a new connection-specific NTP configuration every time the connection changes and restarting <code>systemd-timesyncd.service</code>: