Dunst crashes if run as service

New NixOS install, using sway (wayland). I installed dunst as a service via Home Manager:

services.dunst = {
  enable = true;

  settings = {
    # ... dunstrc items
  };
};

According to systemctl, the service was created and launched. However, dunst immediately crashes, as it tries to use X11:

Apr 27 14:48:23 kharik systemd[1294]: Starting Dunst notification daemon...
Apr 27 14:48:23 kharik dunst[927543]: WARNING: Cannot open X11 display.
Apr 27 14:48:23 kharik dunst[927543]: ERROR: [  get_x11_output:0065] Couldn't initialize X11 output. Aborting...
Apr 27 14:48:23 kharik systemd-coredump[927617]: [🡕] Process 927543 (.dunst-wrapped) of user 1000 dumped core.

Odd thing is, if I run dunst manually, it works as expected using wayland.

Does systemd (or dbus?) create a different environment where dunst can’t detect wayland? I looked in the dunst.service file, but didn’t see anything obvious:

[Service]
BusName=org.freedesktop.Notifications
Environment=
ExecStart=/nix/store/da8mrr63ngk67jpgmf4v57p8qsh4p58x-dunst-1.9.2/bin/dunst -config /home/nairou/.config/dunst/dunstrc
Type=dbus

[Unit]
After=graphical-session-pre.target
Description=Dunst notification daemon
PartOf=graphical-session.target

I think I figured this one out. Apparently programs launched by dbus don’t by default see the wayland session. I was able to fix that by running:

dbus-update-activation-environment WAYLAND_DISPLAY

After that, dunst (and other notification daemons I tried, like fnott and mako) started working as expected.

2 Likes

This solution did not work for me, still getting the errors.