When installing NixOS one may encounter a cryptic "Invalid cross-device link" bug. This is a minimal working example flake for reproducing this bug.
-
Boot a NixOS ISO image in a QEMU VM using BIOS boot and using a VirtIO virtual hard disk. Optionally, set a password using
passwd
for thenixos
user so that the process could be continued over SSH. -
Enter a Nix shell with Git and with the new Nix command syntax & Flakes enabled:
NIX_CONFIG='experimental-features = nix-command flakes' nix-shell -p git
-
Clone this flake as
git clone https://github.com/KornelJahn/nixos-crossdev-link-bug-mwe.git
-
Enter the repo directory as
cd nixos-crossdev-link-bug-mwe
-
First, try to enter a Nix shell featuring the default package as
nix shell .#
It should fail with the following ShellCheck error:
error: builder for '/nix/store/n7mkzq126vljwpvm5cy9kj9skzg8q47w-my-script.drv' failed with exit code 1; last 7 log lines: > > In /nix/store/d585g86virsxax1msalmx5z8wb0mvk81-my-script/bin/my-script line 7: > unused= > ^----^ SC2034 (warning): unused appears unused. Verify use (or export if used externally). > > For more information: > https://www.shellcheck.net/wiki/SC2034 -- unused appears unused. Verify use... For full logs, run 'nix log /nix/store/n7mkzq126vljwpvm5cy9kj9skzg8q47w-my-script.drv'.
This is what we expect: a meaningful error message.
-
Now try to install NixOS as follows (:warning: THE TARGET VIRTUAL HARD DISK IS WIPED! :warning:):
./install.bash
Toward the end of the process, it should also fail, but this time, with a different error message:
error: filesystem error: cannot rename: Invalid cross-device link [/mnt/nix/store/n7mkzq126vljwpvm5cy9kj9skzg8q47w-my-script.drv.chroot/nix/store/d585g86virsxax1msalmx5z8wb0mvk81-my-script] [/nix/store/d585g86virsxax1msalmx5z8wb0mvk81-my-script]
The latter error message is probably caused by the same kernel-related issue as described here. Note that correcting the error in the script inside flake.nix
(e.g. by commenting the line unused=
) results in a successful installation since ShellCheck won't complain anymore.