bdesham
bdesham

Reputation: 16089

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?

Upvotes: 3

Views: 1236

Answers (2)

ches
ches

Reputation: 6632

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.

Upvotes: 3

Robert Hensing
Robert Hensing

Reputation: 7389

Perhaps there's a better way, like with nix-env, but I usually use nix repl for this purpose.

$ nix repl '<nixpkgs>'
Welcome to Nix version 2.2.2. Type :? for help.

Loading '<nixpkgs>'...
Added 10069 variables.

nix-repl> docker-c[TAB]     
docker-compose         docker-credential-gcr
nix-repl> docker-compose.version
"1.23.1"

Upvotes: 2

Related Questions