-
-
Notifications
You must be signed in to change notification settings - Fork 14.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 submodules to use custom lib
/evalModules
#98952
Conversation
The module system already uses the parent modules _type as a fallback, so we don't need to inject the file in a weird way With a future commit that allows passing custom lib versions, this will also allow usage of older nixpkgs versions that don't have aa61342 yet
This allows evaluating modules with older lib versions
Lgtm! |
I think this might be useful to us for our docs generation stuff @dasJ |
This invites a new type of complexity when troubleshooting module system issues. We'll have to consider the possibility that other versions of the module system are integrated into e.g. the options list. Not only consider it; clearly it will happen as evidenced by the fact that this is not a two-line diff. So unless there's a fundamental reason why passing Note that it's still possible to just invoke whichever |
Hmm I see what you mean. I think we can organize the problem like this:
My opinions:
So in conclusion: it's not ideal. |
However, 1.b and 2.b are actually already a problem, because setting Here's an idea though:
|
Thinking about this again, I had the idea of just using
So this won't work well |
It would be possible to implement the idea from #98952 (comment), which would result in a safe use of this kind of feature. However the fix for 1.b is very restricting. As an alternative, I think this should rather be fixed by ensuring that all functions which interact with the module evaluation (like {
attrsOf = elemType: {
_type = "option-type";
name = "attrsOf";
argument = elemType;
};
} While the module evaluation side would then actually take care of implementing this type. We could also have a With these changes we'll be able to write modules like { lib, ... }: {
# A nested submodule that uses a different `lib` for its evaluation
options.some.submodule = lib.mkOption {
# Even though we use the toplevel modules `lib` value, the module evaluation can decide how `attrsOf` is implemented for itself.
type = lib.types.attrsOf lib.types.int;
};
# Meanwhile options in the toplevel module evaluation work as well with the same `lib`
options.normal = lib.mkOption {
type = lib.types.attrsOf lib.types.int;
};
} This is a rather big undertaking, but I think it's a step in the right direction, and not just for the motivation I gave in this PR. This goes toward having a stable module system API, which we currently don't really have. Especially the |
So I think this is a problem for another day. I'll close this PR, but will open a new one with just the first 2 commits, which are still worthwhile to add (it's just a refactoring and a test). |
Motivation for this change
This allows submodules to use a custom
evalModules
function, which is useful when the modules aren't compatible with the default version, especially for thelib
module argument.Note that previously it was possible to pass a custom
lib
argument usingspecialArgs.lib
. However that still evaluated the modules using the standardlib.evalModules
, which causes problems when e.g.specialArgs.lib.mkOption
uses a newer nixpkgs version that adds anothermkOption
attribute (like #97114) but the standardlib.evalModules
can't handle that attribute yet.This allows fixing of infinisil/nixus#34
This is an extension of #75031
Ping @roberth @bqv
Things done