How to find out which (not installed) package a file belongs to on NixOS

nixnixospackage-management

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.

Best Answer

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.

Related Question