forked from viperML/nh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
83 lines (73 loc) · 1.98 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
self: {
config,
lib,
pkgs,
...
}: {
options.nh = with lib; {
enable = mkOption {
type = types.bool;
default = true;
description = "Adds nh to your package list";
};
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
description = "Which NH package to use";
};
flake = mkOption {
type = with types; nullOr path;
default = null;
description = "The path that will be used for the `FLAKE` environment variable";
};
clean = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enables periodic cleaning";
};
dates = mkOption {
type = types.str;
default = "weekly";
description = "How often cleaning is triggered. Passed to systemd.time";
};
extraArgs = mkOption {
type = types.str;
default = "";
example = "--keep 5 --keep-since 3d";
description = "Flags passed to nh clean all";
};
};
};
config = lib.mkIf config.nh.enable {
assertions = [
{
assertion = config.nh.clean.enable -> config.nh.enable;
message = "nh.clean.enable requires nh.enable";
}
{
assertion = (config.nh.flake != null) -> !(lib.hasSuffix ".nix" config.nh.flake);
message = "nh.flake must be a directory";
}
];
environment = {
systemPackages = [config.nh.package];
variables = lib.optionalAttrs (config.nh.flake != null) {
FLAKE = config.nh.flake;
};
};
systemd = lib.mkIf config.nh.clean.enable {
services.nh-clean = {
description = "NH cleaner";
script = "exec ${config.nh.package}/bin/nh clean all ${config.nh.clean.extraArgs}";
startAt = config.nh.clean.dates;
path = [config.nix.package];
};
timers.nh-clean = {
timerConfig = {
Persistent = true;
};
};
};
};
}