Xdg-desktop-portal not working on Wayland while KDE is installed?

I managed to solve the problem after a while of tinkering, though forgot to post it (shame on me). So here it is, for future reference (and adapted to nixos-22.11):

  1. My configuration for xdg-portal now looks like this:
    xdg.portal = {
      enable = true;
      extraPortals = with pkgs; [
        xdg-desktop-portal-wlr
        xdg-desktop-portal-kde
        xdg-desktop-portal-gtk
      ];
      wlr = {
        enable = true;
        settings = { # uninteresting for this problem, for completeness only
          screencast = {
            output_name = "eDP-1";
            max_fps = 30;
            chooser_type = "simple";
            chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or";
          };
        };
      };
    };
    
  2. I guess this is the most crucial part which I messed up because I didn’t know better: You must announce the fact that a sway session is running to systemd manually. This is extensively documented in the sway wiki but well, if you don’t know where the problem is it’s hard to look for a solution in the right places. Put this in ~/.config/sway/config:
    # announce a running sway session to systemd
    exec systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP
    exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
    

Works like a charm now.

2 Likes