1919 simpleOptionWithParameter = type : elemType : default :
2020 simpleOption ( type elemType ) default ;
2121in rec {
22+ # Types
2223 inherit ( lib . types ) anything attrsOf bool coercedTo enum float int listOf number package path port singleLineStr str submodule ;
2324 attrs = attrsOf anything ;
2425 attrsLegacy = lib . types . attrs ;
2526 lambda = lib . types . functionTo anything ;
2627 lambdaTo = lib . types . functionTo ;
2728 list = listOf anything ;
2829
30+ # Options
2931 anythingOption = simpleOption anything ;
3032 attrsLegacyOption = simpleOption attrsLegacy ;
3133 attrsOfOption = simpleOptionWithParameter attrsOf ;
@@ -47,6 +49,7 @@ in rec {
4749 strOption = simpleOption str ;
4850 submoduleOption = simpleOptionWithParameter submodule ;
4951
52+ # Option type extensions
5053 allowAnything = addTypeToOption anything ;
5154 allowAttrs = addTypeToOption attrs ;
5255 allowAttrsLegacy = addTypeToOption attrsLegacy ;
@@ -68,17 +71,18 @@ in rec {
6871 allowSingleLineStrOption = addTypeToOption singleLineStr ;
6972 allowStr = addTypeToOption str ;
7073
74+ # Option modifiers
7175 noDefault = option : builtins . removeAttrs option [ "default" ] ;
7276 # This is a more convenient way to handle the presence of a default value in the option based on the condition (#18)
7377 noNullDefault = option :
7478 if option . default == null
7579 then builtins . removeAttrs option [ "default" ]
7680 else option ;
7781 readOnly = option : option // { readOnly = true ; } ;
78-
7982 apply = option : apply : option // { inherit apply ; } ;
8083 description = option : description : option // { inherit description ; } ;
8184
85+ # Predefined option patterns
8286 singleEnableOption = default : { name , ...} :
8387 delib . attrset . setAttrByStrPath "${ name } .enable" ( boolOption default ) ;
8488}
0 commit comments