How to find which package holds an arbitrary program/executable?

When simply trying to run a program that is not installed (e.g., pdflatex) on the command line, Nix gives clues:

$ pdflatex
The program ‘pdflatex’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.texlive.combined.scheme-basic
  nix-env -iA nixos.texlive.combined.scheme-minimal
  nix-env -iA nixos.texlive.combined.scheme-small

but these are not the only packages that provide it,

$ nix-shell -p texlive.combined.scheme- # TAB TAB
texlive.combined.scheme-basic      texlive.combined.scheme-gust       texlive.combined.scheme-minimal
texlive.combined.scheme-context    texlive.combined.scheme-infraonly  texlive.combined.scheme-small
texlive.combined.scheme-full       texlive.combined.scheme-medium     texlive.combined.scheme-tetex

and sometimes there are factors internal to a certain package that render a given package unsuitable (I think).

search.nixos.org can’t do such queries (or did I miss something?), and the only other resources in this topic that I could find are more generic (and a solution to them woud be even more welcome):

nix-index is roughly correct

  • If you really just need to run the program and don’t otherwise care what package it is in, https://github.com/Shopify/comma uses nix-index to address this problem somewhat cleanly.
  • The IRC bot has a locate command you can use in-channel via ,locate pdflatex or ,locate bin pdflatex (you can also msg/query the bot the same, to keep it out of the channel). I believe the index is occasionally updated, so it might be stale if you are looking for something new.
2 Likes