Search code examples
nix

Asking Nix for metadata about the given package


I’m using Nix on macOS and on (non-NixOS) Linux. I’d like to give Nix a package or attribute name and have it show me

  1. the latest version number of that package that Nix knows about and
  2. the path to my local copy of the corresponding .nix file (or maybe a URL to that .nix file within the nixpkgs repository on GitHub).

I’m essentially looking for the Nix equivalent of Homebrew’s brew info packagename.

How can I get Nix to give me these pieces of information?


Solution

  • With nix-env on the CLI, I think the best we can currently and (relatively) conveniently do is JSON or XML:

    $ nix-env --query --available --attr nixpkgs.hello --meta --json
    
    # Or in terse form:
    $ nix-env -qaA nixpkgs.hello --json
    

    Neither output nor input are especially human-friendly, typical Nix usability…

    The path to the .nix file is listed as position, also in the REPL as in Robert's neat answer it's hello.meta.position. It is worth mentioning nix edit nixpkgs.hello, for opening the file.