Nixpkgs: Which package provides file "foo"

Created on 15 Feb 2014  Â·  7Comments  Â·  Source: NixOS/nixpkgs

I wanted to find out how to install gitk. I ran:

$ nix-env -qaP gitk
error: selector `gitk' matches no derivations

I then searched for it in the nixpkgs repository and found nothing.

I then realized that, actually, I already have it on my path:

$ gitk
gitk not supported, reinstall with config git = { guiSupport = true; } set

Fine, no problem. (Though I don't know where that error message comes from; I would have thought it would be in nixpkgs somewhere and so would have appeared in my github search.)

But I wouldn't have been able to figure this out had I not already had the git package installed.

Is there any general way to search for packages providing some file or program? E.g. do package definitions declare what programs they produce on compilation? Or can I search on Hydra for packages that produced such-and-such file?

Such a facility is provided by at least Ubuntu/Debian/yum, I believe.

bug

Most helpful comment

nix-env -qaP some-package only matches the exact name "some-package", not "_some-package_" (wildcard at each end). You may want to use nix-env -qaP | grep some-package instead.

In the case of "gitk" it isn't listed no matter how you search, because it is not a separate package but included in the "git" package.

Nix has a "command-not-found" functionality similar to Ubuntu. If you try to run a command and it isn't installed on your system, nix will suggest a package that provides that binary. This functionality is provided by Hydra which builds a sqlite database of files from packages' /bin and /sbin directories. When you update your channel sources you also get a copy of this database.

A more general "file index" built by Hydra would be really nice to have, similar to "apt-file" on Debian/Ubuntu. That way we could locate which package any file is located in, not just binaries.

For example, figuring out what package to install to provide "some-header.h" would be nice.

All 7 comments

I see that "GitHub search" is actually a lot more useless than I thought it was; it doesn't seem to do full-text search. git grep does the job and the git package is here: https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/version-management/git-and-tools/git/default.nix

Second issue; when I said "fine, no problem", I was wrong. I don't know what that error message is asking me to do. I can see that the git package is a function that accepts an argument guiSupport. But I don't call that function; something in Nix does. I suppose I could wrap the function, like

systemPackages = [
  ...
  (args: pkgs.git (args { guiSupport = true; }))
  ...
];

where args { guiSupport = true; } is a functional update like in Haskell. But I don't know how to do functional update in Nix.

nix-env -qaP some-package only matches the exact name "some-package", not "_some-package_" (wildcard at each end). You may want to use nix-env -qaP | grep some-package instead.

In the case of "gitk" it isn't listed no matter how you search, because it is not a separate package but included in the "git" package.

Nix has a "command-not-found" functionality similar to Ubuntu. If you try to run a command and it isn't installed on your system, nix will suggest a package that provides that binary. This functionality is provided by Hydra which builds a sqlite database of files from packages' /bin and /sbin directories. When you update your channel sources you also get a copy of this database.

A more general "file index" built by Hydra would be really nice to have, similar to "apt-file" on Debian/Ubuntu. That way we could locate which package any file is located in, not just binaries.

For example, figuring out what package to install to provide "some-header.h" would be nice.

Ah, I wasn't aware of this command-not-found functionality. It seems Nix has that as well as a convention that packages like git create dummy programs for things like gitk which they _could_ build but don't due to configuration options.

Notes to self on how this works: there's a literal program command-not-found, e.g.

$ command-not-found mysql
The program ‘mysql’ is currently not installed. You can install it by typing:
  nix-env -i mysql

I notice it only gets used in bash, not /bin/sh, so I assume there's some bash hook for when a program is not found on the PATH.

And yes, it would be very useful if command-not-found also worked for arbitrary files.

Src: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/bash/command-not-found.nix

Which uses a file at: /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite

It seems Nix has that as well as a convention that packages like git create dummy programs for things like gitk which they could build but don't due to configuration options.

I wouldn't call it a convention. I don't think any package other than git does this. (And, personally, I'm not sure I like the fact that git installs the pseudo scripts.)

IMO this is a bug in git. Any objections to removing that fake gitk script when the support is not installed?

+1 for removal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

spacekitteh picture spacekitteh  Â·  3Comments

vaibhavsagar picture vaibhavsagar  Â·  3Comments

langston-barrett picture langston-barrett  Â·  3Comments

copumpkin picture copumpkin  Â·  3Comments