1

when I do

nix-instantiate --verbose --eval --json --strict -E 'with (import <nixpkgs> {}); rec { x = "foo"; y = pkgs.hello; }'

it outputs

{"x":"foo","y":"/nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10"}

but directory /nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10 doesn't actually exist, because nix-instantiate doesn't realize/build derivations (more about this here What is the purpose of nix-instantiate? What is a store-derivation? )

$ ls -al /nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10
ls: cannot access '/nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10': No such file or directory

What command or combination of commands could:

  1. evaludate nix to json
  2. build/realize all packages/paths in json string
  3. return json

Tried and doesn't work

$ nix-store -r $(nix-instantiate --verbose --eval --json --strict -E 'with (import <nixpkgs> {}); rec { x = "foo"; y = pkgs.hello; }')
error: getting status of '/home/srghma/{"x":"foo","y":"/nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10"}': No such file or directory

Works but not what expected

$ nix-build -E 'with import <nixpkgs> {}; writeTextFile { name = "json"; text = builtins.toJSON (import ./test.tmuxp.nix); }'

these derivations will be built:
  /nix/store/0aid3qvrwpfs1n11cdj1c54rznay6vjx-json.drv
these paths will be fetched (0.04 MiB download, 0.20 MiB unpacked):
  /nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10
copying path '/nix/store/83vqfmpq19g0rkgjf0sa319x919p0vvg-hello-2.10' from 'https://cache.nixos.org'...
building '/nix/store/0aid3qvrwpfs1n11cdj1c54rznay6vjx-json.drv'...
/nix/store/5zs9jzx4l1zqv27hxcnw1prlj7df8ilx-json

FILED AN ISSUE https://github.com/NixOS/nix/issues/3018

srghma
  • 4,770
  • 2
  • 38
  • 54
  • Do you have a particular reason to ask for all three to be the same command? Why not use `nix-build` to do (1) and (2), and `nix show-derivation` to do (3)? – Charles Duffy Aug 08 '19 at 16:13
  • 1
    That is, run `nix show-derivation /nix/store/5zs9jzx4l1zqv27hxcnw1prlj7df8ilx-json`, (that argument coming from the result of your last `nix-build`), and you'll have your result. – Charles Duffy Aug 08 '19 at 16:14

0 Answers0