-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Flake inputs to accept boolean and integer attributes #4435
Conversation
I believe that this makes it possible to do things like Git inputs with submodules, but it also likely applies to other input types from libfetchers.
src/libexpr/flake/flake.cc
Outdated
throw TypeError("flake input attribute '%s' is %s while a string is expected", | ||
} else if (attr.value->type() == nBool) { | ||
attrs.emplace(attr.name, Explicit<bool>{ attr.value->boolean }); | ||
} else if (attr.value->type() == nInt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably go for a switch
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize it was an enum! Yes, switch
works much better here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit that switches this to a switch.
Do you know how one would make sure that nix fetches submodules for |
@knedlsepp unfortunately, I'm not sure. This change affects only the |
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
What you say makes sense, but when you consider how it's actually used, it's very inconvenient. A flake will either always want its submodules initialized, or never want to. A flake that has submodules will not work if you don't enable them, so there is no point in allowing a user to not fetch the submodules for a flake (if they are required to build it). Since whether submodules should be fetched depends on the flake, I propose that the flake set for itself whether its submodules should be fetched. You could also just unconditionally fetch them for flakes, since I can't see any scenario where you wouldn't want them. It's not foreign repositories being fetched for nixpkgs; they're flakes fit for nix. If the owner has added a submodule, it's likely required for using the flake. Would a PR enabling fetching of submodules unconditionally for all flakes be accepted? |
I'm getting a very strange error when trying to use this. After successfully fetching the module and all submodules, nix gave an error that disallowed usage saying: submodule is not a Boolean when it fact it is. I was able to work around by manually removing the |
I am also getting submodule is not a Boolean. |
I am running into the same issue that @L-as nicely described, where my I would be interested in contributing to a flake-submodule-fetcher PR if such a thing would be accepted. |
`self` flake can't have submodules. see: NixOS/nix#5312 NixOS/nix#4435 for now, it seems cleaner to just work through `Cargo.toml`, with specified git revisions...
I'm also in the same situation as @mhuesch and @L-as. Ofc I could try converting the submodule to a flake input, but that creates different inconveniences for us. |
It would be inconvenient to do manually, but if Nix itself could gain the power of locking the submodules as flake inputs so that Nix can handle the fetching of them lazily, that might be the best solution in the long run. |
Looking through the code base for Nix, I found that it creates
fetchers::Input
from the attributes given to Flakes' input refs (see also lines 108 through 133 inflake.cc
):nix/src/libexpr/flake/flakeref.cc
Lines 191 to 198 in 920e6a6
The attributes accepted by the fetches can be strings, integers, or booleans. However, currently, the code in
flake.cc
rejects all attributes that are not strings. It does, however, forward all extra string arguments, no matter what they are, to thefetchers::Input
. This seems inconsistent, and prevents input types like Git from accepting certain arguments, includingsubmodules
.This PR expands the code in
flake.cc
to accept non-string arguments. Combined with this, I was able to make non-flake inputs with recursive git modules work as follows:Note that
type = "git"
is already supported by Nix; this PR allows thesubmodules = true
argument to be passed in alongsidetype
. I believe this would close #4357 (and its duplicate, #4423).So far, the only non-integer attributes are
submodules
(bool),revCount
(int), andlastModified
(int). While the latter two are not particularly useful, I think the benefits for git submodules and consistency make this a worthwhile change.