-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule.nix
108 lines (105 loc) · 2.79 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.angrr;
in
{
options = {
services.angrr = {
enable = lib.mkEnableOption "angrr";
package = lib.mkPackageOption pkgs "angrr" { };
timer = {
enable = lib.mkEnableOption "angrr timer";
dates = lib.mkOption {
type = with lib.types; str;
default = "03:00";
description = ''
How often or when the retention policy is performed.
'';
};
};
enableNixGcIntegration = lib.mkOption {
type = with lib.types; bool;
description = ''
Whether to enable nix-gc.service integration
'';
};
period = lib.mkOption {
type = with lib.types; str;
default = "7d";
example = "2weeks";
description = ''
The retention period of auto GC roots.
'';
};
removeRoot = lib.mkOption {
type = with lib.types; bool;
default = false;
description = ''
Whether to pass the `--remove-root` option to angrr.
'';
};
ownedOnly = lib.mkOption {
type = with lib.types; bool;
default = false;
description = ''
Control the `--remove-root=<true|false>` option of angrr.
'';
apply = b: if b then "true" else "false";
};
extraArgs = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = ''
Extra command-line arguments pass to angrr.
'';
};
};
};
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
assertions = [
{
assertion = cfg.enableNixGcIntegration -> config.nix.gc.automatic;
message = "angrr nix-gc.service integration requires `nix.gc.automatic = true`";
}
];
services.angrr.enableNixGcIntegration = lib.mkDefault config.nix.gc.automatic;
}
{
systemd.services.angrr = {
description = "Auto Nix GC Roots Retention";
script = ''
${cfg.package}/bin/angrr run \
--period "${cfg.period}" \
${lib.optionalString cfg.removeRoot "--remove-root"} \
--owned-only="${cfg.ownedOnly}" \
--no-prompt ${lib.escapeShellArgs cfg.extraArgs}
'';
serviceConfig = {
Type = "oneshot";
};
};
}
(lib.mkIf cfg.timer.enable {
systemd.timers.angrr = {
timerConfig = {
OnCalendar = cfg.timer.dates;
};
wantedBy = [ "timers.target" ];
};
})
(lib.mkIf cfg.enableNixGcIntegration {
systemd.services.angrr = {
wantedBy = [ "nix-gc.service" ];
before = [ "nix-gc.service" ];
};
})
]
);
}