tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
earlyoom service: init
Leon Isenberg
9 years ago
db30cff5
82adcd6c
+97
2 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
services
system
earlyoom.nix
+1
nixos/modules/module-list.nix
···
528
528
./services/system/cgmanager.nix
529
529
./services/system/cloud-init.nix
530
530
./services/system/dbus.nix
531
531
+
./services/system/earlyoom.nix
531
532
./services/system/kerberos.nix
532
533
./services/system/nscd.nix
533
534
./services/system/uptimed.nix
+96
nixos/modules/services/system/earlyoom.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
3
3
+
with lib;
4
4
+
5
5
+
let
6
6
+
ecfg = config.services.earlyoom;
7
7
+
in
8
8
+
{
9
9
+
options = {
10
10
+
services.earlyoom = {
11
11
+
12
12
+
enable = mkOption {
13
13
+
type = types.bool;
14
14
+
default = false;
15
15
+
description = ''
16
16
+
Enable early out of memory killing.
17
17
+
'';
18
18
+
};
19
19
+
20
20
+
freeMemThreshold = mkOption {
21
21
+
type = types.int;
22
22
+
default = 10;
23
23
+
description = ''
24
24
+
Minimum of availabe memory (in percent).
25
25
+
If the free memory falls below this threshold and the analog is true for
26
26
+
<option>services.earlyoom.freeSwapThreshold</option>
27
27
+
the killing begins.
28
28
+
'';
29
29
+
};
30
30
+
31
31
+
freeSwapThreshold = mkOption {
32
32
+
type = types.int;
33
33
+
default = 10;
34
34
+
description = ''
35
35
+
Minimum of availabe swap space (in percent).
36
36
+
If the available swap space falls below this threshold and the analog
37
37
+
is true for <option>services.earlyoom.freeMemThreshold</option>
38
38
+
the killing begins.
39
39
+
'';
40
40
+
};
41
41
+
42
42
+
useKernelOOMKiller= mkOption {
43
43
+
type = types.bool;
44
44
+
default = false;
45
45
+
description = ''
46
46
+
Use kernel OOM killer instead of own user-space implementation.
47
47
+
'';
48
48
+
};
49
49
+
50
50
+
ignoreOOMScoreAdjust = mkOption {
51
51
+
type = types.bool;
52
52
+
default = false;
53
53
+
description = ''
54
54
+
Ignore oom_score_adjust values of processes.
55
55
+
User-space implementation only.
56
56
+
'';
57
57
+
};
58
58
+
59
59
+
enableDebugInfo = mkOption {
60
60
+
type = types.bool;
61
61
+
default = false;
62
62
+
description = ''
63
63
+
Enable debugging messages.
64
64
+
'';
65
65
+
};
66
66
+
};
67
67
+
};
68
68
+
69
69
+
config = mkIf ecfg.enable {
70
70
+
assertions = [
71
71
+
{ assertion = ecfg.freeMemThreshold > 0 && ecfg.freeMemThreshold <= 100;
72
72
+
message = "Needs to be a positive percentage"; }
73
73
+
{ assertion = ecfg.freeSwapThreshold > 0 && ecfg.freeSwapThreshold <= 100;
74
74
+
message = "Needs to be a positive percentage"; }
75
75
+
{ assertion = !ecfg.useKernelOOMKiller || !ecfg.ignoreOOMScoreAdjust;
76
76
+
message = "Both options in conjunction do not make sense"; }
77
77
+
];
78
78
+
79
79
+
systemd.services.earlyoom = {
80
80
+
description = "Early OOM Daemon for Linux";
81
81
+
wantedBy = [ "multi-user.target" ];
82
82
+
serviceConfig = {
83
83
+
StandardOutput = "null";
84
84
+
StandardError = "syslog";
85
85
+
ExecStart = ''
86
86
+
${pkgs.earlyoom}/bin/earlyoom \
87
87
+
-m ${toString ecfg.freeMemThreshold} \
88
88
+
-s ${toString ecfg.freeSwapThreshold} \
89
89
+
${optionalString ecfg.useKernelOOMKiller "-k"} \
90
90
+
${optionalString ecfg.ignoreOOMScoreAdjust "-i"} \
91
91
+
${optionalString ecfg.enableDebugInfo "-d"}
92
92
+
'';
93
93
+
};
94
94
+
};
95
95
+
};
96
96
+
}