2017-03-24 22:16:16 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
ecfg = config.services.earlyoom;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.earlyoom = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable early out of memory killing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
freeMemThreshold = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
|
|
|
description = ''
|
|
|
|
Minimum of availabe memory (in percent).
|
|
|
|
If the free memory falls below this threshold and the analog is true for
|
|
|
|
<option>services.earlyoom.freeSwapThreshold</option>
|
|
|
|
the killing begins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
freeSwapThreshold = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10;
|
|
|
|
description = ''
|
|
|
|
Minimum of availabe swap space (in percent).
|
|
|
|
If the available swap space falls below this threshold and the analog
|
|
|
|
is true for <option>services.earlyoom.freeMemThreshold</option>
|
|
|
|
the killing begins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-02-13 15:25:24 +00:00
|
|
|
# TODO: remove or warn after 1.7 (https://github.com/rfjakob/earlyoom/commit/7ebc4554)
|
2017-03-24 22:16:16 +00:00
|
|
|
ignoreOOMScoreAdjust = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Ignore oom_score_adjust values of processes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableDebugInfo = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable debugging messages.
|
|
|
|
'';
|
|
|
|
};
|
2019-01-05 12:26:12 +00:00
|
|
|
|
|
|
|
notificationsCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
2020-05-25 16:13:55 +01:00
|
|
|
This option is deprecated and ignored by earlyoom since 1.6.
|
|
|
|
Use <option>services.earlyoom.enableNotifications</option> instead.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableNotifications = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Send notifications about killed processes via the system d-bus.
|
|
|
|
To actually see the notifications in your GUI session, you need to have
|
|
|
|
<literal>systembus-notify</literal> running as your user.
|
2019-01-05 12:26:12 +00:00
|
|
|
|
|
|
|
See <link xlink:href="https://github.com/rfjakob/earlyoom#notifications">README</link> for details.
|
|
|
|
'';
|
|
|
|
};
|
2017-03-24 22:16:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-13 15:25:24 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "earlyoom" "useKernelOOMKiller" ] ''
|
|
|
|
This option is deprecated and ignored by earlyoom since 1.2.
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2017-03-24 22:16:16 +00:00
|
|
|
config = mkIf ecfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{ assertion = ecfg.freeMemThreshold > 0 && ecfg.freeMemThreshold <= 100;
|
|
|
|
message = "Needs to be a positive percentage"; }
|
|
|
|
{ assertion = ecfg.freeSwapThreshold > 0 && ecfg.freeSwapThreshold <= 100;
|
|
|
|
message = "Needs to be a positive percentage"; }
|
|
|
|
];
|
|
|
|
|
2022-02-13 15:25:24 +00:00
|
|
|
# TODO: reimplement this option as -N after 1.7 (https://github.com/rfjakob/earlyoom/commit/afe03606)
|
2020-05-25 16:13:55 +01:00
|
|
|
warnings = optional (ecfg.notificationsCommand != null)
|
|
|
|
"`services.earlyoom.notificationsCommand` is deprecated and ignored by earlyoom since 1.6.";
|
|
|
|
|
2017-03-24 22:16:16 +00:00
|
|
|
systemd.services.earlyoom = {
|
|
|
|
description = "Early OOM Daemon for Linux";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-05-25 16:13:55 +01:00
|
|
|
path = optional ecfg.enableNotifications pkgs.dbus;
|
2017-03-24 22:16:16 +00:00
|
|
|
serviceConfig = {
|
|
|
|
StandardOutput = "null";
|
2021-10-05 10:17:09 +01:00
|
|
|
StandardError = "journal";
|
2022-02-13 15:25:24 +00:00
|
|
|
ExecStart = concatStringsSep " " ([
|
|
|
|
"${pkgs.earlyoom}/bin/earlyoom"
|
|
|
|
"-m ${toString ecfg.freeMemThreshold}"
|
|
|
|
"-s ${toString ecfg.freeSwapThreshold}"
|
|
|
|
] ++ optional ecfg.ignoreOOMScoreAdjust "-i"
|
|
|
|
++ optional ecfg.enableDebugInfo "-d"
|
|
|
|
++ optional ecfg.enableNotifications "-n");
|
2017-03-24 22:16:16 +00:00
|
|
|
};
|
|
|
|
};
|
2020-05-25 16:13:55 +01:00
|
|
|
|
|
|
|
environment.systemPackages = optional ecfg.enableNotifications pkgs.systembus-notify;
|
2017-03-24 22:16:16 +00:00
|
|
|
};
|
|
|
|
}
|