How do I find which package might contain a file?

This is a quick thing that I can’t seem to find an easy answer to:

I would like to figure out which package owns a particular file or binary. E.g. which one contains “xcb” (as in what is normally /usr/bin/xcb on Redhat or Ubuntu)

The normal package search interface (NixOS Search) just looks for a string match in the package name. I want to map a binary to it’s package, WITHOUT having to install anything.

This would really help as I’m implementing a build environment on top of Ubuntu with Nix, and I need to figure out which Nix package corresponds to which Debian one. Which is seriously non-trivial.

I did find ‘nix-index’, but it’s currently not working, as it can’t download the index it needs so far…

Any other good way?

Probably not the best way, but I do this (for anything I currently have installed):

$ readlink $(which vim)
/nix/store/fymb2prdsmc9268m3nr061zyxxqi8wkv-vim-9.1.0707/bin/vim

If you want to trawl all of nixpkgs, then nix-index is the way to go.

1 Like