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

<name> as prefix in types.attrsOf types.submodule is often unhelpful #295872

Closed
Ma27 opened this issue Mar 14, 2024 · 5 comments · Fixed by #344216
Closed

<name> as prefix in types.attrsOf types.submodule is often unhelpful #295872

Ma27 opened this issue Mar 14, 2024 · 5 comments · Fixed by #344216
Labels
0.kind: bug Something is broken 6.topic: module system About "NixOS" module system internals

Comments

@Ma27
Copy link
Member

Ma27 commented Mar 14, 2024

Describe the bug

Let's take a look at e.g. systemd.tmpfiles.settings.<name>.<name>.<name>.user.

The line itself is the first thing you get when searching for how to use systemd.tmpfiles on search.nixos.org. The problem is, how am I supposed to know what each of these <name> entries means?
Sure, you can deduce it by looking at the example from options.systemd.tmpfiles.settings, but it would be immediately obvious if it's called like this:

systemd.tmpfiles.settings.<rule-name>.<type>.<path>

(type & path are derived from tmpfiles.d(5)).

One ad-hoc way of solving that is to add some kind of namedAttrsOf function that accepts an argument for the prefix for getSubOptions, however it feels wrong to add a new "type" just for that. Also, namedAttrsOf str doesn't make much sense, it's effectively the same as attrsOf str.

But perhaps the sub-type can provide a "prefix name" to the parent? Like attrsOf (submodule { options = ...; name = ...; })? We should probably force it to be in </> for lib.showOption. Anyways, I know the knobs where to change that, but we should discuss first whether we want this and I'd need some input on how to reasonably design that.

Notify maintainers

@roberth
@infinisil


Add a 👍 reaction to issues you find important.

@Ma27 Ma27 added 0.kind: bug Something is broken 6.topic: module system About "NixOS" module system internals labels Mar 14, 2024
@infinisil
Copy link
Member

infinisil commented Apr 9, 2024

The pattern that has established itself is to add -With variants, in this case attrsOfWith, which takes an attribute set with more arguments. In this case it could be

attrsOfWith {
  elemType = ...;
  metaName = ...;
}

I'd be in favor of adding something like this :)

@roberth
Copy link
Member

roberth commented Apr 9, 2024

I think we can drop the Of, because we don't have a simply parameter for the type.

attrsWith {
  elemType = ...;
  ...
}

Not sure about metaName. Does it only affect docs, or also the module argument?

Context:

@infinisil
Copy link
Member

Good point on the Of, attrsWith sounds good.

And oh actually indeed, this would effectively implement this and therefore also solve that problem! I still think it should be called metaName though, or at least definitely not name to avoid confusion with the attribute name of the definitions

@roberth
Copy link
Member

roberth commented Apr 9, 2024

"Meta" is ambiguous in that name. I assume you want it to take the proper meaning of meta, and not refer to the meta attribute or something like "name for use in metadata".

nameName would solve that, but we can probably do even better.

@infinisil
Copy link
Member

Oh yeah. I think metaName would be fine because the true meaning of meta is the only one that makes sense here. Can't immediately think of a better alternative that would not be more confusing, but I'm open to alternatives (definitely not nameName though!).

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.

3 participants