Get nix store path for a flake locked input

Say I have this:

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = inputs: {
    ...
  };
}

In this case, nixpkgs points to some version of nixpkgs/nixos-unstable as per flake.lock.

I’d like to get the /nix/store path for that particular locked input. Is there a way to do this?

String interpolation. "${inputs.nixpkgs}" will resolve to the store path.

Thanks @NobbZ. Sorry, I was not clear - I wanted to get this from the command line somehow. I’m not sure how to reach the inputs of the flake since

$ nix eval --expr '"${inputs.nixpgs}"'
error: undefined variable 'inputs'
       at «string»:1:4:
            1| "${inputs.nixpgs}"
             |    ^
$ nix eval --expr '(builtins.getFlake "path://'$PWD'").inputs.nixpkgs.outPath' --impure
"/nix/store/i5zbq5by44gz4w1v0kwdcv2d8vacqhd1-source"

Use git+file:// instead of path:// if it’s a git repo. (getFlake is kind of broken in terms of autodetecting a git vs non-git repo, so you really want to provide the actual flake scheme explicitly.)

You probably also want to use --json if you’re going to manipulate the output of nix eval using a script.

1 Like