Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake falsely assumes the store path. #4081

Open
LEXUGE opened this issue Sep 27, 2020 · 21 comments
Open

Flake falsely assumes the store path. #4081

LEXUGE opened this issue Sep 27, 2020 · 21 comments
Labels

Comments

@LEXUGE
Copy link

LEXUGE commented Sep 27, 2020

Describe the bug

Recently, I have been trying to install my full configuration in flake at once from NixOS LiveCD. To achieve that, I have to use the store on the target drive instead of that on tmpfs or OverlayFS.

However, even if I apply --option store /mnt, nix sometimes still uses /nix/store instead of /mnt/nix/store to check and eval.

Steps To Reproduce

  1. nix build "${MOUNTPOINT}/etc/nixos#name" --option store ${MOUNTPOINT}

Above would throw error like

path /nix/store/nvmqjsr9nh3vy7w2p6bqqmrjs17q5dfc-nix-3.0pre20200829_f156513/ is not valid

To get around it, I have to nix copy --to /mnt nixpkgs#nixFlakes --no-check-sigs (without --no-check-sigs it doesn't work on LiveCD, despite normal behavior on an ordinary NixOS).

  1. After nix copy, run above nix build again gives me complaints about absence of flake.nix (I guess this is because nix archived the /mnt/etc/nixos to /mnt/nix/store, but still checked presence of flake.nix in /nix/store).

  2. If I manually nix archive it, and run nix build again, it will throw error about impurity.

access to path `/mnt/nix/store/some_hash_here-source/flake.nix` is forbidden in restricted mode.

which I guess is caused by nix thinking /mnt/nix/store is not the store (anything other than /nix/store is not allowed then).

Expected behavior

Use /mnt/nix/store for all occasions.

nix-env --version output
nix-env (Nix) 3.0pre20200829_f156513
Additional context

Add any other context about the problem here.

@xaverdh
Copy link

xaverdh commented Oct 3, 2020

As a workaround you can use the --impure flag.
I think a simpler way to reproduce the core problem is trying to run something like

nix build --option store ./test-store nixpkgs#hello

which will fail with an InvalidPath error (due to nix itself).

@xaverdh
Copy link

xaverdh commented Oct 3, 2020

on a related note, the out link for local stores also appears to be wrong, likely for the same reason..

@LEXUGE
Copy link
Author

LEXUGE commented Oct 3, 2020

Yes, if you try to use the external store, the result link is still /nix/store.

@xaverdh
Copy link

xaverdh commented Oct 5, 2020

Suggestion: maybe rename this issue to something like "local stores don't work in pure evaluation mode" or "invalid path error with local store"?
At least to me it wasn't quite obvious from the title what this is about..

@LEXUGE
Copy link
Author

LEXUGE commented Oct 5, 2020

Well, but I do think this issue is related to other references to the store in the codebase because nix is getting wrong store paths in several occasions as I described above.

@xaverdh
Copy link

xaverdh commented Oct 15, 2020

Not sure if this issue is getting as much attention as it should.. @edolstra are you aware of this?
(sorry if I am too pushy)

@Ericson2314
Copy link
Member

I think the issue is the evaluation cache writing down paths. One thing I did in #3754 is is make it write down "store path descriptors" (hashes and references used to write the store path) instead of the store path itself. This means a store path can be computed from that from any store dir.

@shadowrylander
Copy link

shadowrylander commented Nov 9, 2020

Any updates on this? I got past the original "fetched file isn't in nix store" by using the latest master and setting the store to / (i.e. /nix/store), but now I'm stuck on chroot: failed to run command '/nix/var/nix/profiles/system/activate': No such file or directory and chroot: failed to run command '/run/current-system/bin/switch-to-configuration': No such file or directory; I'm assuming this is related, as the /mnt store hasn't been modified, so chrooting into /mnt wouldn't find the appropriate files? Or would this be more related to #4183?

Update: It turns out that the files themselves are there, but can't be run for some reason.

@xaverdh
Copy link

xaverdh commented Nov 12, 2020

If I am not mistaken 4badb69 fixes part of this. Unfortunately even with this commit the symlink will still not point to the correct path, so uses of these symlinks in nixos-rebuild / install might still cause trouble.
edit: actually the symlink always used to be like this and nixos-install deals with it appropriately by prepending the mount point.

@shadowrylander
Copy link

I can rebuild my spare system with the latest master and report back on whether that still occurs or not, if you wish?

@shadowrylander
Copy link

@xaverdh Well that didn't work, though I'm not sure I did it properly to begin with; how do I use the master branch of the Nix repo in my flake?

@shadowrylander
Copy link

Never mind; I figured out how to use the master branch, but now I'm getting stuck on 'flake.nix' file of flake [flake] escapes from [path].

@shadowrylander
Copy link

shadowrylander commented Nov 15, 2020

@xaverdh So I can use absolute paths everywhere?

Edit: never mind. Same problem of the file not being found.

@shadowrylander
Copy link

Any updates on this, if I may ask?

@shadowrylander
Copy link

May I ask if there are any updates on this again? I am currently attempting to initialize a new system with the flake, but am getting the same errors as above. Should I just create a smaller configuration without flakes to initialize the new system in the meantime?

@cole-h
Copy link
Member

cole-h commented Jan 1, 2021

FWIW, I also ran into the same issue. Thanks to a pointer on IRC from @colemickens, I was able to get a fresh, flakes-based install up and running.

nix build .#nixosConfigurations.hostname.config.system.build.toplevel && nixos-install --system ./result is essentially what I had to do.

@shadowrylander
Copy link

@cole-h Which is similar to the advice given here; however, I'm still getting errors where any repos referenced using flake paths are not being found, such as when using { inputs.<input>.flake = false; } in a flake.

@stale
Copy link

stale bot commented Jun 30, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Jun 30, 2021
@figsoda
Copy link
Member

figsoda commented Jun 30, 2021

still important to me

@stale stale bot removed the stale label Jun 30, 2021
@domenkozar
Copy link
Member

Detailed logs are in NixOS/nixpkgs#126141 (comment)

@bhankas
Copy link

bhankas commented Apr 15, 2022

I had to use solution from @cole-h 's comment today while setting up my Raspberry Pi. The error message is not very helpful, and the solution is not obvious. Fix does become semi-obvious in hindsight, but it is a UX gap, and might be worth fixing.

@stale stale bot added the stale label Oct 30, 2022
@edolstra edolstra removed their assignment Apr 26, 2024
@stale stale bot removed the stale label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants