# Nixpkgs.desktop

**URL:** https://discourse.nixos.org/t/nixpkgs-desktop/39781
**Category:** Help
**Created:** [February 14, 2024, 4:29pm UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781 "2024-02-14T16:29:22Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kiara](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kiara/32/37249_2.png) [@kiara](https://discourse.nixos.org/u/kiara)
#### Post date: [February 14, 2024, 4:29pm UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/1 "2024-02-14T16:29:22Z")

</div>

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 :))

---

<div class="post-metadata">

### Author: ![fricklerhandwerk](https://discourse.nixos.org/user_avatar/discourse.nixos.org/fricklerhandwerk/32/2029_2.png) [@fricklerhandwerk](https://discourse.nixos.org/u/fricklerhandwerk)
#### Post date: [February 14, 2024, 4:40pm UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/2 "2024-02-14T16:40:26Z")

</div>

Actually that could be scary simple, and exactly as you describe. We could leverage (or extend) the [search.nixos.org](http://search.nixos.org) 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.

---

<div class="post-metadata">

### Author: ![TLATER](https://discourse.nixos.org/user_avatar/discourse.nixos.org/tlater/32/4257_2.png) [@TLATER](https://discourse.nixos.org/u/TLATER)
#### Post date: [February 14, 2024, 8:38pm UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/3 "2024-02-14T20:38:34Z")

</div>

> [@fricklerhandwerk](#):
>
> Actually that could be scary simple, and exactly as you describe. We could leverage (or extend) the [search.nixos.org](http://search.nixos.org) 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`.

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](https://snowflakeos.org/) has the [nix software center](https://github.com/snowfallorg/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.

---

<div class="post-metadata">

### Author: ![kiara](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kiara/32/37249_2.png) [@kiara](https://discourse.nixos.org/u/kiara)
#### Post date: [February 15, 2024, 1:45am UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/4 "2024-02-15T01:45:49Z")

</div>

@TLATER i guess for cleanup one could also follow the [tmpfs approach](https://mt-caret.github.io/blog/posts/2020-06-29-optin-state.html).  
i have been checking out `nix-software-center`, i agree that one seems cool as well.

---

<div class="post-metadata">

### Author: ![bobvanderlinden](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bobvanderlinden/32/59_2.png) [@bobvanderlinden](https://discourse.nixos.org/u/bobvanderlinden)
#### Post date: [February 15, 2024, 7:41am UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/5 "2024-02-15T07:41:56Z")

</div>

Haha that’s a fun idea 😂 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 😕)), 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.

---

<div class="post-metadata">

### Author: ![carspider](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/c/9fc29f/32.png) [@carspider](https://discourse.nixos.org/u/carspider)
#### Post date: [February 15, 2024, 8:09am UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/6 "2024-02-15T08:09:41Z")

</div>

That sounds fun!

> **[GitHub - nix-community/nix-index-database: Weekly updated nix-index database...](https://github.com/nix-community/nix-index-database)**
>
> Weekly updated nix-index database \[maintainer=@Mic92\] - nix-community/nix-index-database

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:

```auto
#!/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"

```

---

<div class="post-metadata">

### Author: ![bobvanderlinden](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bobvanderlinden/32/59_2.png) [@bobvanderlinden](https://discourse.nixos.org/u/bobvanderlinden)
#### Post date: [February 16, 2024, 10:13pm UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/7 "2024-02-16T22:13:16Z")

</div>

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:

```auto
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.

Code: [https://github.com/bobvanderlinden/nixos-config/blob/3b2a868001188062781b952d47d7964b86f3b814/packages/lazy-desktop/default.nix](https://github.com/bobvanderlinden/nixos-config/blob/3b2a868001188062781b952d47d7964b86f3b814/packages/lazy-desktop/default.nix)

---

<div class="post-metadata">

### Author: ![kiara](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kiara/32/37249_2.png) [@kiara](https://discourse.nixos.org/u/kiara)
#### Post date: [February 17, 2024, 12:04am UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/8 "2024-02-17T00:04:40Z")

</div>

haha nice 😄, 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](https://github.com/nix-community/nix-index?tab=readme-ov-file#use-pre-generated-database)? 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. 😻

---

<div class="post-metadata">

### Author: ![bobvanderlinden](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bobvanderlinden/32/59_2.png) [@bobvanderlinden](https://discourse.nixos.org/u/bobvanderlinden)
#### Post date: [February 17, 2024, 2:31am UTC](https://discourse.nixos.org/t/nixpkgs-desktop/39781/9 "2024-02-17T02:31:00Z")

</div>

> [@kiara](#):
>
> had you figured out how to have your derivation use the [pre-generated db](https://github.com/nix-community/nix-index?tab=readme-ov-file#use-pre-generated-database)?

Yes, the derivation already uses the pre generated db 👍

> <https://github.com/bobvanderlinden/nixos-config/blob/3b2a868001188062781b952d47d7964b86f3b814/packages/lazy-desktop/default.nix#L8>
