lib/types: Introduce types.unconditional#160491
lib/types: Introduce types.unconditional#160491infinisil wants to merge 1 commit intoNixOS:masterfrom
Conversation
Allows replacing `types.lazyAttrsOf elemType` with `types.attrsOf (types.unconditional elemType)`. Also works with lists: `types.listOf (types.unconditional elemType)`.
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
ncfavier
left a comment
There was a problem hiding this comment.
Let's get this in while we wait for NixOS/nix#4090? I think this is a welcome simplification with no downsides.
| # nested types | ||
| nestedTypes ? {} | ||
| # Whether `mkIf` assignments can cause the definiton to be optional in | ||
| # the parent option. If `processed` is false, this is implicitly false too |
There was a problem hiding this comment.
processed does not seem to have survived, whatever it was
| isDefined = defsFinal != []; | ||
| # Note: We use `or true` in case `lib.types` from an older nixpkgs version | ||
| # that doesn't set `conditional` is used. Avoids some trouble down the road | ||
| isDefined = type.conditional or true -> defsFinal != []; |
There was a problem hiding this comment.
Let's maybe factor out the two type.conditional or trues
| types = rec { | ||
|
|
||
| unconditional = elemType: elemType // { | ||
| conditional = false; |
There was a problem hiding this comment.
| conditional = false; | |
| conditional = false; | |
| description = "unconditional ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}"; | |
| descriptionClass = "composite"; |
Maybe? Or lazy? IDK
That proposed change only allows access to attributes on the right hand side of (EDIT) haven't tested |
Motivation for this change
Introduce
types.unconditional <elemType>as a type, which when used as e.g.attrsOf (unconditional str)can replacelazyAttrsOf str. This type ensures that conditionalmkIfdefinitions can't influence whether the option is defined or not, and therefore make the attribute set values be evaluated lazily. This notably also works withlistOf (unconditional str), making the list elements evaluated lazily, which was not possible before.Split off from #132448
Things done