Systemd - how to properly terminate a graphical sesion?

I noticed something odd.

I have a bunch of user services that get properly started when I log into my session. (sway via regreet)

Before I log in systemctl --user status graphical-session.target and some other services that depend on it are dead.

Once I log in, they become active.

But No matter how I log out, they don’t terminate right. So if I re-login they are all not re-started.

I tried to just exit sway. Also via loginctl terminate-session but the graphical session target remains active. (Also sway-session.target)

If I stop graphical-session after I log out it all works again.

Can someone confirm the same behavior with other login managers? GDM perhaps?

Any idea what magic is missing?

My config: https://github.com/tbaumann/nix-conf/blob/2763e470e4b4bc6276598403fa5e353b6c84df79/nix/home-manager/desktop/sway.nix and https://github.com/tbaumann/nix-conf/blob/2763e470e4b4bc6276598403fa5e353b6c84df79/nix/common/desktops/sway.nix

2 Likes

regreet is set up rather minimalistic

  services.xserver = {
    enable = true;
    videoDrivers = [
      "amdgpu"
      "intel"
    ];
    desktopManager = {
      xterm.enable = false;
    };
  };
  programs.regreet = {
    enable = true;
    settings.background = {
      path = pkgs.nixos-artwork.wallpapers.stripes-logo.gnomeFilePath;
      fit = "Cover";
    };
  };

PS: If I enable wayland.windowManager.sway.systemd.xdgAutostart then those auto-start services all also go to failed when I re-login

› cat /home/tilli/.config/systemd/user/sway-session.target

[Unit]
After=graphical-session-pre.target
BindsTo=graphical-session.target
Description=sway compositor session
Documentation=man:systemd.special(7)
Wants=graphical-session-pre.target

BindsTo= is a directional dependency that makes sway-session.target start and stop with graphical-session-pre.target

But it only goes that direction. There is nothing making the graphical-session-pre.target go down with sway…

Plot thickens. Seems like stopping sway-session.target takes down graphical-session.target too. I was looking at the wrong place.

sway starts those targets. :monkey:

.config/sway/config

exec "/nix/store/m9bp68sxl8pi3gxhplfg8cgmld9c2lc0-dbus-1.14.10/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP XDG_SESSION_TYPE NIXOS_OZONE_WL; systemctl --user start sway-session.target"

I think logind is supposed to do all that stuff…

I think greetd needs to tell logind that the ssession is closed so that this target gets stopped.

I’m still not a 100% clear on how it’s done right.

GDM can do it. And does even somehow support multiple sessions.
Xsession does it right too.

Something regressed badly with plain wayland sessions.

There is a sway specific workaround and I’m tempted to use it. https://github.com/alebastr/sway-systemd/blob/73c8870f8290b50f9d9a3079560ff0c6f6747aed/src/session.sh#L124

But this issue will affect all wayland sessions not started via GDM/KDE not just sway.

This is how xsession does it

I feel your pain, the silence is deafening.

How did you end up going about this?

1 Like

I ignore it and think about one day maybe porting all the support structure of xsession into wayland-session.