Xdg-desktop-portal not using the default browser

On my (mostly desktop environment free) laptop I am experimenting with xdg-desktop-portal, mainly to give sandboxed applications a way to open links.

So I enabled the portals using

  xdg.portal.enable = true;
  xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
  xdg.portal.config.common.default = [ "gtk" ];

and indeed, they are running, and

NIXOS_XDG_OPEN_USE_PORTAL=1 xdg-open http://localhost

opens a browser – but the wrong one, it opens chrominum, although I prefer firefox.

All the different ways of setting default appilcations that I could find are correctly set up

$ gio mime x-scheme-handler/http
Default application for ?x-scheme-handler/http?: firefox.desktop
Registered applications:
	firefox.desktop
	google-chrome.desktop
Recommended applications:
	firefox.desktop
	google-chrome.desktop
$ xdg-mime query default x-scheme-handler/http
firefox.desktop

and both xdg-open http://localhost and gio open http://test.de do the “right thing”. So why would xdg-desktop-portal (plausibly in this file) pick chrome instead – any hints?

(Using the gnome portal backend instead of gtk does not change things … not unexpected, given that url handling is done by xdg-desktop-portal itself.)

Stracing the xdg-desktop-portal process shows that it looks at both the firefox and the chrome .desktop files and then somehow decides to use chrome:

[pid 26268] newfstatat(AT_FDCWD, "/home/jojo/.local/share/mime//mime.cache", {st_mode=S_IFREG|0644, st_size=2028, ...}, 0) = 0
[pid 26268] newfstatat(AT_FDCWD, "/run/current-system/sw/share/mime//mime.cache", {st_mode=S_IFREG|0444, st_size=160132, ...}, 0) = 0
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/firefox.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/nix/var/nix/profiles/system/sw/share/applications/firefox.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/google-chrome.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/firefox.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/nix/var/nix/profiles/system/sw/share/applications/firefox.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/google-chrome.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/google-chrome.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26268] openat(AT_FDCWD, "/run/current-system/sw/share/applications/google-chrome.desktop", O_RDONLY|O_CLOEXEC) = 12
[pid 26470] execve("/nix/store/f3v1vx92y1cvhbhvm2yi28y9pqxfwlwp-glib-2.78.4/libexec/gio-launch-desktop", ["/nix/store/f3v1vx92y1cvhbhvm2yi28y9pqxfwlwp-glib-2.78.4/libexec/gio-launch-desktop", "/nix/store/rd5vhfsvqg8claz0qcr3d9d5sq12p22p-google-chrome-122.0.6261.69/bin/google-chrome-stable", "http://localhost"], 0x7fb5c80374e0 /* 40 vars */ <unfinished ...>

One interesting bit is that it only stats /home/jojo/.local/share/mime//mime.cache, but doesn’t open it. stracing gio open shows

[pid 27151] newfstatat(AT_FDCWD, "/home/jojo/.local/share/mime//mime.cache", {st_mode=S_IFREG|0644, st_size=2028, ...}, 0) = 0
[pid 27151] newfstatat(AT_FDCWD, "/home/jojo/.local/share/mime//mime.cache", {st_mode=S_IFREG|0644, st_size=2028, ...}, 0) = 0
[pid 27151] openat(AT_FDCWD, "/home/jojo/.local/share/mime//mime.cache", O_RDONLY) = 5

(but also looks at other files like /home/jojo/.config/mimeapps.list, so maybe the two implementations aren’t comparable.)

I’m having the exact same issue. Now I don’t know how you’re getting any usable output from straceing the xdg-desktop-portal process, but maybe you can show me the command you used.

gio open will use the browser I’ve defined as my x-scheme-handler/http, however xdg-open will not.

Judging from my bash history, I used

strace -e file -f -p 1528