13

I am using a Nix package manager on NixOS. Suppose I want to install a package that provides a file libgtk-x11-2.0.so.0. How do I find a package that provides this file, similar to other GNU/Linux distributions?

Currently I have to google the file and figure out which package it might belong and find the corresponding package on Nix repository, but I would like a more idiomatic method.

  • 1
    I got as far as "setup a ctags database..." nixos.org/wiki/… before giving up. – thrig Dec 29 '15 at 21:03
  • Some package managers (e.g. yum and dnf in RPMland) allow you to say "install file", they figure out the right package and install that one. – vonbrand Dec 29 '15 at 21:12
  • 2
    We only have this for executables ATM ($ command-not-found foo). Note that searching nix files (e.g. with ctags) won't help there. You do have to perform the build to find what it installs. – Vladimír Čunát Dec 30 '15 at 9:37
  • Why? Are other package managers really have such a function? More "idiomatic" method is to read INSTALL file of the package (for which you want to create the environment), namely the Requirements/Dependencies section for the packages you have to have pre-installed. Then look for the packages in nixpkgs. (In other words, package managers are about packages not files...) – Andrew Miloradovsky Mar 19 '16 at 0:48
  • 3
    @AndrewMiloradovsky, because sometimes you know the name of a command (or another filename) but not the name of the package that provides it. And yes, other package managers have such a feature, e.g. yum provides '*/bin/grep' or dnf provides '*/bin/grep or apt-file search 'fprintf.3.gz'. – maxschlepzig Oct 31 '16 at 22:18
8

nix-index is what you need.

Install and build the index:

nix-env -iA nixos.nix-index
nix-index

Locate libgtk-x11-2.0.so.0:

nix-locate -w libgtk-x11-2.0.so.0

Output:

(zed.out)                                             0 s /nix/store/bc4mngklj2j7hmm21jra4641x4pm9r8z-node-webkit-env/lib/libgtk-x11-2.0.so.0
(thrust.out)                                          0 s /nix/store/wzg0k4i2cy0qsm3hwxlywxxbga019hbq-env-thrust/lib/libgtk-x11-2.0.so.0
(nwjs_0_12.out)                                       0 s /nix/store/js6klvzjfi5q4djmwb0bqzfb4x0vzm6g-nwjs-env/lib/libgtk-x11-2.0.so.0
(node_webkit_0_11.out)                                0 s /nix/store/30vm6a7bmc56ckl575rqassw60ccxjpg-node-webkit-env/lib/libgtk-x11-2.0.so.0
(mumble_overlay.out)                                  0 s /nix/store/wayx023w1nslqg2z0c5v4n0b4jxn5n06-gtk+-2.24.31/lib/libgtk-x11-2.0.so.0
gnome2.gtk.out                                        0 s /nix/store/3iqchhncghm5s458lzy99c3prfymrnp2-gtk+-2.24.31/lib/libgtk-x11-2.0.so.0

The last line says that package gtk+-2.24.31 with attribute path gnome2.gtk contains this file.

2

Looking through the documentation it doesn't look like there is an easy way to do this.

With yum based distro you could do yum provides $file and in apt-get distro you could install apt-file and do apt-file $file but I cannot see an equivalent in nix-env -q.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.