Skip to content
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

Repeated use of moduleType or (extendModules foo).type in attrsOf can not use the name parameter. #177564

Closed
roberth opened this issue Jun 13, 2022 · 2 comments
Labels
0.kind: bug Something is broken 6.topic: module system About "NixOS" module system internals

Comments

@roberth
Copy link
Member

roberth commented Jun 13, 2022

Describe the bug

For context, moduleType and extendModules duplicate the configuration namespace, but with user-defined modules added.

Extending the configuration more than once makes name throw a duplicate definition error.

Steps To Reproduce

Suppose we have

{ config, moduleType, ... }: {
  options.variants = mkOption { type = attrsOf moduleType; };
  options.result = mkOption { type = str; };
}

then

variants.foo = { name, ... }: { result = name; }

will result in

variants.foo.result == "foo"

but

variants.foo.variants.bar = { name, ... }: { result = name; }

causes an error because name is redefined in the second level.

Expected behavior

  • name does not throw an error.

  • All names can be used.

Additional context

Discovered in #176557 matrix module.

This can be solved by defining name in specialArgs, or by making the parameter name configurable (creating PR in a minute).

Notify maintainers

@infinisil

@roberth roberth added 0.kind: bug Something is broken 6.topic: module system About "NixOS" module system internals labels Jun 13, 2022
@roberth
Copy link
Member Author

roberth commented Jun 18, 2022

Workaround: add a submodule between attrsOf and moduleType so that the submodule can set the appropriate option in moduleType, instead of having moduleType itself rely on _module.args.name (which still can't be used, but doesn't have to be used).

Example: 7071f1d

@roberth
Copy link
Member Author

roberth commented Aug 19, 2022

attrsOf (attrsOf x) seems like an antipattern limiting extensibility at the attrsOf (once) level.

@roberth roberth closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: module system About "NixOS" module system internals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant