···
1
+
{ config, lib, pkgs, ... }:
6
+
ecfg = config.services.earlyoom;
10
+
services.earlyoom = {
16
+
Enable early out of memory killing.
20
+
freeMemThreshold = mkOption {
24
+
Minimum of availabe memory (in percent).
25
+
If the free memory falls below this threshold and the analog is true for
26
+
<option>services.earlyoom.freeSwapThreshold</option>
31
+
freeSwapThreshold = mkOption {
35
+
Minimum of availabe swap space (in percent).
36
+
If the available swap space falls below this threshold and the analog
37
+
is true for <option>services.earlyoom.freeMemThreshold</option>
42
+
useKernelOOMKiller= mkOption {
46
+
Use kernel OOM killer instead of own user-space implementation.
50
+
ignoreOOMScoreAdjust = mkOption {
54
+
Ignore oom_score_adjust values of processes.
55
+
User-space implementation only.
59
+
enableDebugInfo = mkOption {
63
+
Enable debugging messages.
69
+
config = mkIf ecfg.enable {
71
+
{ assertion = ecfg.freeMemThreshold > 0 && ecfg.freeMemThreshold <= 100;
72
+
message = "Needs to be a positive percentage"; }
73
+
{ assertion = ecfg.freeSwapThreshold > 0 && ecfg.freeSwapThreshold <= 100;
74
+
message = "Needs to be a positive percentage"; }
75
+
{ assertion = !ecfg.useKernelOOMKiller || !ecfg.ignoreOOMScoreAdjust;
76
+
message = "Both options in conjunction do not make sense"; }
79
+
systemd.services.earlyoom = {
80
+
description = "Early OOM Daemon for Linux";
81
+
wantedBy = [ "multi-user.target" ];
83
+
StandardOutput = "null";
84
+
StandardError = "syslog";
86
+
${pkgs.earlyoom}/bin/earlyoom \
87
+
-m ${toString ecfg.freeMemThreshold} \
88
+
-s ${toString ecfg.freeSwapThreshold} \
89
+
${optionalString ecfg.useKernelOOMKiller "-k"} \
90
+
${optionalString ecfg.ignoreOOMScoreAdjust "-i"} \
91
+
${optionalString ecfg.enableDebugInfo "-d"}