git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/earlyoom: use the newly introduced systembus-notify option

Also some cleanups.

commit895090bf89cd1a9cd7bc3ea7edd3bd2a0ae9d88f authorPeter Hoeg <peter@hoeg.com> dateMon 12 Jul 2021, 15:36 (5 years ago) parent27e32bb
1 file changed+70−85
nixos/modules/services/system/earlyoom.nix+70−85
nixos/modules/services/system/earlyoom.nix+70−85
@@ -1,81 +1,73 @@
11{ config, lib, pkgs, ... }:
22
3−with lib;
4−
53let
6− ecfg = config.services.earlyoom;
4+ cfg = config.services.earlyoom;
5+
6+ inherit (lib)
7+ mkDefault mkEnableOption mkIf mkOption types
8+ mkRemovedOptionModule
9+ concatStringsSep optional;
10+
711in
812{
9− options = {
10− services.earlyoom = {
13+ options.services.earlyoom = {
14+ enable = mkEnableOption "Early out of memory killing";
1115
12− enable = mkOption {
13− type = types.bool;
14− default = false;
15− description = ''
16− Enable early out of memory killing.
17− '';
18− };
16+ freeMemThreshold = mkOption {
17+ type = types.ints.between 1 100;
18+ default = 10;
19+ description = ''
20+ Minimum of availabe memory (in percent).
21+ If the free memory falls below this threshold and the analog is true for
22+ <option>services.earlyoom.freeSwapThreshold</option>
23+ the killing begins.
24+ '';
25+ };
1926
20− freeMemThreshold = mkOption {
21− type = types.int;
22− default = 10;
23− description = ''
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>
27− the killing begins.
28− '';
29− };
27+ freeSwapThreshold = mkOption {
28+ type = types.ints.between 1 100;
29+ default = 10;
30+ description = ''
31+ Minimum of availabe swap space (in percent).
32+ If the available swap space falls below this threshold and the analog
33+ is true for <option>services.earlyoom.freeMemThreshold</option>
34+ the killing begins.
35+ '';
36+ };
3037
31− freeSwapThreshold = mkOption {
32− type = types.int;
33− default = 10;
34− description = ''
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>
38− the killing begins.
39− '';
40− };
38+ # TODO: remove or warn after 1.7 (https://github.com/rfjakob/earlyoom/commit/7ebc4554)
39+ ignoreOOMScoreAdjust = mkOption {
40+ type = types.bool;
41+ default = false;
42+ description = ''
43+ Ignore oom_score_adjust values of processes.
44+ '';
45+ };
4146
42− # TODO: remove or warn after 1.7 (https://github.com/rfjakob/earlyoom/commit/7ebc4554)
43− ignoreOOMScoreAdjust = mkOption {
44− type = types.bool;
45− default = false;
46− description = ''
47− Ignore oom_score_adjust values of processes.
48− '';
49− };
47+ enableDebugInfo = mkOption {
48+ type = types.bool;
49+ default = false;
50+ description = ''
51+ Enable debugging messages.
52+ '';
53+ };
5054
51− enableDebugInfo = mkOption {
52− type = types.bool;
53− default = false;
54− description = ''
55− Enable debugging messages.
56− '';
57− };
55+ enableNotifications = mkOption {
56+ type = types.bool;
57+ default = false;
58+ description = ''
59+ Send notifications about killed processes via the system d-bus.
5860
59− notificationsCommand = mkOption {
60− type = types.nullOr types.str;
61− default = null;
62− description = ''
63− This option is deprecated and ignored by earlyoom since 1.6.
64− Use <option>services.earlyoom.enableNotifications</option> instead.
65− '';
66− };
61+ WARNING: enabling this option (while convenient) should *not* be done on a
62+ machine where you do not trust the other users as it allows any other
63+ local user to DoS your session by spamming notifications.
6764
68− enableNotifications = mkOption {
69− type = types.bool;
70− default = false;
71− description = ''
72− Send notifications about killed processes via the system d-bus.
73− To actually see the notifications in your GUI session, you need to have
74− <literal>systembus-notify</literal> running as your user.
65+ To actually see the notifications in your GUI session, you need to have
66+ <literal>systembus-notify</literal> running as your user which this
67+ option handles.
7568
76− See <link xlink:href="https://github.com/rfjakob/earlyoom#notifications">README</link> for details.
77− '';
78− };
69+ See <link xlink:href="https://github.com/rfjakob/earlyoom#notifications">README</link> for details.
70+ '';
7971 };
8072 };
8173
@@ -83,37 +75,30 @@ in
8375 (mkRemovedOptionModule [ "services" "earlyoom" "useKernelOOMKiller" ] ''
8476 This option is deprecated and ignored by earlyoom since 1.2.
8577 '')
78+ (mkRemovedOptionModule [ "services" "earlyoom" "notificationsCommand" ] ''
79+ This option is deprecated and ignored by earlyoom since 1.6.
80+ '')
8681 ];
8782
88− config = mkIf ecfg.enable {
89− assertions = [
90− { assertion = ecfg.freeMemThreshold > 0 && ecfg.freeMemThreshold <= 100;
91− message = "Needs to be a positive percentage"; }
92− { assertion = ecfg.freeSwapThreshold > 0 && ecfg.freeSwapThreshold <= 100;
93− message = "Needs to be a positive percentage"; }
94− ];
95−
96− # TODO: reimplement this option as -N after 1.7 (https://github.com/rfjakob/earlyoom/commit/afe03606)
97− warnings = optional (ecfg.notificationsCommand != null)
98− "`services.earlyoom.notificationsCommand` is deprecated and ignored by earlyoom since 1.6.";
83+ config = mkIf cfg.enable {
84+ services.systembus-notify.enable = mkDefault cfg.enableNotifications;
9985
10086 systemd.services.earlyoom = {
10187 description = "Early OOM Daemon for Linux";
10288 wantedBy = [ "multi-user.target" ];
103− path = optional ecfg.enableNotifications pkgs.dbus;
89+ path = optional cfg.enableNotifications pkgs.dbus;
10490 serviceConfig = {
105− StandardOutput = "null";
10691 StandardError = "journal";
10792 ExecStart = concatStringsSep " " ([
10893 "${pkgs.earlyoom}/bin/earlyoom"
109− "-m ${toString ecfg.freeMemThreshold}"
110− "-s ${toString ecfg.freeSwapThreshold}"
111− ] ++ optional ecfg.ignoreOOMScoreAdjust "-i"
112− ++ optional ecfg.enableDebugInfo "-d"
113− ++ optional ecfg.enableNotifications "-n");
94+ "-m ${toString cfg.freeMemThreshold}"
95+ "-s ${toString cfg.freeSwapThreshold}"
96+ ]
97+ ++ optional cfg.ignoreOOMScoreAdjust "-i"
98+ ++ optional cfg.enableDebugInfo "-d"
99+ ++ optional cfg.enableNotifications "-n"
100+ );
114101 };
115102 };
116−
117− environment.systemPackages = optional ecfg.enableNotifications pkgs.systembus-notify;
118103 };
119104}