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.