Commit a40f80e4 authored by ccicnce113424's avatar ccicnce113424
Browse files

nixos/chrony: add NetworkManager dispatcher script

parent eb9f9778
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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.