Here’s what happens with most recent Nix 2.31.3:
> nix run github:NixOS/nix/2.31.3 -- build -L https://github.com/jakubgs/nix-submodule-bug-repro
error:
… while fetching the input 'https://github.com/jakubgs/nix-submodule-bug-repro'
error: Failed to open archive (Unrecognized archive format)
> nix run github:NixOS/nix/2.31.3 -- build -L github:jakubgs/nix-submodule-bug-repro
nix-submodule-bug-repro> cp: cannot stat '/nix/store/8z6yr8dcq3h4yf4rpsahvlyj8g6yd7iz-source/dummy-submodule/README.md': No such file or directory
error: builder for '/nix/store/66676knwjjkxd5jc40jj6p68j7fajcnv-nix-submodule-bug-repro.drv' failed with exit code 1;
last 1 log lines:
> cp: cannot stat '/nix/store/8z6yr8dcq3h4yf4rpsahvlyj8g6yd7iz-source/dummy-submodule/README.md': No such file or directory
For full logs, run:
nix log /nix/store/66676knwjjkxd5jc40jj6p68j7fajcnv-nix-submodule-bug-repro.drv
> nix run github:NixOS/nix/2.31.3 -- build -L 'git+https://github.com/jakubgs/nix-submodule-bug-repro'
> ls -l ./result/
total 1
-r--r--r-- 1 root root 41 Jan 1 1970 README.md
So it only works if you use the git+https:// format of the URL for some magical reason.
Also, it’s worth knowing contents of ~/.cache/nix can affect result of these commands so clearing that can help too.