Home-manager installed apps don't show up in Applications Launcher

I’m running home-manager on an Ubuntu 20.04 system, and overall its been a good experience. My biggest gripe thus far is that apps that I install via home-manager don’t show up in my Ubuntu Applications Launcher thingy. Eg. I have pkgs.vlc installed via my home-manager config, but in order to start VLC I have to first open a terminal, run $ vlc etc and then close the terminal again when I’m done. For me personally it’s much faster to be able to hit the Super key to show the apps launcher and then fuzzy search for the name of the app I’m looking for.

Is there any way to get home-manager-installed software to show up the Applications Launcher thingy?

1 Like

What does your XDG_DATA_DIRS look like? I had the same problem with dmenu - it looks for .desktop files in the application folder of the locations listed in XDG_DATA_DIRS, and my Nix profile was not in there. Assuming the Application Launcher uses the same strategy, adding XDG_DATA_DIRS=$HOME/.nix-profile/share:$XDG_DATA_DIRS to ~/.profile might do the trick.

If that works, home-manager recently added a targets.genericLinux.enable option that looks like it sets it up for you (among other things). It’s meant for home-manager installs on non-NixOS systems.

EDIT: Tried the config and it didn’t help - I guess sessionVariables doesn’t touch ~/.profile.

EDIT 2: In order for home-manager to set session variables you need to enable it for your shell, e.g. programs.bash.enable = true. Then ~/.profile will source hm-session-vars.sh which, provided that targets.genericLinux.enable = true, will add $HOME/.nix-profile/share to XDG_DATA_DIRS. Which will enable any launcher that uses the XDG Base Directory Spec to find programs installed with Nix.

I’m gonna stop editing now.

1 Like

Thanks for the pointers! This makes some sense. I add targets.genericLinux.enable to my home-manager config and after logging out and back in, I have some new XDG_DATA_DIRS now:

❯ echo $XDG_DATA_DIRS
/nix/var/nix/profiles/default/share:/home/skainswo/.nix-profile/share:/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

But unfortunately they’re still not showing up in the Ubuntu “Show Applications” launcher.

Based on Where is the location of application shortcuts in Gnome? - Ask Ubuntu it looks like it’s looking for .desktop files, but after poking around a bit in /home/skainswo/.nix-profile/share/ I’m not able to find any .desktop files, even for applications like VLC.

EDIT: They live in /home/skainswo/.nix-profile/share/applications. Still not sure why they’re not getting picked up.

I wonder if it has something to do with

❯ update-desktop-database
The databases in [/nix/var/nix/profiles/default/share/applications, /home/skainswo/.nix-profile/share/applications, /home/skainswo/.nix-profile/share/applications/applications, /usr/share/ubuntu/applications, /usr/local/share/applications, /usr/share/applications, /var/lib/snapd/desktop/applications] could not be updated.

It’s looking in all the right places, but the update is failing for some reason.

And here’s the verbose version:

❯ update-desktop-database -v
Search path is now: [/nix/var/nix/profiles/default/share/applications, /home/skainswo/.nix-profile/share/applications, /home/skainswo/.nix-profile/share/applications/applications, /usr/share/ubuntu/applications, /usr/local/share/applications, /usr/share/applications, /var/lib/snapd/desktop/applications]
Could not create cache file in "/nix/var/nix/profiles/default/share/applications": Error opening directory ?/nix/var/nix/profiles/default/share/applications?: No such file or directory
File "/home/skainswo/.nix-profile/share/applications/htop.desktop" lacks MimeType key
...
Could not create cache file in "/usr/share/applications": Permission denied
File "/var/lib/snapd/desktop/applications/gnome-system-monitor_gnome-system-monitor.desktop" lacks MimeType key
Could not create cache file in "/var/lib/snapd/desktop/applications": Permission denied
The databases in [/nix/var/nix/profiles/default/share/applications, /home/skainswo/.nix-profile/share/applications, /home/skainswo/.nix-profile/share/applications/applications, /usr/share/ubuntu/applications, /usr/local/share/applications, /usr/share/applications, /var/lib/snapd/desktop/applications] could not be updated.

and

❯ update-desktop-database -v /home/skainswo/.nix-profile/share/applications 
Search path is now: [/home/skainswo/.nix-profile/share/applications]
File "/home/skainswo/.nix-profile/share/applications/htop.desktop" lacks MimeType key
File "/home/skainswo/.nix-profile/share/applications/virt-manager.desktop" lacks MimeType key
Could not create cache file in "/home/skainswo/.nix-profile/share/applications": Permission denied
The databases in [/home/skainswo/.nix-profile/share/applications] could not be updated.

They live in /home/skainswo/.nix-profile/share/applications .

That is as expected. I think you’re there as far as home-manager is concerned.

I’m not running GNOME so I can’t test this myself, and I don’t know update-desktop-database, but the reason it cannot create a cache file is because your Nix profile is read-only (as it should be). To check if this is indeed what is missing to close the gap, you could make a (writable) copy of the Nix profile share/applications folder somewhere, add it to XDG_DATA_DIRS and run update-desktop-database…maybe?

Ah, yes if I copy all the files in /home/skainswo/.nix-profile/share/ into another directory, and then add that directory to my XDG_DATA_DIRS path and run update-desktop-database it works.

Since the nix store is read-only is there any way to get this to work?

Ah ok, so it looks like update-desktop-database just dumps a file $XDG_DATA_DIRS/applications/mimeinfo.cache that actually contains the database thing that GNOME/Unity looks for to pick up app launchers. So it seems as though the solution is simply to have home-manager run update-desktop-database in the targets.genericLinux.enable derivation.

I think the proper thing to do is to have Home Manager run update-desktop-database on activation. How does this play out?

EDIT: Sorry, I didn’t see your latest reply. Actually, I see that Home Manager is already doing this by default. So maybe file an issue on home-manager?

Ok, I created installed apps don’t show up in Ubuntu's "Show Applications" · Issue #1439 · nix-community/home-manager · GitHub :crossed_fingers:

2 Likes