Xdg-desktop-portal.service fails - unable to locate /usr/lib/xdg-desktop-portal

I’ve been using NixOS for a little less than 2 weeks and have really settled into it, but there’s a weird issue I’ve experienced. I was setting up XDG Desktop Portals to get screen recording/sharing to work but I stumbled upon this:
xdg-desktop-portal.service fails with xdg-desktop-portal.service: Unable to locate executable '/usr/lib/xdg-desktop-portal': No such file or directory and then xdg-desktop-portal.service: Failed at step EXEC spawning /usr/lib/xdg-desktop-portal: No such file or directory.
Initially I worked around this by creating the following activation script that linked the executable to /usr/lib:

system.activationScripts.usrlibxdg = ''
	mkdir -p /usr/lib
	chmod 0755 /usr/
	ln -sfn ${pkgs.xdg-desktop-portal}/libexec/xdg-desktop-portal /usr/lib/.xdg.tmp
	mv /usr/lib/.xdg.tmp /usr/lib/xdg-desktop-portal
'';

This worked. But I decided to revisit this issue yesterday when another issue popped up (also because there HAS to be something I’m doing wrong and using this activation script can’t be the only solution): OBS studio recordings using the pipewire screen capture which would work perfectly until then, started freezing on a single frame of the recording. Same with streams via Discord (Vesktop).
But well, all I’m asking about is that first issue. If resolving it doesn’t fix the other issue, I’ll probably make a separate topic for it.
One other thing, here’s my xdg.portal in my configuration.nix:

	xdg.portal = {
		enable = true;
		wlr.enable = true;
		xdgOpenUsePortal = true;
		extraPortals = with pkgs; [
			xdg-desktop-portal-wlr
			xdg-desktop-portal-gtk
		];

		wlr.settings = {
			screencast = {
				chooser_type = "simple";
				chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or";
			};
		};
	};

I’m on NixOS 26.11, nixpkgs unstable and nix 2.34.7 if that helps in any way.

What DE are you using? gnome, sway?

I forgot to specify that, sorry. I’m on sway.

The following is currently mostly working for me.

    xdg.portal = {
      enable = true;
      wlr = {
        enable = true;
        settings.screencast = {
          max_fps = 30;
          chooser_type = "dmenu";
          chooser_cmd = "${pkgs.bemenu}/bin/bemenu -l 12 --center --width-factor 0.4 -p \"Share window:\" -i -B 3";
          exec_before = "${pkgs.swaynotificationcenter}/bin/swaync-client -dnd-on";
          exec_after = "${pkgs.swaynotificationcenter}/bin/swaync-client -dnd-off";
        };
      };
    };
    services.pipewire = {
      enable = true;
      alsa.enable = true;
      pulse.enable = true;
    };
  • Mozilla: gUM Test Page
    ’Screen capture’ > select the mozilla browser ‘Window: xxxxxx - Mozilla Firefox’
    I can see my browser movements.

  • obs
    Sources > Screen Capture (PipeWire)
    It works for even when I select ‘Monitor: xxx’ or any ‘Window: xxx’

1 Like

Doesn’t change anything for me. I’m just not sure what to do or where to even ask. This shouldn’t be happening. I’m starting to think that something is wrong with my installation and the activation script might be the only “fix”.

I updated my system flake and everything. Still nothing. I really have no idea what else to do other than using that activation script.

Could you use systemctl status to find the .service file of this unit and its .overrides directory (if any) and share their paths and contents?

Looks to me like you’re somehow using a .service unit that isn’t written by NixOS.

The file is ~/.config/systemd/user/xdg-desktop-portal.service and here are the contents:

[Unit]
Description=Portal service
PartOf=graphical-session.target
# Requisite=graphical-session.target
After=graphical-session.target

[Service]
Type=dbus
BusName=org.freedesktop.portal.Desktop
ExecStart=/usr/lib/xdg-desktop-portal
Slice=session.slice

Cool, there’s the issue, but NixOS configuration.nix is the only way I’m doing anything related to xdg-desktop-portals. So if I edit it won’t this file just be regenerated wrong on nixos-rebuild switch?

It shouldn’t be. Wonder how it ended up there in the first place, the canonical location for that file is /etc/systemd/user/xdg-desktop-portal.service. All user units installed by NixOS should be in that directory; you probably have another copy there, but the user-installed file overrides it.

You must have either copied it from an old host (maybe stow, or perhaps you kept a home partition from a previous install?) or used home-manager to put it there. Or some weird autofix feature in a program you use? I don’t know, the fact that that file exists is bizzarre to me.

The NixOS-installed unit looks very different, too, it depends on dbus (arguably incorrectly, Type=dbus does do that automatically). No idea where your unit came from, looks like it’s from another distro.

Huh. I see. Yeah. Now I see exactly what the problem is. I forgot to delete .config/systemd from my backup dotfiles! It stowed and ruined everything. Thanks for the help.

1 Like