I am looking for a shell command to display some information/metadata about a derivation. I can
nix search nixpkgs nvimpager and it will give me a very short info:
* legacyPackages.x86_64-linux.nvimpager (0.10.4)
Use neovim as pager
But I would like to have a shell command that can show me more info, like the homepage or the long description from the
meta attribute of the derivation.
Some other package managers have something like this, for example:
apt info /
yum info /
pacman -Si /
Currently I am doing
nix edit nixpkgs#nvimpager but that feels like an ugly hack and I have to close my editor afterwards and I can not list the info of several derivations at the same time. Is there any better command?
In the wiki I just found
nix-env -qa --description '.*nvimpager.*' and
nix-env -qa --xml --meta '.*nvimpager.*'. But the former is only the short description again and the latter is in xml. Additionally the searching is quite slow and I have to write a regex because I don’t understand how to specify a specific derivation directly. And it did not work on my NixOS system where I use flakes and the new nix command.
You can use
nix eval for this.
I define a simple fish helper function for this like so:
function meta -a drv attr
xdg-open (nix eval --raw self#$drv.meta.homepage)
nix eval self#$drv.meta.$attr
complete -c meta -n 'not __fish_is_first_arg' -xa '(complete -C "nix eval self#"(commandline -p | string split " ").meta. | sed "s/^self#.*\\.meta\.//")'
complete -c meta -n '__fish_is_first_arg' -xa '(complete -C "nix eval self#"(commandline -t) | sed "s/^self#//")'
Edit: seems I’d forgotten about
nix eval --raw whenever I wrote that function.
I don’t really see any details about how you function gets called, and I can infer that you’ve written a
fish function that’s in your shell rc file that’s part of an auto-completion of something not shown.
Regardless, I managed to guesswork my way to a straightforward command-line I’ve confirmed works:
nix eval --json 'nixpkgs#nvimpager.meta'