Help needed: environment.extraSetup and OS-wide default application launcher

I’m making a new post go get more attention.

I am trying to make a module that lalows specifying default application launchers. The format would be something like this-

	programs.defaults.defaults = { 
		"application/pdf" = [ pkgs.zathura "${pkgs.evince}/share/applications/org.gnome.Evince.desktop" ];
		"inode/directory" = [ "${pkgs.spaceFM}/share/applications/spacefm.desktop" pkgs.ranger pkgs.vifm ];
		"video/mp4" = pkgs.vlc;
	} ; 


The PR is here: [WIP] nixos/open-with: init by SRGOM · Pull Request #88025 · NixOS/nixpkgs · GitHub


There is some previous discussion on the need for this here- Configure how xdg-open opens html files? and also on the PR but to summarize, the problem is that there is no straightforward way to override the global defaults from user code. Most programs read their own choice of user space files and the management of those files isn’t so easy either. That said, most programs also do respect the global defaults.

The global defaults themselves are set in what seems like alphabetical order :slight_smile: so for my computer (and for yours) inkscape opens pdf, not org.gnome.Evince, code (visual studio code written in electron) opens directory, not vifm. The list can ovviously go on.

This code should allow root to specify sane default launchers.

help needed

I wrote the code assume environment.extraSetup would let me manipulate a mimeinfo.cache. However, when my module tries to read that file, it doesn’t find any file. I’m going to spend some more time on this this weekend but I am wondering if any experts here can (hopefully without spending time) tell me a way to proceed, basically ensuring in some way that my module runs after whichver module generates mimeinfo.cache or tell me which module does it.
EDIT: I think I found the module: nixos/modules/config/xdg/mime.nix

I will see how to go from here.

The solution we arrived at in Configure how xdg-open opens html files? was:

environment.etc."xdg/mimeapps.list" = {
  text = ''
    [Default Applications]

What is the advantage of adding this as an explicit nix feature? (honest question, I’m not trying to downplay your work, just trying to understand what it solves)

1 Like

I completely missed that!

My solution is marginally better in that you don’t have to worry about the actual .desktop file, just specify the package name.

But I do regret having spent time on this … :slight_smile:

1 Like