-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Freeform modules #82743
Freeform modules #82743
Conversation
I now separated the orthogonal changes into #82751 |
4534c07
to
a7d6990
Compare
I don't think |
@roberth I don't think this would work without big changes, because currently it's not known upfront which values are unstructured and which aren't, and this could get complicated with nested |
@infinisil Quote for when the commit is lost:
One feature I suspect may be lost due to this change is the ability to check for the existence of option declarations before defining them, which I think will be important when modules move into flakes and need to adapt a bit at runtime to their now variable environment. |
@infinisil test available: #82802 |
@roberth I think I see what you mean, this might be possible, I'll give it a try soon. Implementation would be a bit like: Do a recursive |
9ee0bf8
to
80a9553
Compare
@roberth Done that! Commits need some cleanup, and other things are still left to do, but now the code is looking much nicer. I also did some very sweet cleanups related to this. Also I'm now not generating fake options anymore: Only Unfortunately without {
config._module.unstructuredType = attrsOf int;
options.a.b = mkOption {};
config.a.c = "foo";
} it now throws
and if you change it to { config.a = 0; } you get (as expected)
Instead of the previous (code now in https://github.com/Infinisil/nixpkgs/tree/partially-typed-v2-old)
I could get back the original error message if I add |
This can probably be improved quite a bit by rethrowing the error with an extra message. |
@roberth Hm it does work with |
dd1d716
to
ec7db16
Compare
4a787f2
to
8279d9b
Compare
Some more instances of this change finding mistakes/hacks:
I have opened #95932 to add release note entries for the feature and the backwards incompatibility this introduces. |
As introduced by NixOS#82743
There doesn't seem to be any way to define typing for an optional setting, I was looking to set |
Motivation for this change
This implement freeform modules, which are like a combination between
types.submodule
andtypes.attrsOf
: The options declared with the submodule are type-checked, while the others are combined using a freeform type. This has been a desired feature in multiple occasions now:settings
values very conventional.config
argument, as previously attempted in Typednixpkgs.config
married to NixOS #57123 and nixos/nixpkgs: add override/merging capabilities from the module system to thenixpkgs.config
option #80582, will now be possible in a sane way.How it looks like (updated for latest version) (evaluate with
nix-instantiate --eval --strict example.nix -A config
)Ping @roberth @Ma27 @rycee @Profpatsch @oxij
TODO