1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

nix-gc: rename frequency to dates

This commit is contained in:
Aguirre Matteo 2025-08-14 13:55:29 -03:00 committed by Austin Horstman
parent 3001400e9f
commit 6911d3e7f4
8 changed files with 87 additions and 10 deletions

View file

@ -5,7 +5,7 @@
...
}:
let
inherit (lib) mkOption types;
inherit (lib) mkChangedOptionModule mkOption types;
cfg = config.nix.gc;
@ -15,6 +15,12 @@ in
{
meta.maintainers = [ lib.maintainers.shivaraj-bh ];
imports = [
(mkChangedOptionModule [ "nix" "gc" "frequency" ] [ "nix" "gc" "dates" ] (
config: lib.toList (lib.getAttrFromPath [ "nix" "gc" "frequency" ] config)
))
];
options = {
nix.gc = {
automatic = mkOption {
@ -27,8 +33,9 @@ in
'';
};
frequency = mkOption {
type = types.str;
dates = mkOption {
type = with types; either singleLineStr (listOf str);
apply = lib.toList;
default = "weekly";
example = "03:15";
description = ''
@ -97,7 +104,7 @@ in
Description = "Nix Garbage Collector";
};
Timer = {
OnCalendar = "${cfg.frequency}";
OnCalendar = cfg.dates;
RandomizedDelaySec = cfg.randomizedDelaySec;
Persistent = cfg.persistent;
Unit = "nix-gc.service";
@ -110,7 +117,11 @@ in
(lib.mkIf pkgs.stdenv.isDarwin {
assertions = [
(lib.hm.darwin.assertInterval "nix.gc.frequency" cfg.frequency pkgs)
{
assertion = (lib.length cfg.dates) == 1;
message = "On Darwin, `nix.gc.dates` must contain a single element.";
}
(lib.hm.darwin.assertInterval "nix.gc.dates.*" (lib.elemAt cfg.dates 0) pkgs)
];
launchd.agents.nix-gc = {
@ -120,7 +131,7 @@ in
"${nixPackage}/bin/nix-collect-garbage"
]
++ lib.optional (cfg.options != null) cfg.options;
StartCalendarInterval = lib.hm.darwin.mkCalendarInterval cfg.frequency;
StartCalendarInterval = lib.hm.darwin.mkCalendarInterval (lib.elemAt cfg.dates 0);
};
};
})

View file

@ -1,7 +1,7 @@
{
nix.gc = {
automatic = true;
frequency = "monthly";
dates = "monthly";
options = "--delete-older-than 30d";
};

View file

@ -0,0 +1,21 @@
{ lib, options, ... }:
{
nix.gc = {
automatic = true;
frequency = "monthly";
options = "--delete-older-than 30d";
};
test.asserts.warnings.expected = [
"The option `nix.gc.frequency' defined in ${lib.showFiles options.nix.gc.frequency.files} has been changed to `nix.gc.dates' that has a different type. Please read `nix.gc.dates' documentation and update your configuration accordingly."
];
nmt.script = ''
serviceFile=LaunchAgents/org.nix-community.home.nix-gc.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./expected-agent.plist}
'';
}

View file

@ -1,10 +1,10 @@
{
nix.gc = {
automatic = true;
frequency = "00:02:03";
dates = "00:02:03";
};
test.asserts.assertions.expected = [
"On Darwin nix.gc.frequency must be one of: hourly, daily, weekly, monthly, semiannually, annually."
"On Darwin nix.gc.dates.* must be one of: hourly, daily, weekly, monthly, semiannually, annually."
];
}

View file

@ -1,4 +1,5 @@
{
nix-gc = ./basic.nix;
nix-gc-interval-assertion = ./darwin-nix-gc-interval-assertion.nix;
nix-gc-changed-options = ./changed-options.nix;
}

View file

@ -1,7 +1,7 @@
{
nix.gc = {
automatic = true;
frequency = "monthly";
dates = [ "monthly" ];
randomizedDelaySec = "42min";
options = "--delete-older-than 30d --max-freed $((64 * 1024**3))";
};

View file

@ -0,0 +1,43 @@
{ lib, options, ... }:
{
nix.gc = {
automatic = true;
frequency = "monthly";
randomizedDelaySec = "42min";
options = "--delete-older-than 30d --max-freed $((64 * 1024**3))";
};
test.asserts.warnings.expected = [
"The option `nix.gc.frequency' defined in ${lib.showFiles options.nix.gc.frequency.files} has been changed to `nix.gc.dates' that has a different type. Please read `nix.gc.dates' documentation and update your configuration accordingly."
];
nmt.script = ''
serviceFile=home-files/.config/systemd/user/nix-gc.service
assertFileExists $serviceFile
serviceFile=$(normalizeStorePaths $serviceFile)
assertFileContent $serviceFile ${./expected.service}
timerFile=home-files/.config/systemd/user/nix-gc.timer
assertFileExists $timerFile
timerFile=$(normalizeStorePaths $timerFile)
assertFileContent $timerFile ${./expected.timer}
nixgcScriptFile=$(grep -o \
'/nix/store/.*-nix-gc' \
$TESTED/home-files/.config/systemd/user/nix-gc.service
)
assertFileExists $nixgcScriptFile
nixgcScriptFile=$(normalizeStorePaths $nixgcScriptFile)
assertFileContent $nixgcScriptFile ${./nix-gc-script-expected}
'';
}

View file

@ -1,3 +1,4 @@
{
nix-gc = ./basic.nix;
nix-gc-changed-options = ./changed-options.nix;
}