I’ve been relying on nix build ".?submodules=1" -L for a certain flake, but it no longer works. I’ve opened an issue: flake: broken .?submodules=1 · Issue #11859 · NixOS/nix · GitHub
FWIW the UX here has caused enough trouble that I’ve moved away from submodules and embraced subtrees instead.
For future reference, one approach since Nix 2.27.0 is to use the inputs.self.submodules flake attribute:
I am using Nix 2.31.2 and I am still confused about the following behavior.
There is a flake repository hosted on GitHub, aaa/bbb, which contains inputs.self.submodules = true;. However, running nix build github:aaa/bbb fails.
I then cloned the repository locally and ran nix run ., which also failed. Even after executing git submodule update --remote --init, the build still complains that the submodule directory cannot be found.
Later in this thread, I noticed the suggestion to use nix build '.?submodules=1', and with this command the build succeeds.
What confuses me is that after this successful build, running nix run . works and the program runs correctly. This makes me suspect that it might be reusing a cached derivation, but I am not sure. Even if I remove inputs.self.submodules = true; from flake.nix, nix run . still works.
Finally, when I try nix build github:aaa/bbb again, it still fails.
Is there an underlying issue or inconsistency here that explains this behavior?
I have seen the same with inputs.self.submodules which appears to just have no effect whatsoever.
People keep saying it works but I have never seen it work, you can see some of my investigation here:
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.
inputs.self.submodules = true; works after 2.27 nix.
github input scheme (the one that fetches from the archive endpoint) doesn’t do submodules (yet). @roberth filed your issue in `github` input scheme silently ignores submodules parameter · Issue #14982 · NixOS/nix · GitHub.
So does a submodule get removed from the view of nix’s view? How does including the submodule flag work under the hood (could you point me to a place to research this a bit further). Having submodule compatibility is pretty important, and I appreciate the guidance on learning more about this utility?
Adding the query parameter will tell nix to clone recursively.
If your repo has submodules, you have to specify it. IIRC, there was a point in time during '25 when submodule=1 became the default at least for local git repos, not sure about remotes.
There was also a time when submodule=1 only worked for git+… but was ignored for github and gitlab flakes.
Thank you @NobbZ ! If possible, could point me to the source code implementation where I can see the algorithm for the nixos-rebuild switch mechanism with the submodule query parameter?
nixos-rebuild is completely unrelated and all the flake-input resolving logic lives in nix’ implementation of fetchTree IIRC.
So you might want to dig GitHub - NixOS/nix: Nix, the purely functional package manager · GitHub for more details.
Thanks for the suggestions @NobbZ ! Other than browsing the source code, where would you recommend learning about nix internals (any books, video series, etc. that you found to be particularly insightful?)