-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix_gc_env.nix
47 lines (40 loc) · 1.16 KB
/
nix_gc_env.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
{ config, lib, pkgs, ... }:
# Remove older generations before running the garbage collector
# using [nix-env --delete-generations].
#
# This applies to every profiles (system, user profile, home-manager).
with lib;
let
conf = config.nix.gc;
clean_profiles = pkgs.writeShellScript "clean_profiles.sh" ''
PATH="${pkgs.nix}/bin:$PATH"
. ${./clean_profiles.sh} ${escapeShellArg conf.delete_generations}
'';
in {
options.nix.gc = {
delete_generations = mkOption {
type = types.str;
default = null;
example = "+5";
description = ''
Argument passed to [nix-env --delete-generations]. The default of '+5'
means to keep the 5 most recent generations of each profiles.
'';
};
};
config = mkIf (conf.delete_generations != null) {
assertions = [{
assertion = config.nix.gc.automatic;
message =
"'nix.gc.delete_generations' requires 'nix.gc.automatic' to be 'true'.";
}];
systemd.services.nix_gc_env = {
wantedBy = [ "nix-gc.service" ];
before = [ "nix-gc.service" ];
serviceConfig = {
Type = "oneshot";
ExecStart = clean_profiles;
};
};
};
}