-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
lib/types: better error when trying to order submodules and optionTypes #180701
Conversation
The alternative is to silently ignore the
Often less is more. By allowing ignored metadata to seep into the module system implementation, we create a situation where it isn't clear which information is used, required or discarded, and where consumers of such information can pop up in unexpected places without having to consider the overall design of the module system, including bad interactions such as the one I just mentioned. We're finding out about it because it triggers an error, which is a better than allowing all sorts of ambiguities to build up over time. That said, I am interested in carrying |
Regarding the linked home manager PR, it'd be wise to contribute the dag type, or a similar type to |
It's not exactly silently ignored: you could still order the submodule definitions, but this order would only matter in unspecified ways (for example, if you ensure that one submodule definition A containing a list definition comes before another submodule definition B, then the lists will actually be merged in the reverse order On the other hand, I now think we should keep the |
The following contrived example: with lib; (evalModules { modules = [ { options.foo = mkOption { type = types.submodule { }; }; config.foo = mkBefore { }; } ]; }).config.foo currently fails with `error: anonymous function at nixpkgs/lib/types.nix:608:33 called with unexpected argument 'priority'`. This changes the error to `submodule definitions cannot be ordered`, and similarly for `optionType`.
d85fc3d
to
c31ae38
Compare
The following contrived example:
currently fails with
error: anonymous function at nixpkgs/lib/types.nix:608:33 called with unexpected argument 'priority'
.This is because
sortProperties
adds apriority
attribute tomkOrder
ed definitions for sorting purposes, but some consumers (here thesubmodule
merge
function) only expectvalue
andfile
attributes.While there is usually no reason to use ordering on submodule definitions, there is no reason it should fail either.
The other solution would be to discard the
priority
aftersortProperties
is done sorting, but I think it's more future-proof to allow definition values to come with arbitrary metadata.