Sway doesn't clean its session upon exit (Gnome subsequently fails to start)

Hi, I noticed an issue after upgrading to 26.05:

If I exit from Sway, and try to log back in with Gnome, Gnome refuses to start, dropping me back immediately to the login screen.

journalctl shows .gnome-session complaining about “A graphical session is already running!”. Indeed, if I run systemctl –user stop sway-session.target in a TTY, then I can login into Gnome just fine.

I checked on another old systems that I haven’t yet upgraded to 26.05, and I noticed that the stale session was there as well, when exiting from Sway, so I think what changed in 26.05 is Gnome being less lenient when a session is already running.

/etc/sway/config.d/nixos.conf contains a command that is meant to cleanup the session. I tested the swaymsg -t subscribe on its own, and I confirmed:

  • it works with a window event
  • it fails with a shutdown event with [ERROR] [common/ipc-client.c:86] Unable to receive IPC response and never successfully receives the event

I reported this issue on the sway bug tracker, but I’m writing this here to let Nixos users know, and maybe see if someone has ideas for better stopgap solutions than manually killing the session.

Btw, while I was looking into this issue, I also stumbled upon:

which suggests to stop the session with a separate target:

A special sway-session-shutdown.target can be used to stop the
graphical-session.target and the sway-session.target with all the contained
services.
systemctl start sway-session-shutdown.target will apply the Conflicts=
statements in the unit file and ensure that everything is exited, something that
systemctl stop sway-session.target is unable to guarantee

I wonder if it might make sense to adopt this (though it wouldn’t address this issue, since the swaymsg -t subscribe failure happens earlier). It seems that it’s already packaged in nixpkgs, though only for the assign-cgroups functionality.

You could try creating a sway session with uwsm instead of the sway module. uwsm generally does wayland session init correctly, I’ve finally had properly working graphical sessions since switching to it.