NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.44k stars 1.5k forks source link

`--store` does something _strange_ with relative paths #8102

Open K900 opened 1 year ago

K900 commented 1 year ago

Describe the bug

I honestly have no idea what is happening here.

Steps To Reproduce

  1. nix build --store ./foo nixpkgs#hello
  2. Observe everything working as intended
  3. nix build --store ./foo --expr 'derivation { name = "boop"; system = "x86_64-linux"; builder = builtins.toFile "beep" "boop"; }'
  4. error: creating directory '/foo': Permission denied

Expected behavior

The second command works as intended.

nix-env --version output

nix-env (Nix) 2.13.3

Additional context

...what even. Found while trying to debug a potentially unrelated issue on Matrix.

Priorities

Add :+1: to issues you find important.

thufschmitt commented 1 year ago

Mh, it looks like the “relativity” of the path gets interpreted relatively to / somewhere in the build loop. I'm surprised that we (apparently) don't resolve it right away to $PWD/foo and only deal with the absolute path afterwards

K900 commented 1 year ago

That's probably it, yeah. I'm unfortunately not familiar enough with the codebase to know where it happens or why though.

thufschmitt commented 1 year ago

Aaah, that's actually funnier than that: Nix does actually seem to take the absolute path before doing anything else with that store argument (here). So that bit works just fine (which is why the first example works). However, what Nix also does is that it spawns a separate process at the beginning of the build process (the build-hook which is used to potentially distribute the build to other machines). And that process apparently runs with its cwd set to /. Hence the issue.

Depending on the exact Nix version, your error message might include a … while reading the response from the build hook line which is a trace of that