nixos/autoUpgrade: add runGarbageCollection option (#441565)

This commit is contained in:
Felix Bühler
2025-11-15 10:59:24 +00:00
committed by GitHub

View File

@@ -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";