Unverified Commit 5df4625c authored by Prasanna Loganathar's avatar Prasanna Loganathar
Browse files

sway: prefer systemd user bus over spawning a session dbus-daemon

The base wrapper falls back to `dbus-run-session sway` when
`DBUS_SESSION_BUS_ADDRESS` is unset. `dbus-run-session` unconditionally
spawns `dbus-daemon` (reference impl) as a fresh session bus, ignoring the
per-user bus already provided by `systemd --user` at
`$XDG_RUNTIME_DIR/bus`.

On NixOS this matters in two ways:

- Under `services.dbus.implementation = "broker"`, sway descendants bypass
  the broker user bus and land on a separate `dbus-daemon`, splitting the
  session between two buses.
- Even under the reference impl, a redundant second `dbus-daemon` gets
  spawned for the sway session.

Prefer the existing user bus at `$XDG_RUNTIME_DIR/bus` when available and
keep `dbus-run-session` only as the last-resort fallback for environments
without a `systemd --user` instance (containers, minimal CI).
parent 67650575
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -41,6 +41,11 @@ let
    if [ "$DBUS_SESSION_BUS_ADDRESS" ]; then
      export DBUS_SESSION_BUS_ADDRESS
      exec ${getExe sway} "$@"
    elif [ -n "$XDG_RUNTIME_DIR" ] && [ -S "$XDG_RUNTIME_DIR/bus" ]; then
      # Prefer the systemd --user bus (dbus-daemon or dbus-broker) over
      # spawning a redundant session bus via dbus-run-session.
      export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
      exec ${getExe sway} "$@"
    else
      exec ${optionalString dbusSupport "${dbus}/bin/dbus-run-session"} ${getExe sway} "$@"
    fi