How to set the `xdg-mime` default?

I try to make xdg-open use evince for pdf files but not success.

I have try

$ xdg-mime default evince.desktop application/pdf

but it always ignored (without any error) and fall back to draw.desktop

$ xdg-mime query default application/pdf

Do I need to set some config in /etc/nixos/configuration.nix?

1 Like

you can run the same command with XDG_UTILS_DEBUG_LEVEL=2 to understand what’s going on


Short xdg-mime tutorial:

  • xdg-mime query filetype <file> to get the mimetype of <file>
  • see available .desktop files in /run/current-system/sw/share/applications (or others from $XDG_DATA_DIRS)
  • use xdg-mime default <programname>.desktop <mimetype> to change the default program, e.g. xdg-mime default firefox.desktop text/plain
  • Mime type for HTTP and HTTPS is x-scheme-handler/http and x-scheme-handler/https

The reason your command doesn’t work is because the evince .desktop file was renamed to org.gnome.Evince.desktop, so this command should work:

xdg-mime default org.gnome.Evince.desktop application/pdf

Here’s a home-manager solution: