NixOS / nix

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

[flake] `nix flake init` failed with `~/.local/share/nix/root used` as a chroot store #6853

Open augu5te opened 1 year ago

augu5te commented 1 year ago

Describe the bug

When ~/.local/share/nix/root is used as a chroot store, template's source is not found despite it being present in the store.

[root@tmp:~]# nix --extra-experimental-features 'flakes nix-command' flake init
error: '/home/orichard/.local/share/nix/root/nix/store/kgr2zyykdhyck7wx14x2pmnx0bl49hgs-source/trivial' was not found in the Nix store
       If you've set 'defaultTemplate.path' to a string, try using a path instead.

[root@tmp:~]# ls /home/orichard/.local/share/nix/root/nix/store/kgr2zyykdhyck7wx14x2pmnx0bl49hgs-source/trivial
flake.nix

Steps To Reproduce

  1. Build nix-static to simplify test on machine without nix and nix store nix build "github:NixOS/nix/0b62dab6db3da5b20e62697b14aaaf80f1a2eea6#packages.x86_64-linux.nix-static"
    1. Copy `result/bin/nix on machine without nix
    2. On this machine execute ./nix --extra-experimental-features 'flakes nix-command' flake init

Expected behavior Copy flake.nix from trivial template in current directory.

Tested with: nix (Nix) 2.10.3

edolstra commented 1 year ago

This is fixed by #6530.

tuffnerdstuff commented 2 months ago

Same problem still present on nix (Nix) 2.22.1

chaserhkj commented 2 months ago

Confirm same problem still present on nix (Nix) 2.23.0pre20240510_87ab3c0

nix profile seems to have similar problem too:

[user@e36842965c86 ~]$ ./nix --extra-experimental-features 'flakes nix-command' profile install nixpkgs#hello
error: filesystem error: directory iterator cannot open directory: No such file or directory [/nix/store/bw9z0jxp5qcm7jfp4vr6ci9qynjyaaip-hello-2.12.1]