Setting `xdg-open` default apps

I’m trying to set the default apps in XMonad for xdg-open, I have GTK and KDE portals, but I when I try they with xdg-open command its throw me a window that says “Apps no available”. I set they like this in my configuration.nix:


xdg = {

 portal = {

   enable = true;
   xdgOpenUsePortal = true;

   extraPortals = with pkgs; [

      kdePackages.xdg-desktop-portal-kde
      xdg-desktop-portal-gtk 

   ];
 
 };

  mime.defaultApplications = {

     "x-scheme-handler/http" = "librewolf.desktop";
     "x-scheme-handler/https" = "librewolf.desktop";
     "x-scheme-handler/about" = "librewolf.desktop";
     "x-scheme-handler/unknow" = "librewolf.desktop"; 

     "image/*" = "pix.desktop";

  };

};

$XDG_DATA_DIR = /nix/store/1c8sm86wj45vwkb3ww2b870h9i9wna6r-patchelf-0.15.0/share:/nix/store/14l8y7y2h36z7jyiwmm878mdbd55fpp6-hicolor-icon-theme-0.18/share:/nix/store/m717h6dbc1wwfpj0n2916bgibiz3q78j-rofi-1.7.9.1/share:/nix/store/fx2957yk3h2js06jls40yaasi0pay7js-gsettings-desktop-schemas-48.0/share/gsettings-schemas/gsettings-desktop-schemas-48.0:/nix/store/xl3d5aczk5wxvhrlrzs4ayrhnsmn8ib3-gtk+3-3.24.49/share/gsettings-schemas/gtk+3-3.24.49:/nix/store/xahsqpk33ixb6wjl69h01v27xrv347yw-desktops/share:/home/nix/.nix-profile/share:/nix/profile/share:/home/nix/.local/state/nix/profile/share:/etc/profiles/per-user/nix/share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share

How do you start Xmonad? If I recall correctly I had to start my window manager with something like dbus-run-session river (I use river as WM) in order for xdg-open to work correctly.

So adding programs.river.enable = true; to your configuration.nix didn’t work?

xdg-open is a super hacky shell script: Making sure you're not a bot!

My suspicion is that most people only don’t notice because of the very liberally sprinkled hard-coded fallback browsers.

My suggestion is to permanently set BROWSER=librewolf.

If you wish to get the xdg mime handling to work, browse through that script and manually prod the xdg-mime scripts until you figure out where things are going wrong. I’ve only ever set mime associations under user directories, so I’m not sure how global settings propagate. All of this ultimately ends up in a “cache”, which you may or may not need to regenerate.

If on the other hand the issue is an xdg-open inside a flatpak, then things get more tricky.

1 Like

With this if I remember right, this autostart XMonad

services = { 

    xserver = {

     enable = true;
     autorun = true;
     xkb.layout = "latam";
    
     displayManager = {

       startx = {   
   
        enable = true;
        generateScript = true;

       };

     }; 

     windowManager.xmonad = {

      enable = true;
      enableContribAndExtras = true;

      extraPackages = haskellPackages: [

        haskellPackages.xmonad-contrib
        haskellPackages.xmonad-extras
 
      ];

    };

   };

export BROWSER="librewolf" doesn’t works, I got the same popup. I export $EDITOR as vim for yazi a file manager in the terminal that open files with xdg-open, vim works in yazi, you input enter and its open the text file. But vim doesn’t works with xdg-open command directly e.g. xdg-open file.txt just throw the “No applications available” window.

Where do you set BROWSER? In your .profile (which might not work), or elsewhere?

In .bashrc I set it

What happens if you run echo $BROWSER in a terminal while running XMonad?

Effectively librewolf as output in this case

What does “effectively” mean? What is the actual output of printenv BROWSER? (Don’t use echo for envvars)

Means is the same value I set in .bashrc. printenv also output librewolf.

Having both KDE and GTK makes KDE portal not running, I tried just GTK but same thing.

Hang on, wait, this should not be possible if you use xdg-open. It does not open windows by itself, it’s a non-graphical application.

This means you must be running into it using one of the other backends, which should not be happening on xmonad. You’ve probably played with your DE variable, or registered some kind of catchall association. What is the window that pops up?

xdg-open does not respect the $EDITOR variable for what it’s worth, so that’s not a useful test. It’s just clear that you end up with a non-generic branch.

xdg-mime query default image/*
pix.desktop

Also, which values must have XDG_DESKTOP_PORTAL, DESKTOP_SESSION and DE for GTK backend?

Well that popup is from the GTK portal, so you’re using the GTK portal.
Please share the values you set for those variables.

They was not set, printenv on they just give empty output. That’s why I’m asking the values for they.

Well, this is the code for that: Making sure you're not a bot!

You can try forcing it with XDG_CURRENT_DESKTOP=X-Generic

I set in /etc/nixos/configuration.nix XDG_CURRENT_DESKTOP=X-Generic in environment.variables section, but doesn’t wokrs, printenv prints its value. XDG_SESSION_TYPE=tty why I’m start XMonad with startx, thats matter?