mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 11:36:05 +01:00
services.nix-gc: extract darwin agent interval code to new library file
This commit is contained in:
parent
3b930bb653
commit
1c2fccef83
3 changed files with 80 additions and 66 deletions
76
modules/lib/darwin.nix
Normal file
76
modules/lib/darwin.nix
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
{ lib }:
|
||||
let
|
||||
intervals = [
|
||||
"hourly"
|
||||
"daily"
|
||||
"weekly"
|
||||
"monthly"
|
||||
"semiannually"
|
||||
"annually"
|
||||
];
|
||||
|
||||
mkCalendarInterval =
|
||||
frequency:
|
||||
let
|
||||
freq = {
|
||||
"hourly" = [ { Minute = 0; } ];
|
||||
"daily" = [
|
||||
{
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"weekly" = [
|
||||
{
|
||||
Weekday = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"monthly" = [
|
||||
{
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"semiannually" = [
|
||||
{
|
||||
Month = 1;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
{
|
||||
Month = 7;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"annually" = [
|
||||
{
|
||||
Month = 1;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
freq.${frequency} or null;
|
||||
|
||||
intervalsString = lib.concatStringsSep ", " intervals;
|
||||
|
||||
assertInterval = option: interval: pkgs: {
|
||||
assertion = (!pkgs.stdenv.isDarwin) || (lib.elem interval intervals);
|
||||
message = "On Darwin ${option} must be one of: ${intervalsString}.";
|
||||
};
|
||||
|
||||
intervalDocumentation = ''
|
||||
On Darwin it must be one of: ${intervalsString}, which are implemented as defined in {manpage}`systemd.time(7)`.
|
||||
'';
|
||||
in
|
||||
{
|
||||
inherit mkCalendarInterval assertInterval intervalDocumentation;
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ rec {
|
|||
assertions = import ./assertions.nix { inherit lib; };
|
||||
|
||||
booleans = import ./booleans.nix { inherit lib; };
|
||||
darwin = import ./darwin.nix { inherit lib; };
|
||||
deprecations = import ./deprecations.nix { inherit lib; };
|
||||
generators = import ./generators.nix { inherit lib; };
|
||||
gvariant = import ./gvariant.nix { inherit lib; };
|
||||
|
|
|
|||
|
|
@ -8,65 +8,6 @@ let
|
|||
inherit (lib) mkOption types;
|
||||
|
||||
cfg = config.nix.gc;
|
||||
darwinIntervals = [
|
||||
"hourly"
|
||||
"daily"
|
||||
"weekly"
|
||||
"monthly"
|
||||
"semiannually"
|
||||
"annually"
|
||||
];
|
||||
|
||||
mkCalendarInterval =
|
||||
frequency:
|
||||
let
|
||||
freq = {
|
||||
"hourly" = [ { Minute = 0; } ];
|
||||
"daily" = [
|
||||
{
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"weekly" = [
|
||||
{
|
||||
Weekday = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"monthly" = [
|
||||
{
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"semiannually" = [
|
||||
{
|
||||
Month = 1;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
{
|
||||
Month = 7;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
"annually" = [
|
||||
{
|
||||
Month = 1;
|
||||
Day = 1;
|
||||
Hour = 0;
|
||||
Minute = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
in
|
||||
freq.${frequency} or null;
|
||||
|
||||
nixPackage =
|
||||
if config.nix.enable && config.nix.package != null then config.nix.package else pkgs.nix;
|
||||
|
|
@ -95,8 +36,7 @@ in
|
|||
|
||||
On Linux this is a string as defined by {manpage}`systemd.time(7)`.
|
||||
|
||||
On Darwin it must be one of: ${lib.concatStringsSep ", " darwinIntervals}, which are
|
||||
implemented as defined in the manual page above.
|
||||
$lib.hm.darwin.{intervalDocumentation}
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -170,10 +110,7 @@ in
|
|||
|
||||
(lib.mkIf pkgs.stdenv.isDarwin {
|
||||
assertions = [
|
||||
{
|
||||
assertion = lib.elem cfg.frequency darwinIntervals;
|
||||
message = "On Darwin nix.gc.frequency must be one of: ${lib.concatStringsSep ", " darwinIntervals}.";
|
||||
}
|
||||
(lib.hm.darwin.assertInterval "nix.gc.frequency" cfg.frequency pkgs)
|
||||
];
|
||||
|
||||
launchd.agents.nix-gc = {
|
||||
|
|
@ -182,7 +119,7 @@ in
|
|||
ProgramArguments = [
|
||||
"${nixPackage}/bin/nix-collect-garbage"
|
||||
] ++ lib.optional (cfg.options != null) cfg.options;
|
||||
StartCalendarInterval = mkCalendarInterval cfg.frequency;
|
||||
StartCalendarInterval = lib.hm.darwin.mkCalendarInterval cfg.frequency;
|
||||
};
|
||||
};
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue