Why isn't there an official / built-in way to find what package provides a specific executable?

… and vice versa: what executables are provided by a given package? (E.g., coreutils)

Is there already an issue or a general discussion thread about this? There are plenty of examples of users having a hard time finding the right package that provides the needed program / executable:

There is probably more; couldn’t even find one of my own questions from a couple years back…

The common suggestion for these questions is to use nix-index and then nix-locate commands, but (1) these are not official, (2) still hard to find what the package names are, and (3) it doesn’t always work (or, most likely, I’m doing something wrong). (@bennofs Thank you for these! Without your tools, it would be a nigh hopeless task to find stuff.)

$ nix-locate bin/ffplay
jellyfin-ffmpeg.out         176,320 x /nix/store/46dz6jx9mk8fhc3brfka8iigjk66lssc-jellyfin-ffmpeg-5.1.2-2/bin/ffplay
arcanPackages.ffmpeg.out    176,064 x /nix/store/f7j7jmjqsig1xcff4ypcw8bnr0lj3ha2-ffmpeg-full-4.4.2/bin/ffplay
ffmpeg_5-full.out           176,320 x /nix/store/d12zpv3j48v7ykslf3l0q9q8jf59h225-ffmpeg-full-5.1.2/bin/ffplay

$ nix-locate bin/aplay 

Needed to include the bin/ prefix to make sure only executables are found. Tried aplay without bin/, but there were no aplay executables listed. (Maybe because it automatically excludes packages that won’t evaluate on a given architecture?)

My scenario that prompted this question:

I wanted to play a WAV file from the terminal, looked online, and remembered that I used aplay on Linux out of the box. I’m on Mac at the moment, so this wasn’t available.

Steps trying to find aplay:

  • First instinct was to look in NixOS package, but none the packages seemed relevant (obviously, they only had the string “aplay”)

  • Did a google search for nix nixos aplay, the most relevant (and seemingly only) result was the ALSA NixOS Wiki page; it didn’t help much either, but the name “ALSA” gave me some pointers.

  • Did a NixOS package search on alsa next, and alsa-lib & alsa-utils seemed generic enough so I gave them a try with nix-shell -p.

  • They didn’t evaluate as ALSA is not supported on Mac M1 (at least, that’s what the output said).

Went back to the askubuntu threa above, and ffmpeg's ffplay was my next candidate.


At least on nixOS there is a semi-built-in way.

$ command-not-found hello
The program 'hello' is not in your PATH. It is provided by several packages.
You can make it available in an ephemeral shell by typing one of the following:
  nix-shell -p hello
  nix-shell -p mbedtls

Creating the necessary index can only be done by hydra (or more generally: only by third party tools) as nix itself does not know what content a path would have.

So there needs to be some “party” that builds everything and creates a reverse mapping.

And this mapping will always only include those attributes that have been actually built by that party, so no unfree stuff and no “your packages”.


It also sounds like there are some flake-compatibility issues with that approach: `command-not-found` flake support by RyanGibb · Pull Request #187894 · NixOS/nixpkgs · GitHub. Some other issues with useful detail:


Why isn’t there an official / built-in way to find what package provides a specific executable?

command-not-found is the closest thing to an official solution, but as @abathur mentions this doesn’t work for flakes as we can’t add a programs.sqlite database.

I’ve started using nix-index.

(1) these are not official

I don’t think the fact that it’s not ‘official’ is a huge issue. I suppose as an ecosystem grows it’s hard to keep everything under one umbrella.

(2) still hard to find what the package names are

I’ve tied this into my shell, which when I use a command that isn’t installed prompts me with the package name.


$ audacity
The program 'audacity' is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixpkgs.audacity-gtk3.out
  nix-env -iA nixpkgs.audacity.out

Or run it once with:
  nix-shell -p audacity-gtk3.out --run ...
  nix-shell -p audacity.out --run ...

This seems to work well enough for me.

(3) it doesn’t always work

Perhaps a bug report in bennofs/nix-index would be in order?