I set my store path with:
export NIX_STORE_DIR=/home/tobor/test/store
export NIX_STATE_DIR=/home/tobor/test/state
export NIX_LOG_DIR=/home/tobor/test/log
I then make a very simple derivation in test.nix
:
derivation {
system = "aarch64-linux";
name = "test";
builder = "/bin/sh";
args = [
"-c"
"echo hello > $out"
];
}
This works just fine with both nix-instantiate test.nix
and nix-build test.nix
.
I then delete the store and restart the process. This time I use IFD:
let
a = derivation {
system = "aarch64-linux";
name = "test";
builder = "/bin/sh";
args = [
"-c"
"echo hello > $out"
];
};
in
builtins.readFile a
Now, when I run nix-instantiate --eval test.nix
:
error:
… while calling the 'readFile' builtin
at /home/tobor/test/test.nix:12:1:
11| in
12| builtins.readFile a
| ^
13|
… while realising the context of path '/home/tobor/test/store/b9pmpsr4mc1lwf3havcl6g1901msyyr1-test'
error: path '/home/tobor/test/store/m53j1p0dq2hhdnxzykrs0zw2qdrbgicc-test.drv' is not valid
The drv file does not exist in the store.
I then go back to using the first file and run nix-instantiate test.nix
, which creates the drv file. I then try IFD again:
error:
… while calling the 'readFile' builtin
at /home/tobor/test/test.nix:12:1:
11| in
12| builtins.readFile a
| ^
13|
… while realising the context of path '/home/tobor/test/store/b9pmpsr4mc1lwf3havcl6g1901msyyr1-test'
error: cannot substitute path '/home/tobor/test/store/b9pmpsr4mc1lwf3havcl6g1901msyyr1-test' - no write access to the Nix store
If I run nix-build /home/tobor/test/store/m53j1p0dq2hhdnxzykrs0zw2qdrbgicc-test.drv
and try again, then it finally works:
"hello\n"
Does anyone have any clue why this could be happening and how I could fix it? I want to use nix in a derivation without recursive-nix
(I don’t want to enable it system-wide) to evaluate a file that does IFD.
A separate question, is there also by any chance a way to tell it to find the built derivation for the IFD from a specific path in the real /nix/store (or it can even just somehow get it from the real /nix/store if the inputs match)?
Thank you in advance for any help.