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

For a while now (I think since my upgrade to 22.05), starting certain programs on my machine while running sway takes unusally long (in case of Firefox almost a minute!). And sure enough, opening one of these applications from the terminal yields me this error message:

felix@entropy ~> pavucontrol
(pavucontrol:24729): Gdk-WARNING **: 11:48:44.051: Settings portal not found: Error calling StartServiceByName for org.freedesktop.portal.Desktop: Timeout was reached

This is odd, since I enabled xdg-portal and had no problems like these in the past.

systemctl status --user xdg-desktop-portal.service gives me:

× xdg-desktop-portal.service - Portal service
     Loaded: loaded (/etc/systemd/user/xdg-desktop-portal.service; static)
     Active: failed (Result: timeout) since Fri 2022-08-12 10:11:45 CEST; 1h 23min ago
    Process: 5118 ExecStart=/nix/store/4m2l35l351shhzg4qak7c13n20x71daf-xdg-desktop-portal-1.14.4/libexec/xdg-desktop-portal (code=killed, signal=TERM)
   Main PID: 5118 (code=killed, signal=TERM)
        CPU: 30ms

Aug 12 10:10:15 entropy systemd[1727]: Starting Portal service...
Aug 12 10:10:40 entropy .xdg-desktop-po[5118]: Failed to create settings proxy: Error calling StartServiceByName for org.freedesktop.impl.portal.desktop.kde: Timeout was rea>
Aug 12 10:10:40 entropy .xdg-desktop-po[5118]: No skeleton to export
Aug 12 10:11:05 entropy .xdg-desktop-po[5118]: Failed to create file chooser proxy: Error calling StartServiceByName for org.freedesktop.impl.portal.desktop.kde: Timeout was>
Aug 12 10:11:05 entropy .xdg-desktop-po[5118]: No skeleton to export
Aug 12 10:11:30 entropy .xdg-desktop-po[5118]: Failed to create app chooser proxy: Error calling StartServiceByName for org.freedesktop.impl.portal.desktop.kde: Timeout was >
Aug 12 10:11:30 entropy .xdg-desktop-po[5118]: No skeleton to export
Aug 12 10:11:45 entropy systemd[1727]: xdg-desktop-portal.service: start operation timed out. Terminating.
Aug 12 10:11:45 entropy systemd[1727]: xdg-desktop-portal.service: Failed with result 'timeout'.
Aug 12 10:11:45 entropy systemd[1727]: Failed to start Portal service.

I have Plasma enabled as a fallback x11 option in case I need to use some very petulant programs that don’t work well on Wayland. But the portal service seems to insist on having the KDE portal present as well (which should be added automatically, no?).

Is there any error in my config? How do I set up xdg-portal for both plasma and sway properly?

Thanks in advance for any hints or suggestions!

I had a similar issue occur on multiple computers and figured out that for some reason the portal implementations are not started properly, so the main xdg-desktop-portal process cannot export their functionality, which creates this delay.
One possible temporary workaround is to manually start the implementations (depending on whether you have installed it, either from ~/.nix-profile/libexec/xdg-desktop-portal-* in case of a user level package or their respective store entries if they are declared in your configuration.nix) and restart the main xdg-desktop-portal service afterwards, which will be happy now. (You can also try manually starting it in verbose mode and observe either the success or the 25 seconds of timeout that occurs while waiting for implementations to be spun up.)
Feel free to ask for clarification if it isn’t clear enough and I’ll try to explain what I mean in more details.

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

I think this bug is related to this one Failing to start xdg-desktop-portal-gnome after logging on Gnome · Issue #206630 · NixOS/nixpkgs · GitHub.

Fantastic hints @feliix42.

For those using home manager, the changes feliix42 mentioned can be enabled by doing the following:

  xdg.portal = {
    enable = true;
    wlr = {
      enable = true;
      settings = {
        screencast = {
          chooser_type = "simple";
          chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -ro";
        };
      };
    };
  };
  wayland.windowManager.sway = {
    enable = true;
    systemdIntegration = true;
  };