8
8
modulePath = nixpkgs + "/nixos/modules" ;
9
9
moduleListPath = modulePath + "/module-list.nix" ;
10
10
11
- inherit ( builtins ) isString filter mapAttrs isPath isFunction functionArgs pathExists ;
12
- inherit ( lib ) evalModules trivial optionals filterAttrs ;
11
+ inherit ( builtins )
12
+ isString
13
+ filter
14
+ mapAttrs
15
+ isPath
16
+ isFunction
17
+ functionArgs
18
+ pathExists
19
+ ;
20
+ inherit ( lib )
21
+ evalModules
22
+ trivial
23
+ optionals
24
+ filterAttrs
25
+ ;
13
26
inherit ( lib . options ) unknownModule literalExpression ;
14
27
15
28
# Polyfill for < 23.05
16
- renderOptionValue = lib . options . renderOptionValue or ( v :
17
- if v ? _type && v ? text then v
18
- else literalExpression ( lib . generators . toPretty {
19
- multiline = true ;
20
- allowPrettyValues = true ;
21
- } v ) ) ;
29
+ renderOptionValue =
30
+ lib . options . renderOptionValue or (
31
+ v :
32
+ if v ? _type && v ? text then
33
+ v
34
+ else
35
+ literalExpression (
36
+ lib . generators . toPretty {
37
+ multiline = true ;
38
+ allowPrettyValues = true ;
39
+ } v
40
+ )
41
+ ) ;
22
42
23
43
# Special tranfrom for < 23.05
24
- renderDoc = v :
25
- if isString v
26
- then { _type = "mdDoc" ; text = v ; }
27
- else v ;
44
+ renderDoc =
45
+ v :
46
+ if isString v then
47
+ {
48
+ _type = "mdDoc" ;
49
+ text = v ;
50
+ }
51
+ else
52
+ v ;
28
53
29
54
# Dummy `pkgs`.
30
55
pkgs = import ( nixpkgs + "/pkgs/pkgs-lib" ) {
39
64
modules = filter canCacheDocs ( import moduleListPath ) ;
40
65
41
66
# From `nixos/modules/misc/documentation.nix`.
42
- canCacheDocs = m :
67
+ canCacheDocs =
68
+ m :
43
69
let
44
70
f = import m ;
45
71
instance = f ( mapAttrs ( n : _ : abort "evaluating ${ n } for `meta` failed" ) ( functionArgs f ) ) ;
46
72
in
47
- isPath m
48
- && isFunction f
49
- && instance ? options
50
- && instance . meta . buildDocsInSandbox or true ;
73
+ isPath m && isFunction f && instance ? options && instance . meta . buildDocsInSandbox or true ;
51
74
52
75
config = {
53
76
_module . check = false ;
54
- _module . args = { } ;
77
+ _module . args = { } ;
55
78
system . stateVersion = trivial . release ;
56
79
} ;
57
80
eval = evalModules {
@@ -62,122 +85,147 @@ let
62
85
} ;
63
86
64
87
# https://github.com/NixOS/nixpkgs/blob/28c1aac72e3aef70b8c898ea9c16d5907f9eae22/lib/types.nix#L212
65
- normalizeType = submoduleVisible : ty : let
66
- elem = normalizeType submoduleVisible ty . nestedTypes . elemType ;
67
- ty' = rec {
68
- anything . name = "any" ;
69
- raw = anything ;
70
- unspecified = anything ;
71
-
72
- bool . name = "bool" ;
73
-
74
- int . name = "int" ;
75
- intBetween = int ;
76
- unsignedInt = int ;
77
- positiveInt = int ;
78
- signedInt8 = int ;
79
- signedInt16 = int ;
80
- signedInt32 = int ;
81
- unsignedInt8 = int ;
82
- unsignedInt16 = int ;
83
- unsignedInt32 = int ;
84
-
85
- float . name = "float" ;
86
- number = float ;
87
- numberBetween = float ;
88
- numberNonnegative = float ;
89
- numberPositive = float ;
90
-
91
- str . name = "string" ;
92
- nonEmptyStr = str ;
93
- singleLineStr = str ;
94
- # strMatching<regex>
95
- separatedString = str ;
96
- string = str ;
97
- # passwdEntry<name>
98
-
99
- attrs = { name = "attrset" ; rest = anything ; } ;
100
- package . name = "derivation" ;
101
- shellPackage . name = "derivation" ;
102
-
103
- path . name = "path" ;
104
-
105
- listOf = { name = "list" ; inherit elem ; } ;
106
-
107
- attrsOf = { name = "attrset" ; rest = elem ; } ;
108
- lazyAttrsOf = { name = "attrset" ; rest = elem ; } ;
109
-
110
- uniq = elem ;
111
- unique = elem ;
112
-
113
- # FIXME: Union and null type.
114
- nullOr = elem ;
115
-
116
- functionTo = { name = "lambda" ; from = anything ; to = elem ; } ;
117
-
118
- submodule = if submoduleVisible then {
119
- name = "attrset" ;
120
- fields = normalizeOptionSet ( ty . getSubOptions [ ] ) ;
121
- } else {
122
- name = "any" ;
123
- } ;
124
- deferredModule = submodule ;
125
-
126
- optionType = { name = "attrset" ; rest = anything ; } ;
127
-
128
- # enum
129
- # either
130
- # oneOf
131
- # coerceTo
132
- } . ${ ty . name } or { name = "any" ; } ;
133
- in
88
+ normalizeType =
89
+ submoduleVisible : ty :
90
+ let
91
+ elem = normalizeType submoduleVisible ty . nestedTypes . elemType ;
92
+ ty' =
93
+ rec {
94
+ anything . name = "any" ;
95
+ raw = anything ;
96
+ unspecified = anything ;
97
+
98
+ bool . name = "bool" ;
99
+
100
+ int . name = "int" ;
101
+ intBetween = int ;
102
+ unsignedInt = int ;
103
+ positiveInt = int ;
104
+ signedInt8 = int ;
105
+ signedInt16 = int ;
106
+ signedInt32 = int ;
107
+ unsignedInt8 = int ;
108
+ unsignedInt16 = int ;
109
+ unsignedInt32 = int ;
110
+
111
+ float . name = "float" ;
112
+ number = float ;
113
+ numberBetween = float ;
114
+ numberNonnegative = float ;
115
+ numberPositive = float ;
116
+
117
+ str . name = "string" ;
118
+ nonEmptyStr = str ;
119
+ singleLineStr = str ;
120
+ # strMatching<regex>
121
+ separatedString = str ;
122
+ string = str ;
123
+ # passwdEntry<name>
124
+
125
+ attrs = {
126
+ name = "attrset" ;
127
+ rest = anything ;
128
+ } ;
129
+ package . name = "derivation" ;
130
+ shellPackage . name = "derivation" ;
131
+
132
+ path . name = "path" ;
133
+
134
+ listOf = {
135
+ name = "list" ;
136
+ inherit elem ;
137
+ } ;
138
+
139
+ attrsOf = {
140
+ name = "attrset" ;
141
+ rest = elem ;
142
+ } ;
143
+ lazyAttrsOf = {
144
+ name = "attrset" ;
145
+ rest = elem ;
146
+ } ;
147
+
148
+ uniq = elem ;
149
+ unique = elem ;
150
+
151
+ # FIXME: Union and null type.
152
+ nullOr = elem ;
153
+
154
+ functionTo = {
155
+ name = "lambda" ;
156
+ from = anything ;
157
+ to = elem ;
158
+ } ;
159
+
160
+ submodule =
161
+ if submoduleVisible then
162
+ {
163
+ name = "attrset" ;
164
+ fields = normalizeOptionSet ( ty . getSubOptions [ ] ) ;
165
+ }
166
+ else
167
+ {
168
+ name = "any" ;
169
+ } ;
170
+ deferredModule = submodule ;
171
+
172
+ optionType = {
173
+ name = "attrset" ;
174
+ rest = anything ;
175
+ } ;
176
+
177
+ # enum
178
+ # either
179
+ # oneOf
180
+ # coerceTo
181
+ }
182
+ . ${ ty . name } or {
183
+ name = "any" ;
184
+ } ;
185
+ in
134
186
assert ty . _type or null == "option-type" ;
135
187
ty' ;
136
188
137
189
# Modified from `lib.optionAttrSetToDocList`.
138
- normalizeOptions = opt : let
139
- # visible: true | false | "shallow"
140
- visible = ( opt . visible or true != false ) && ! ( opt . internal or false ) ;
141
- submoduleVisible = visible && ( opt . visible or true == true ) ;
142
-
143
- opt' = {
144
- description = renderDoc ( opt . description or null ) ;
145
- declarations = filter ( x : x != unknownModule ) opt . declarations ;
146
- readOnly = opt . readOnly or false ;
147
- type = normalizeType submoduleVisible opt . type ;
148
- example =
149
- if opt ? example then
150
- renderOptionValue opt . example
151
- else
152
- null ;
153
- default =
154
- if opt ? default then
155
- renderOptionValue ( opt . defaultText or opt . default )
156
- else
157
- null ;
158
- relatedPackages =
159
- optionals ( opt . relatedPackages or null != null )
160
- opt . relatedPackages ;
161
- } ;
162
- in
190
+ normalizeOptions =
191
+ opt :
192
+ let
193
+ # visible: true | false | "shallow"
194
+ visible = ( opt . visible or true != false ) && ! ( opt . internal or false ) ;
195
+ submoduleVisible = visible && ( opt . visible or true == true ) ;
196
+
197
+ opt' = {
198
+ description = renderDoc ( opt . description or null ) ;
199
+ declarations = filter ( x : x != unknownModule ) opt . declarations ;
200
+ readOnly = opt . readOnly or false ;
201
+ type = normalizeType submoduleVisible opt . type ;
202
+ example = if opt ? example then renderOptionValue opt . example else null ;
203
+ default = if opt ? default then renderOptionValue ( opt . defaultText or opt . default ) else null ;
204
+ relatedPackages = optionals ( opt . relatedPackages or null != null ) opt . relatedPackages ;
205
+ } ;
206
+ in
163
207
if opt . _type or null == "option" then
164
- if visible then
165
- opt'
166
- else
167
- null
168
- else {
169
- type = {
170
- name = "attrset" ;
171
- fields = normalizeOptionSet opt ;
208
+ if visible then opt' else null
209
+ else
210
+ {
211
+ type = {
212
+ name = "attrset" ;
213
+ fields = normalizeOptionSet opt ;
214
+ } ;
172
215
} ;
173
- } ;
174
216
175
- normalizeOptionSet = opts :
176
- filterAttrs ( k : v : k != "_module" && k != "_freeformOptions" && ! isNull v )
177
- ( mapAttrs ( _ : normalizeOptions ) opts ) ;
217
+ normalizeOptionSet =
218
+ opts :
219
+ filterAttrs ( k : v : k != "_module" && k != "_freeformOptions" && ! isNull v ) (
220
+ mapAttrs ( _ : normalizeOptions ) opts
221
+ ) ;
178
222
179
223
in
180
- if pathExists libPath && pathExists moduleListPath
181
- && builtins . compareVersions trivial . release "22.11" >= 0
182
- then normalizeOptionSet eval . options
183
- else { }
224
+ if
225
+ pathExists libPath
226
+ && pathExists moduleListPath
227
+ && builtins . compareVersions trivial . release "22.11" >= 0
228
+ then
229
+ normalizeOptionSet eval . options
230
+ else
231
+ { }
0 commit comments