Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
earlyoom: patch absolute dbus path and make nixos module up to date (…
Browse files Browse the repository at this point in the history
…#88443)

* earlyoom: patch absolute path of dbus-send

* nixos/earlyoom: replace `notificationsCommand` with `enableNotification`

* nixos/earlyoom: setup `systembus-notify` when `enableNotification`
  • Loading branch information
oxalica authored May 25, 2020
1 parent f1d9510 commit fe3e52c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
23 changes: 19 additions & 4 deletions nixos/modules/services/system/earlyoom.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ in
notificationsCommand = mkOption {
type = types.nullOr types.str;
default = null;
example = "sudo -u example_user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send";
description = ''
Command used to send notifications.
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.
See <link xlink:href="https://github.com/rfjakob/earlyoom#notifications">README</link> for details.
'';
Expand All @@ -87,9 +97,13 @@ in
message = "Both options in conjunction do not make sense"; }
];

warnings = optional (ecfg.notificationsCommand != null)
"`services.earlyoom.notificationsCommand` is deprecated and ignored by earlyoom since 1.6.";

systemd.services.earlyoom = {
description = "Early OOM Daemon for Linux";
wantedBy = [ "multi-user.target" ];
path = optional ecfg.enableNotifications pkgs.dbus;
serviceConfig = {
StandardOutput = "null";
StandardError = "syslog";
Expand All @@ -100,10 +114,11 @@ in
${optionalString ecfg.useKernelOOMKiller "-k"} \
${optionalString ecfg.ignoreOOMScoreAdjust "-i"} \
${optionalString ecfg.enableDebugInfo "-d"} \
${optionalString (ecfg.notificationsCommand != null)
"-N ${escapeShellArg ecfg.notificationsCommand}"}
${optionalString ecfg.enableNotifications "-n"}
'';
};
};

environment.systemPackages = optional ecfg.enableNotifications pkgs.systembus-notify;
};
}
2 changes: 2 additions & 0 deletions pkgs/os-specific/linux/earlyoom/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ stdenv.mkDerivation rec {

nativeBuildInputs = stdenv.lib.optionals withManpage [ pandoc installShellFiles ];

patches = [ ./fix-dbus-path.patch ];

makeFlags = [ "VERSION=${version}" ];

installPhase = ''
Expand Down
11 changes: 11 additions & 0 deletions pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/kill.c
+++ b/kill.c
@@ -55,7 +55,7 @@ static void notify(const char* summary, const char* body)
}
// Complete command line looks like this:
// dbus-send --system / net.nuetzlich.SystemNotifications.Notify 'string:summary text' 'string:and body text'
- execl("/usr/bin/dbus-send", "dbus-send", "--system", "/", "net.nuetzlich.SystemNotifications.Notify",
+ execlp("dbus-send", "dbus-send", "--system", "/", "net.nuetzlich.SystemNotifications.Notify",
summary2, body2, NULL);
warn("notify: exec failed: %s\n", strerror(errno));
exit(1);

0 comments on commit fe3e52c

Please sign in to comment.