From 8584d7ec31e6df40a05165b60d1bddbe16c328a0 Mon Sep 17 00:00:00 2001 From: ccicnce113424 Date: Fri, 23 Jan 2026 11:44:57 +0800 Subject: [PATCH 1/3] nixos/chrony: add makestep option --- .../services/networking/ntp/chrony.nix | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/ntp/chrony.nix b/nixos/modules/services/networking/ntp/chrony.nix index a76a642805bc..c23b0d858be9 100644 --- a/nixos/modules/services/networking/ntp/chrony.nix +++ b/nixos/modules/services/networking/ntp/chrony.nix @@ -23,6 +23,8 @@ let cfg.initstepslew.enabled && (cfg.servers != [ ]) ) "initstepslew ${toString cfg.initstepslew.threshold} ${lib.concatStringsSep " " cfg.servers}"} + ${lib.optionalString cfg.makestep.enable "makestep ${toString cfg.makestep.threshold} ${toString cfg.makestep.limit}"} + driftfile ${driftFile} keyfile ${keyFile} ${lib.optionalString (cfg.enableRTCTrimming) "rtcfile ${rtcFile}"} @@ -134,8 +136,9 @@ in initstepslew = { enabled = lib.mkOption { type = lib.types.bool; - default = true; + default = false; description = '' + DEPRECATED. Consider using `services.chrony.makestep` instead. Allow chronyd to make a rapid measurement of the system clock error at boot time, and to correct the system clock by stepping before normal operation begins. @@ -153,6 +156,35 @@ in }; }; + makestep = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Allow chronyd to step the system clock if the error is larger than + the specified threshold. + ''; + }; + + threshold = lib.mkOption { + type = lib.types.either lib.types.float lib.types.int; + default = 0.1; + description = '' + The threshold of system clock error (in seconds) above which the + clock will be stepped. If the correction required is less than the + threshold, a slew is used instead. + ''; + }; + + limit = lib.mkOption { + type = lib.types.ints.positive; + default = 3; + description = '' + The maximum number of times the system clock will be stepped. + ''; + }; + }; + directory = lib.mkOption { type = lib.types.str; default = "/var/lib/chrony"; From eb9f97786be40a3c6aa5e85dca78105ec21c596e Mon Sep 17 00:00:00 2001 From: ccicnce113424 Date: Fri, 23 Jan 2026 11:51:40 +0800 Subject: [PATCH 2/3] nixos/chrony: use `pool` option for pool server --- nixos/modules/services/networking/ntp/chrony.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/ntp/chrony.nix b/nixos/modules/services/networking/ntp/chrony.nix index c23b0d858be9..a04231852907 100644 --- a/nixos/modules/services/networking/ntp/chrony.nix +++ b/nixos/modules/services/networking/ntp/chrony.nix @@ -16,7 +16,12 @@ let configFile = pkgs.writeText "chrony.conf" '' ${lib.concatMapStringsSep "\n" ( - server: "server " + server + " " + cfg.serverOption + lib.optionalString (cfg.enableNTS) " nts" + server: + (if lib.strings.hasInfix "pool" server then "pool " else "server ") + + server + + " " + + cfg.serverOption + + lib.optionalString (cfg.enableNTS) " nts" ) cfg.servers} ${lib.optionalString ( From a40f80e47fa78823f7b2827fb94296e7316f328d Mon Sep 17 00:00:00 2001 From: ccicnce113424 Date: Fri, 23 Jan 2026 12:21:36 +0800 Subject: [PATCH 3/3] nixos/chrony: add NetworkManager dispatcher script --- .../services/networking/ntp/chrony.nix | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/nixos/modules/services/networking/ntp/chrony.nix b/nixos/modules/services/networking/ntp/chrony.nix index a04231852907..06638993e3de 100644 --- a/nixos/modules/services/networking/ntp/chrony.nix +++ b/nixos/modules/services/networking/ntp/chrony.nix @@ -50,6 +50,20 @@ let ] ++ lib.optional cfg.enableMemoryLocking "-m" ++ cfg.extraFlags; + + dispathcerScriptFile = pkgs.callPackage ( + { + runCommand, + srcOnly, + }: + runCommand "10-chrony-onoffline" { } '' + cp ${srcOnly chronyPkg}/examples/chrony.nm-dispatcher.onoffline $out + substituteInPlace $out \ + --replace-fail '/usr/bin/chronyc' '${chronyPkg}/bin/chronyc' + chmod +x $out + patchShebangs $out + '' + ) { }; in { options = { @@ -196,6 +210,16 @@ in description = "Directory where chrony state is stored."; }; + dispatcherScript = lib.mkOption { + type = lib.types.bool; + default = config.networking.networkmanager.enable; + defaultText = lib.literalExpression "config.networking.networkmanager.enable"; + description = '' + Whether to install the chrony NetworkManager dispatcher script + to handle connectivity changes. + ''; + }; + extraConfig = lib.mkOption { type = lib.types.lines; default = ""; @@ -231,6 +255,13 @@ in home = stateDir; }; + networking.networkmanager.dispatcherScripts = lib.mkIf cfg.dispatcherScript [ + { + type = "basic"; + source = dispathcerScriptFile; + } + ]; + services.timesyncd.enable = lib.mkForce false; # If chrony controls and tracks the RTC, writing it externally causes clock error.