Skip to content

Instantly share code, notes, and snippets.

@xnumad
Last active June 28, 2025 11:43
Show Gist options
  • Save xnumad/6613efb71da04cf36c4ad0ba14ea58df to your computer and use it in GitHub Desktop.
Save xnumad/6613efb71da04cf36c4ad0ba14ea58df to your computer and use it in GitHub Desktop.
Adapted for NixOS. Fork of https://git.sr.ht/~vilhalmer/coredump-notify/tree/f48c647a200bc36bd34bfd8ebda7745ba71a5161/item/coredump-notify (user notification on coredump (application crash))
#!/usr/bin/env -S sh
me="$(/usr/bin/env basename "$0")"
# Arguments passed through are from the core pattern:
# %P %u %g %s %t %c %h %e
# pid uid group signal time rlimit hostname executable
#edit: my NixOS has
# %P %u %g %s %t %c %h %d %F
#passing that on to systemd-coredump via $@, so gotta use (at least) that
#sudo sysctl kernel.core_pattern="|/usr/coredump-notify %P %u %g %s %t %c %h %d %F %E"
/nix/store/1idf0vjlp6zaz38psn8541ad092xj8w6-systemd/lib/systemd/systemd-coredump "$@"
#test
echo "Starting gathering users" | /usr/bin/env systemd-cat --identifier="$me"
users="$(/usr/bin/env loginctl --no-legend list-users | /run/current-system/sw/bin/cut -f1 -d' ')"
echo "Done gathering users" | /usr/bin/env systemd-cat --identifier="$me"
echo "Notifying users of core dump: $users" | /usr/bin/env systemd-cat --identifier="$me"
# Attempt to tell someone!
for uid in $users; do
/usr/bin/env sudo --user="#$uid" \
/usr/bin/env DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus \
/usr/bin/env /run/current-system/sw/bin/notify-send \
--app-name="$me" \
--urgency=critical \
"Core dumped: $1" \
"$*" #"pid $1 uid $2 group $3 signal $4 time $5 rlimit $6 hostname $7 dump mode $8 pidfd number $9 ${10}"
echo "Notified user (uid) of core dump: $uid, return code $?" | /usr/bin/env systemd-cat --identifier="$me"
done
echo "Notified all users of core dump: $users" | /usr/bin/env systemd-cat --identifier="$me"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment