i’m gradually wrapping my head around nix, and i’m starting to feel like nix-shell seems one of the cool parts about it, making it easy to invoke packages that might not even have been installed.

now, when used directly that mostly covers command-line usage, whereas people might do things without touching command-lines as well.

nix sym-linking applications to ~/.local/share/applications/ got me thinking - couldn’t one load up a bunch of .desktop files for applications (not necessarily installed) with Exec commands patched to invoke them thru nix-shell as well?

i guess that does raise different questions:

  • how / to where / at what kind of phase might one perform such sym-linking such as to not interfere with legitimate desktop entries not needing such nix-shell patching?
  • how might one even gather desktop entries for applications not installed? e.g. have a repo iterating over nixpkgs/nur packages/updates to nab each new desktop entry?
  • is this a terrible idea? (probably is, but who knows :))

Actually that could be scary simple, and exactly as you describe. We could leverage (or extend) the index, make a little desktop application wrapper to call its API to list metadata, and provide buttons that will essentially do nix-shell -p foo --run foo.

Actually “installing” desktop apps is sort of a different use case and relates to profile management. In my opinion we haven’t figured that one out properly yet. @bobvanderlinden and @ifreicht had good ideas though.


Cute, but that’d be a lot of packages in your start menu ;p

I kind of dislike the idea conceptually, there aren’t many GUI applications one-off enough for nix-shell. Most GUI applications will not clean up after themselves if you use nix-shell to install them anyway.

SnowflakeOS has the nix software center, which may be of interest for a UI for this kind of thing. In general, if you are interested in not touching the command line, check out that project.

1 Like

@TLATER i guess for cleanup one could also follow the tmpfs approach.
i have been checking out nix-software-center, i agree that one seems cool as well.

Haha that’s a fun idea :joy: maybe even useful!

You might be able to use nix-index/nix-locate to gather all existing .desktop files. Make a derivation that gathers all of these .desktop files and Exec= with nix run nixpkgs#package . If you have such a single derivation you could nix profile install --priority 999 ... (install it with low priority (yes high number is lower priority :confused:)), so that the generated desktop files are not conflicting/overriding with any actually installed packages.

Also maybe related, I remember there were also people who did something similar with the command_not_found functionality in the shell. Lookup package using nix-locate /bin/$command and nix run the package with command arguments. Any command will work without installing packages.

1 Like

That sounds fun!

can be used to find packages with .desktop files

fzf (dmenu/rofi/fuzzel/…)
can be used to select which desktop app to try

bubblewrap (or whatever)
can be used to help sandbox and keep it from polluting $HOME.

Here is a junky little script using flakes
to gist a “demo menu” with around 2500 entries:

#!/usr/bin/env -S nix shell nixpkgs#bash nixpkgs#nix nixpkgs#fzf nixpkgs#bubblewrap github:Mic92/nix-index-database#default --command bash

set -euo pipefail

APPS=$(nix-locate --minimal --regex '/share/applications/.*\.desktop$' \
	   | sed 's/\.out$//;/(.*)/d' \
	   | sort -u)
SELECTION=$(fzf --border \
		--reverse \
		--prompt='Demo Application: ' \
		<<< "$APPS")
# tighten the sandbox to what you need
# $HOME is tmpfs to the app so it puts its trash into a trash can
bwrap --dev-bind / / \
      --tmpfs "$HOME" \
      nix --experimental-features 'nix-command flakes' \
      run nixpkgs#"$SELECTION"

Based on what @carspider made, I created a derivation that holds /share/applications/*.desktop with a desktop file for each package. You can install it using:

nix profile install github:bobvanderlinden/nixos-config#lazy-desktop

After that rofi -show drun would show each entry. I’m guessing the gnome launcher looks better, but I haven’t been able to get the gnome launcher to function on my laptop.


1 Like

haha nice :smile:, too bad the lazy version uses generic icons, but this feels actually useful already!
@bobvanderlinden had you figured out how to have your derivation use the pre-generated db? i hadn’t quite managed to make it see it yet.
@carspider i love your fzf version as well, these really feel like peak nix already. :heart_eyes_cat:

Yes, the derivation already uses the pre generated db :+1: