Commit af0d1d90 authored by Felix Buehler's avatar Felix Buehler
Browse files

nixos/autoUpgrade: add runGarbageCollection option

parent 69a295cc
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -184,6 +184,15 @@ in
        '';
      };

      runGarbageCollection = lib.mkOption {
        type = lib.types.bool;
        default = false;
        description = ''
          Whether to automatically run `nix-gc.service` after a successful
          system upgrade.
        '';
      };

    };

  };
@@ -197,6 +206,12 @@ in
          The options 'system.autoUpgrade.channel' and 'system.autoUpgrade.flake' cannot both be set.
        '';
      }
      {
        assertion = (cfg.runGarbageCollection -> config.nix.enable);
        message = ''
          The option 'system.autoUpgrade.runGarbageCollection = true' requires 'nix.enable = true'.
        '';
      }
    ];

    system.autoUpgrade.flags = (
@@ -218,6 +233,9 @@ in

      restartIfChanged = false;
      unitConfig.X-StopOnRemoval = false;
      unitConfig.OnSuccess = lib.optional (
        cfg.runGarbageCollection && config.nix.enable
      ) "nix-gc.service";

      serviceConfig.Type = "oneshot";