Graphical-session.target does not get activated by Sway

Since I updated my entire config flake yesterday and rebuilt my system, I’ve been having a problem where I can’t start xdg-desktop-portal.service because graphical-session.target does not get activated by Sway. I’m wondering if the issue could be caused by the fact that home-manager places it’s own graphical-session.target under ~/.config/systemd/user/. Since my last post I learned that the actual proper directory used by configuration.nix stuff is /etc/systemd/user/, which does also have it’s own graphical-session.target. But it gets overriden by the one placed by home-manager.
I don’t know how much of an issue that is. And I don’t even know if that is the issue.

I enable sway in configuration.nix via programs.sway and none of my configuration changed before or after the update to cause this failure. I start sway via SDDM.
My home-manager configuration also hasn’t changed before or after the update to cause this new file to be placed under that directory. (Except for an attempt at setting up sway via home-manager, which could be the fix but which I also quickly reverted because I simply would prefer if that was my last resort). So I believe something changed in home-manager itself to cause this change. But I have no idea.

NixOS version I’m on: 26.11.20260804.e72e4f2 (Zokor)
Nix version: 2.34.8

Not sure if this helps you.

I have in /etc/nixos/:

  programs = {
    uwsm = {
      enable = true;
      waylandCompositors = {
        sway = {
          binPath = "/run/current-system/sw/bin/sway";
          prettyName = "Sway";
        };
      };
    };
  };

in home-manager:

  wayland = {
    systemd.target = "sway-session.target";
    windowManager = {
      sway = {
        enable = true;
        systemd = {
          xdgAutostart = true;
        };
        xwayland = false;
      };
    };
  };

And I start sway from the commandline with uwsm start sway

Setting up Sway with home-manager does solve the issue, but then it introduces a lot of inconveniences.
First, home-manager writes a config file for me, even though I don’t want that. Luckily I have a backup of my old config. Second, I have to entirely stop using SDDM because Sway doesn’t show up in it anymore.
I tried setting up UWSM and also an SDDM-less setup but it seems that NixOS enables some other display manager (GDM, it looks like) which just straight up didn’t let me do anything and it constantly put me back in GDM even if I switched to a tty. And I had to revert to an older generation to do anything at all.

In general I would prefer not using home-manager for this.

Unless there’s a way to make Sway show up in SDDM and also make Home Manager stop writing a config file for me, I will use Sway system-wide via programs.sway.

I don’t know if this still works cause i found it in an older thread, but you could try something like

xdg.configFile."sway/config".enable = false;

Nevermind everything, the issue almost definitely isn’t with home-manager putting it’s own graphical-session.target in the directory. Then, is there any way I can remove xdg-desktop-portal.service’s dependency on graphical-session.target? I’ll look into that.

Update. I tried handwriting the xdg-desktop-portal services based on the existing ones (just without the dependency on graphical-session.target) as such:

systemd.user.services.xdg-desktop-portal = {
	enable = true;
	after = [];
	partOf = [];
	requisite = [];
	description = "Portal service";
	serviceConfig = {
		Type = "dbus";
		BusName = "org.freedesktop.portal.Desktop";
		ExecStart = "${pkgs.xdg-desktop-portal}/libexec/xdg-desktop-portal";
		Slice = "session.slice";
	};
};

systemd.user.services.xdg-desktop-portal-wlr = {
	enable = true;
	after = [];
	partOf = [];
	description = "Portal service (wlroots impl)";
	serviceConfig = {
		Type = "dbus";
		BusName = "org.freedesktop.impl.portal.desktop.wlr";
		ExecStart = "${pkgs.xdg-desktop-portal-wlr}/libexec/xdg-desktop-portal-wlr";
		Restart = "on-failure";
	};
};

systemd.user.services.xdg-desktop-portal-gtk = {
	enable = true;
	after = [];
	partOf = [];
	description = "Portal service (GTK impl)";
	serviceConfig = {
		Type = "dbus";
		BusName = "org.freedesktop.impl.portal.desktop.gtk";
		ExecStart = "${pkgs.xdg-desktop-portal-gtk}/libexec/xdg-desktop-portal-gtk";
	};
};

But instead of overwriting the existing ones they create overrides. But systemd still seems to read the thingies they’re supposed to override and says that there’s more than one ExecStart for the services.

Is sway-session.target running? What does systemctl --user status sway-session.target say?

1 Like

It’s not running.

Thanks. I made it start with Sway and now it all works.
I didn’t know you can just start it like that since you can’t start graphical-session.target I assumed that’s how it is with sway-session.target too.

1 Like

I think the right way to have it start with sway is to have include /etc/sway/config.d/* in your sway configuration, that’s what the default config in NixOS does.

1 Like