Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which package provides file "foo" #1751

Closed
jameshfisher opened this issue Feb 15, 2014 · 10 comments
Closed

Which package provides file "foo" #1751

jameshfisher opened this issue Feb 15, 2014 · 10 comments
Labels
0.kind: bug Something is broken

Comments

@jameshfisher
Copy link

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.

@jameshfisher
Copy link
Author

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.

@bjornfor
Copy link
Contributor

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.

@jameshfisher
Copy link
Author

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.

@jameshfisher
Copy link
Author

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

@peti
Copy link
Member

peti commented Feb 19, 2014

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.)

@shlevy
Copy link
Member

shlevy commented Apr 5, 2014

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

@shlevy shlevy added the bug label Apr 5, 2014
@vcunat
Copy link
Member

vcunat commented Apr 5, 2014

+1 for removal.

@attila-lendvai
Copy link
Contributor

note: it's rather frustrating to find this 6+ years old discussion as a nixos newbie, yet still spending long-long minutes failing to find out how to enable guiSupport for git...

@Fedcomp
Copy link

Fedcomp commented Feb 12, 2021

@attila-lendvai just solved it, use gitFull instead of git in /etc/nixos/configuration.nix environment.systemPackages = with pkgs; [ ... ]

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-find-which-package-holds-an-arbitrary-program-executable/11890/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

8 participants