-
Notifications
You must be signed in to change notification settings - Fork 45
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
Exposing a flakeModule that depends on other flake modules without defining in the same file #121
Comments
I currently require the user to manually import all the dependencies, in https://github.com/Platonic-Systems/mission-control for example But I guess what we probably want is some sort of module dependency system. |
This touches on a deeper discussion about how we want to manage module dependencies, besides the syntax we use to import them: Let's purpose this thread for the more "syntax-level" details. |
This is making an assumption about the
It's better not to use
This can be combined with a separate file.
This creates the input name dependency that we should try to avoid.
I don't have a definitive answer yet, but these are competing solutions:
|
To clarify this was not part of the exposed module, this was the flake itself and how it defined the module, so I guess that should be fine: {inputs, ...}:
{
imports = [inputs.flake-parts.flakeModules.flakeModules]; I managed to get it to work with the For example: flake.flakeModules = {
default = {
imports = [
config.flake.flakeModules.moduleA
config.flake.flakeModules.moduleB
];
}; |
Yeah (just to add) |
Adding This solves the location part. The "key" aspect (dedup and disabledModules) can not reasonably be covered by it, so this will be the responsibility of the |
As mentioned in #146 (comment) , I think the easier solution is to turn flakeModulesOption into a submodule instead of a flakeModulesOption = mkOption {
apply = builtins.mapAttr (name: module: rec { imports = [ module ]; key = "${inputs.self}#flakeModules.${name}" }; _file = key; });
type = types.submoduleOf {
modules = [
{
# Making it be a freeformType for backward compatibility only
config._module.freeformType = types.lazyAttrsOf types.deferredModule;
}
];
};
}; Then a flake module can be defined as an option to reference other flake modules: # myModule1.nix
# Note that the inputs are from the lexical scope, not the user's root inputs, solving https://github.com/hercules-ci/flake-parts/issues/104
{flake-parts-lib, inputs, ...}:{
option.flake = flake-parts-lib.mkSubmoduleOption {
flakeModules = flake-parts-lib.mkSubmoduleOption {
myModule1 = flake-parts-lib.mkDeferredModuleOption {
options.myOption = mkOption { default = "my default value"; };
};
};
};
} # myModule2.nix
{flake-parts-lib, inputs, ...}:{
imports = [ ./myModule1.nix ];
option.flake = flake-parts-lib.mkSubmoduleOption {
flakeModules = flake-parts-lib.mkSubmoduleOption (flakeModules: {
myModule2 = flake-parts-lib.mkDeferredModuleOption {
imports = [ flakeModules.config.myModule1 ];
config.myOption = "my overridden value";
};
});
};
} If
|
By turning |
We might want to move |
How would
You might be thinking of |
Updated #121 (comment) to describe
Because I want to avoid |
Also we can call |
If |
We have tests for I can't verify any of this right now, and these discussions have already taken up a lot of time. I'll have to resume this later, but feel free to try things in the meantime.
Doing it twice smells a lot like we have a need for fixpoint iteration then, and that would not be feasible. I'd prefer to have a very restricted step that only processes |
Do you mean we can already reference other modules under the same repository via If the claim is true, we should directly close this issue, because referencing a flake module from |
Why do you think it's not feasible? Sbt supports recursively solving sbt plugins for sbt plugins according to this document. |
I think we don't have to change |
It turned out that what resulted in infinite loop is self.outPath, not
lazyAttrsOf.
…On Mon, May 8, 2023 at 6:08 PM Robert Hensing ***@***.***> wrote:
I want to avoid lazyAttrsOf, which would result in infinite loop
We have tests for lazyAttrsOf, so you can paint me skeptical. Would love
to have a reproducer for whatever would be wrong with it, but I find it
unlikely that lazyAttrsOf would be in the critical path. If anything, I
would expect the problem to be with config.
I can't verify any of this right now, and these discussions have already
taken up a lot of time. I'll have to resume this later, but feel free to
try things in the meantime.
Also we can call mkFlake twice to use a flake's own flake module,
Doing it twice smells a lot like we have a need for fixpoint iteration
then, and that would not be feasible. I'd prefer to have a very restricted
step that only processes flakeModules without the incomplete context of
the first step. I would suppose that the incomplete context is unnecessary
anyway.
But yes, the logic I was proposing for localFlakeModules and all that
resembles the flake-parts.flakeModules.flakeModules module a lot.
Implementing it with the module system seems like a good idea, but I
wouldn't reuse mkFlake for it.
(I can sort of imagine perhaps some other "dependency management" options
to end up in that little module context, although those are probably not
very helpful ones without additions to Nix's flakes feature. Ideally flakes
itself would just bear such responsibilities. But let's not get ahead of
ourselves on this)
—
Reply to this email directly, view it on GitHub
<#121 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAES3OSAN2HW6GNCQJRHBIDXFGKJFANCNFSM6AAAAAAVJNYJAI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I updated #197 to utilize partitions to solve this issue. I think this issue can be considered fixed. |
What is the best practice to expose a flakeModule that depends on other flake modules?
I have something like this:
flake.nix:
modules.nix:
my-module.nix:
I currently have 4 solutions, none of them feel optimal.
imports
, but one needs to do(import ./modules.nix { inherit inputs; })
for example)modules.nix
,{ imports = [...inputs, ./my-module.nix]; }
I guess there are no
_module.args.inputs
or something that could be utilized?What is the best practices for this kind of thing?
The text was updated successfully, but these errors were encountered: