Fix 'nix-instantiate --find-file' and add a test

Reported by @lheckemann.
This commit is contained in:
Eelco Dolstra 2022-10-12 21:51:36 +02:00
parent 511590976c
commit 12dd8d49c6
2 changed files with 7 additions and 1 deletions

View file

@ -169,7 +169,10 @@ static int main_nix_instantiate(int argc, char * * argv)
if (findFile) {
for (auto & i : files) {
auto p = state->findFile(i);
std::cout << p.readFile() << std::endl;
if (auto fn = p.getPhysicalPath())
std::cout << fn->abs() << std::endl;
else
throw Error("'%s' has no physical path", p);
}
return 0;
}

View file

@ -9,3 +9,6 @@ nix-instantiate --eval -E '<by-relative-path/simple.nix>' --restrict-eval
# Should ideally also test this, but theres no pure way to do it, so just trust me that it works
# nix-instantiate --eval -E '<nixpkgs>' -I nixpkgs=channel:nixos-unstable --restrict-eval
[[ $(nix-instantiate --find-file by-absolute-path/simple.nix) = $PWD/simple.nix ]]
[[ $(nix-instantiate --find-file by-relative-path/simple.nix) = $PWD/simple.nix ]]