From 5df4625ced1733f3643b4b86c07e43ed1774c0db Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 21 Apr 2026 19:32:47 +0800 Subject: [PATCH] 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). --- pkgs/by-name/sw/sway/package.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/by-name/sw/sway/package.nix b/pkgs/by-name/sw/sway/package.nix index 747c838efe03..a4494d9483cb 100644 --- a/pkgs/by-name/sw/sway/package.nix +++ b/pkgs/by-name/sw/sway/package.nix @@ -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