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:
- evaludate nix to json
- build/realize all packages/paths in json string
- 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