nix flakes: add support for git submodules

Created on 4 Jan 2021  路  5Comments  路  Source: NixOS/nix

I recently learned about Nix Flakes, and I tried out making my blog a perfectly reproducible build. The trouble is, my blog uses a Git submodule to reference some code that I then present in my blog posts. This is fine and all, but I run into an issue - although I can fetch my blog source using Flakes' input attribute, it doesn't fetch submodules! This means that the code that I reference in my build process is simply not there.

This seems to be _almost_ possible; from a brief glance around Nix's source code, I discovered that a flake input gets turned into a "regular" input, which can point to a git repo and have a submodules attribute that, I think, would do what I want. It feels as though it was intended that this would work, but it doesn't.

It doesn't work because, for a reason unknown to me, a flake input's attributes must all be strings (except for flake). Here's the code that rejects non-string arguments:

https://github.com/NixOS/nix/blob/724b7f4fb660212a97ba6482208c299158720c5b/src/libexpr/flake/flake.cc#L123-L127

If non-string arguments were not rejected, a submodules field could be forwarded to the Git input scheme, which I suspect would make this work. Is there a reason that Flakes rejects all non-string "third party" attributes? It puts them into an attribute set anyway. Right now, I'm falling into a rather amusing loop:

duality of nix

If submodules is a string, it's rejected by the Git input scheme. But if it's a bool, it's rejected by the Flake code.

flakes improvement

Most helpful comment

I think there is still one piece missing: the flake itself is not being fetched using submodules.

All 5 comments

I think this is a duplicate of https://github.com/NixOS/nix/issues/4357

Apparently closed by #4435

I think there is still one piece missing: the flake itself is not being fetched using submodules.

Yes, perhaps it's worth closing this issue, and opening the original one (since this is a duplicate)?

Also, I am not sure how to go about requiring a flake itself to pull its own submodules. If a flake only has inputs and outputs, and an external definition determines the method for downloading it (a flake can be a local folder, too, or a tarball, can't it?), then where's the compromise?

A flake is assumed to be a git repo, so it would make sense for a universal "fetch submodules" option, perhaps as an output attribute. This would be orthogonal to the type = "git"; submodules = "true" attributes inside an input, since it wouldn't work for non-flake inputs.

What would be a good & concise way to present the design decision abstract primitives still in question to @edolstra / the maintainers? (possibly on another issue for proper framing)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewbauer picture matthewbauer  路  3Comments

daraul picture daraul  路  3Comments

Infinisil picture Infinisil  路  3Comments

LisannaAtHome picture LisannaAtHome  路  3Comments

ihsanturk picture ihsanturk  路  3Comments