From f4348768df564166762793aed43803675e251926 Mon Sep 17 00:00:00 2001 From: xenia Date: Wed, 5 Feb 2025 15:38:24 -0500 Subject: [PATCH] change the way the zfs patch works --- overlay.nix | 2 +- ...port-for-desktop-notifications-D-Bus.patch | 131 ++++++++++++++++++ ...port-for-libnotify-notify-send.2.2.7.patch | 116 ---------------- 3 files changed, 132 insertions(+), 117 deletions(-) create mode 100644 pkgs/zfs/0001-ZED-add-support-for-desktop-notifications-D-Bus.patch delete mode 100644 pkgs/zfs/0001-ZED-add-support-for-libnotify-notify-send.2.2.7.patch diff --git a/overlay.nix b/overlay.nix index 9e18e13..dc57326 100644 --- a/overlay.nix +++ b/overlay.nix @@ -50,6 +50,6 @@ final: prev: { nix-plugins = builtins.throw "nix-plugins is not supported. see pkgs.lix-plugins"; zfs_2_2 = prev.zfs_2_2.overrideAttrs { - patches = [ ./pkgs/zfs/0001-ZED-add-support-for-libnotify-notify-send.2.2.7.patch ]; + patches = [ ./pkgs/zfs/0001-ZED-add-support-for-desktop-notifications-D-Bus.patch ]; }; } diff --git a/pkgs/zfs/0001-ZED-add-support-for-desktop-notifications-D-Bus.patch b/pkgs/zfs/0001-ZED-add-support-for-desktop-notifications-D-Bus.patch new file mode 100644 index 0000000..40d6346 --- /dev/null +++ b/pkgs/zfs/0001-ZED-add-support-for-desktop-notifications-D-Bus.patch @@ -0,0 +1,131 @@ +From 4ec38cf16ad4cc5f7bb00b93c32cd8f1d313c14c Mon Sep 17 00:00:00 2001 +From: xenia +Date: Mon, 3 Feb 2025 21:36:29 -0500 +Subject: [PATCH] ZED: add support for desktop notifications (D-Bus) + +--- + cmd/zed/zed.d/zed-functions.sh | 85 ++++++++++++++++++++++++++++++++++ + cmd/zed/zed.d/zed.rc | 7 +++ + 2 files changed, 92 insertions(+) + +diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh +index 3a2519633..d47ef070b 100644 +--- a/cmd/zed/zed.d/zed-functions.sh ++++ b/cmd/zed/zed.d/zed-functions.sh +@@ -209,6 +209,10 @@ zed_notify() + [ "${rv}" -eq 0 ] && num_success=$((num_success + 1)) + [ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1)) + ++ zed_notify_dbus "${subject}" "${pathname}"; rv=$? ++ [ "${rv}" -eq 0 ] && num_success=$((num_success + 1)) ++ [ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1)) ++ + [ "${num_success}" -gt 0 ] && return 0 + [ "${num_failure}" -gt 0 ] && return 1 + return 2 +@@ -624,6 +628,87 @@ zed_notify_ntfy() + } + + ++# zed_notify_dbus (subject, pathname) ++# ++# Send a notification via D-Bus ... ++# The variable (ZED_USE_DBUS) defines whether to use D-Bus. ++# ++# Requires systemd (busctl) executables to be installed in the standard PATH. ++# ++# References ++# ... ++# ++# Arguments ++# subject: notification subject ++# pathname: pathname containing the notification message (OPTIONAL) ++# ++# Globals ++# ZED_USE_DBUS ++# ++# Return ++# 0: notification sent ++# 1: notification failed ++# 2: not configured ++# ++zed_notify_dbus() ++{ ++ local subject="$1" ++ local pathname="${2:-"/dev/null"}" ++ local msg_body ++ local msg_out ++ local msg_err ++ local exit_status=0 ++ local dir ++ local userid ++ ++ [ -n "${ZED_USE_DBUS}" ] || return 2 ++ ++ if [ ! -r "${pathname}" ]; then ++ zed_log_err "dbus cannot read \"${pathname}\"" ++ return 1 ++ fi ++ ++ zed_check_cmd "busctl" || return 1 ++ ++ # Read the message body in. ++ # ++ msg_body="$(cat "${pathname}")" ++ ++ if [ -z "${msg_body}" ] ++ then ++ msg_body=$subject ++ subject="" ++ fi ++ ++ # Send the notification to all users with a dbus session and check for ++ # errors. ++ # We use busctl(1) manually rather than eg notify-send(1) due to its ++ # ability to send D-Bus messages from root to a non-root user with the ++ # "--machine=@.host" flag. ++ for dir in /run/user/*; do ++ if [ -S "$dir/bus" ]; then ++ userid="$(basename "$dir")" ++ msg_out="$( \ ++ busctl --user --machine "$userid@.host" -- \ ++ call org.freedesktop.Notifications \ ++ /org/freedesktop/Notifications \ ++ org.freedesktop.Notifications Notify \ ++ "susssasa{sv}i" \ ++ "ZFS" 0 "drive-harddisk-symbolic" \ ++ "$subject" "$msg_body" ++ 0 2 urgency y 2 sender-pid x "$$" "-1" \ ++ 2>/dev/null ++ )"; rv=$? ++ ++ if [ "${rv}" -ne 0 ]; then ++ zed_log_err "busctl exit=${rv}" ++ exit_status=1 ++ fi ++ fi ++ done ++ return $exit_status ++} ++ + + # zed_rate_limit (tag, [interval]) + # +diff --git a/cmd/zed/zed.d/zed.rc b/cmd/zed/zed.d/zed.rc +index 859c6f9cb..567cd556a 100644 +--- a/cmd/zed/zed.d/zed.rc ++++ b/cmd/zed/zed.d/zed.rc +@@ -176,3 +176,10 @@ ZED_SYSLOG_SUBCLASS_EXCLUDE="history_event" + # + # https://ntfy.sh by default; uncomment to enable an alternative service url. + #ZED_NTFY_URL="https://ntfy.sh" ++ ++## ++# Whether to send desktop notifications via D-Bus ++# If defined, busctl(1) will be used to send desktop notifications via ++# the org.freedesktop.Notifications D-Bus interface ++# Disabled by default; uncomment to enable. ++#ZED_USE_DBUS=1 +-- +2.47.0 + diff --git a/pkgs/zfs/0001-ZED-add-support-for-libnotify-notify-send.2.2.7.patch b/pkgs/zfs/0001-ZED-add-support-for-libnotify-notify-send.2.2.7.patch deleted file mode 100644 index 8faffc9..0000000 --- a/pkgs/zfs/0001-ZED-add-support-for-libnotify-notify-send.2.2.7.patch +++ /dev/null @@ -1,116 +0,0 @@ -From 21f833bf906d07ea491d0938b716528be61ed9b6 Mon Sep 17 00:00:00 2001 -From: xenia -Date: Mon, 3 Feb 2025 21:36:29 -0500 -Subject: [PATCH] ZED: add support for libnotify (notify-send) - ---- - cmd/zed/zed.d/zed-functions.sh | 71 ++++++++++++++++++++++++++++++++++ - cmd/zed/zed.d/zed.rc | 6 +++ - 2 files changed, 77 insertions(+) - -diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh -index 3a2519633..111e477c5 100644 ---- a/cmd/zed/zed.d/zed-functions.sh -+++ b/cmd/zed/zed.d/zed-functions.sh -@@ -209,6 +209,10 @@ zed_notify() - [ "${rv}" -eq 0 ] && num_success=$((num_success + 1)) - [ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1)) - -+ zed_notify_libnotify "${subject}" "${pathname}"; rv=$? -+ [ "${rv}" -eq 0 ] && num_success=$((num_success + 1)) -+ [ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1)) -+ - [ "${num_success}" -gt 0 ] && return 0 - [ "${num_failure}" -gt 0 ] && return 1 - return 2 -@@ -624,6 +628,73 @@ zed_notify_ntfy() - } - - -+# zed_notify_libnotify (subject, pathname) -+# -+# Send a notification via libnotify . -+# The variable (ZED_USE_LIBNOTIFY) defines whether to use libnotify. -+# -+# Requires libnotify and sudo executables to be installed in the standard PATH. -+# -+# References -+# https://man.archlinux.org/man/notify-send.1.en -+# -+# Arguments -+# subject: notification subject -+# pathname: pathname containing the notification message (OPTIONAL) -+# -+# Globals -+# ZED_USE_LIBNOTIFY -+# -+# Return -+# 0: notification sent -+# 1: notification failed -+# 2: not configured -+# -+zed_notify_libnotify() -+{ -+ local subject="$1" -+ local pathname="${2:-"/dev/null"}" -+ local msg_body -+ local msg_out -+ local msg_err -+ local exit_status=0 -+ -+ [ -n "${ZED_USE_LIBNOTIFY}" ] || return 2 -+ -+ if [ ! -r "${pathname}" ]; then -+ zed_log_err "libnotify cannot read \"${pathname}\"" -+ return 1 -+ fi -+ -+ zed_check_cmd "notify-send" || return 1 -+ -+ # Read the message body in. -+ # -+ msg_body="$(cat "${pathname}")" -+ -+ if [ -z "${msg_body}" ] -+ then -+ msg_body=$subject -+ subject="" -+ fi -+ -+ # Send the notification to all users with a dbus session and check for errors. -+ for dir in /run/user/*; do -+ if [ -S "$dir/bus" ]; then -+ sudo -u "#$(basename $dir)" \ -+ -E DBUS_SESSION_BUS_ADDRESS=unix:path=$dir/bus \ -+ notify-send -a ZFS -u critical -i drive-harddisk-symbolic \ -+ "$subject" "$msg_body"; rv=$? -+ -+ if [ "${rv}" -ne 0 ]; then -+ zed_log_err "notify-send exit=${rv}" -+ exit_status=1 -+ fi -+ fi -+ done -+ return $exit_status -+} -+ - - # zed_rate_limit (tag, [interval]) - # -diff --git a/cmd/zed/zed.d/zed.rc b/cmd/zed/zed.d/zed.rc -index 859c6f9cb..60ab46b8a 100644 ---- a/cmd/zed/zed.d/zed.rc -+++ b/cmd/zed/zed.d/zed.rc -@@ -176,3 +176,9 @@ ZED_SYSLOG_SUBCLASS_EXCLUDE="history_event" - # - # https://ntfy.sh by default; uncomment to enable an alternative service url. - #ZED_NTFY_URL="https://ntfy.sh" -+ -+## -+# Whether to send notifications via libnotify -+# If defined, notify-send(1) will be used to send notifications -+# Disabled by default; uncomment to enable. -+#ZED_USE_LIBNOTIFY=1 --- -2.47.0 -