Get Nix Flake to include git submodule

I have a directory that looks like this:

| .git/
| ...

I want the submodule (which is not a flake) to be included in the flake source directory. What’s the best way to do this? I’ve tried the various permutations of url options from “nix flakes: add support for git submodules”.

Use submodules=1 in the query.

If this does not work, please share a minimal reproducible example that we can do some testing with.

1 Like

What’s the input url supposed to be for a submodule in the flake’s directory? Checking out from remote works (very inefficient), and this specific combination of:

url = "file:///[snip]/submodule?submodules=1";
type = "git";

works, but these failed:

inputs.submodule = {
    flake = false;
    url = "git+file:///[snip]/submodule?submodules=1";
}; # Fails w/ `error: opening file '[snip]/submodule/.git/config': Not a directory`

inputs.submodule = {
    flake = false;
    url = "git+path:submodule?submodules=1";
}; # Unsupported

inputs.submodule = {
    flake = false;
    url = "path:submodule?submodules=1";
    type = "git";
}; # Unsupported

I’d rather not have to specify the absolute path to the submodule.

You do not add the submodule itself as an input, you need to add the submodules=1 query parameter to the input that has the submodule.

If this is your “self”, you need to provide the query parameter on each CLI invocation.

nix build '.?submodules=1'

That worked! And is… very unintuitive.

EDIT: Is there any way to avoid manually specifying that every time?

1 Like

The only way I am aware of that would remove the necessity of specifying submodules=1 is to remove the submodule.

And I do not consider this unintuitive. You have to specify the argument to the input that has the submodules, if this input is self, then the only place where you can specify that is the CLI.

I’m definitely a nix novice, so you probably know more than me. But, I don’t think I’ve ever passed ?something to the nix CLI before and it’s undocumented AFAIK (excluding the github issue where people are similarly confused).

I agree that it is not convinient. Still, it is not unintuitive, as this is the only place where you specify selfs URL.

The CLI is also where you are able to change its schema.

Though my stance remains: the best way to deal with git submodules is to get rid of them…