@@ -21,7 +21,86 @@ with types;
21
21
22
22
# Work around issue that can cause _lots_ of files to be copied into the store.
23
23
# See https://github.com/NixOS/nixpkgs/pull/64691
24
- let path = types . path // { check = x : types . path . check ( x . origSrc or x ) ; } ;
24
+ let
25
+ path = types . path // { check = x : types . path . check ( x . origSrc or x ) ; } ;
26
+
27
+ componentType = submodule {
28
+ # add the shared componentOptions
29
+ options = ( packageOptions config ) // {
30
+ buildable = mkOption {
31
+ type = bool ;
32
+ default = true ;
33
+ } ;
34
+ depends = mkOption {
35
+ type = listOfFilteringNulls unspecified ;
36
+ default = [ ] ;
37
+ } ;
38
+ libs = mkOption {
39
+ type = listOfFilteringNulls ( nullOr package ) ;
40
+ default = [ ] ;
41
+ } ;
42
+ frameworks = mkOption {
43
+ type = listOfFilteringNulls package ;
44
+ default = [ ] ;
45
+ } ;
46
+ pkgconfig = mkOption {
47
+ type = listOf ( listOfFilteringNulls package ) ;
48
+ default = [ ] ;
49
+ } ;
50
+ build-tools = mkOption {
51
+ type = listOfFilteringNulls unspecified ;
52
+ default = [ ] ;
53
+ } ;
54
+ modules = mkOption {
55
+ type = listOfFilteringNulls unspecified ;
56
+ default = [ ] ;
57
+ } ;
58
+ asmSources = mkOption {
59
+ type = listOfFilteringNulls unspecified ;
60
+ default = [ ] ;
61
+ } ;
62
+ cmmSources = mkOption {
63
+ type = listOfFilteringNulls unspecified ;
64
+ default = [ ] ;
65
+ } ;
66
+ cSources = mkOption {
67
+ type = listOfFilteringNulls unspecified ;
68
+ default = [ ] ;
69
+ } ;
70
+ cxxSources = mkOption {
71
+ type = listOfFilteringNulls unspecified ;
72
+ default = [ ] ;
73
+ } ;
74
+ jsSources = mkOption {
75
+ type = listOfFilteringNulls unspecified ;
76
+ default = [ ] ;
77
+ } ;
78
+ hsSourceDirs = mkOption {
79
+ type = listOfFilteringNulls unspecified ;
80
+ default = [ "." ] ;
81
+ } ;
82
+ includeDirs = mkOption {
83
+ type = listOfFilteringNulls unspecified ;
84
+ default = [ ] ;
85
+ } ;
86
+ includes = mkOption {
87
+ type = listOfFilteringNulls unspecified ;
88
+ default = [ ] ;
89
+ } ;
90
+ mainPath = mkOption {
91
+ type = listOfFilteringNulls unspecified ;
92
+ default = [ ] ;
93
+ } ;
94
+ extraSrcFiles = mkOption {
95
+ type = listOfFilteringNulls unspecified ;
96
+ default = [ ] ;
97
+ } ;
98
+ platforms = mkOption {
99
+ type = nullOr ( listOfFilteringNulls unspecified ) ;
100
+ default = null ;
101
+ } ;
102
+ } ;
103
+ } ;
25
104
26
105
in {
27
106
# This is how the Nix expressions generated by *-to-nix receive
@@ -143,85 +222,7 @@ in {
143
222
} ;
144
223
} ;
145
224
146
- components = let
147
- componentType = submodule {
148
- # add the shared componentOptions
149
- options = ( packageOptions config ) // {
150
- buildable = mkOption {
151
- type = bool ;
152
- default = true ;
153
- } ;
154
- depends = mkOption {
155
- type = listOfFilteringNulls unspecified ;
156
- default = [ ] ;
157
- } ;
158
- libs = mkOption {
159
- type = listOfFilteringNulls ( nullOr package ) ;
160
- default = [ ] ;
161
- } ;
162
- frameworks = mkOption {
163
- type = listOfFilteringNulls package ;
164
- default = [ ] ;
165
- } ;
166
- pkgconfig = mkOption {
167
- type = listOf ( listOfFilteringNulls package ) ;
168
- default = [ ] ;
169
- } ;
170
- build-tools = mkOption {
171
- type = listOfFilteringNulls unspecified ;
172
- default = [ ] ;
173
- } ;
174
- modules = mkOption {
175
- type = listOfFilteringNulls unspecified ;
176
- default = [ ] ;
177
- } ;
178
- asmSources = mkOption {
179
- type = listOfFilteringNulls unspecified ;
180
- default = [ ] ;
181
- } ;
182
- cmmSources = mkOption {
183
- type = listOfFilteringNulls unspecified ;
184
- default = [ ] ;
185
- } ;
186
- cSources = mkOption {
187
- type = listOfFilteringNulls unspecified ;
188
- default = [ ] ;
189
- } ;
190
- cxxSources = mkOption {
191
- type = listOfFilteringNulls unspecified ;
192
- default = [ ] ;
193
- } ;
194
- jsSources = mkOption {
195
- type = listOfFilteringNulls unspecified ;
196
- default = [ ] ;
197
- } ;
198
- hsSourceDirs = mkOption {
199
- type = listOfFilteringNulls unspecified ;
200
- default = [ "." ] ;
201
- } ;
202
- includeDirs = mkOption {
203
- type = listOfFilteringNulls unspecified ;
204
- default = [ ] ;
205
- } ;
206
- includes = mkOption {
207
- type = listOfFilteringNulls unspecified ;
208
- default = [ ] ;
209
- } ;
210
- mainPath = mkOption {
211
- type = listOfFilteringNulls unspecified ;
212
- default = [ ] ;
213
- } ;
214
- extraSrcFiles = mkOption {
215
- type = listOfFilteringNulls unspecified ;
216
- default = [ ] ;
217
- } ;
218
- platforms = mkOption {
219
- type = nullOr ( listOfFilteringNulls unspecified ) ;
220
- default = null ;
221
- } ;
222
- } ;
223
- } ;
224
- in {
225
+ components = {
225
226
setup = mkOption {
226
227
type = nullOr componentType ;
227
228
default = {
@@ -300,5 +301,43 @@ in {
300
301
type = listOf ( either unspecified path ) ;
301
302
default = [ ] ;
302
303
} ;
304
+ # This used to be `components.all` but it has been added back as `allComponent` to
305
+ # to avoid confusion. It is not mapped by `builder/hspkg-builder.nix` to anything
306
+ # you can build. Instead it is used internally when `configureAllComponents`
307
+ # is set or for tests whe on `cabal-doctest` is in the `setup-depends` of the package.
308
+ allComponent = mkOption {
309
+ type = componentType ;
310
+ apply = all : all // {
311
+ # TODO: Should this check for the entire component
312
+ # definition to match, rather than just the identifier?
313
+ depends = builtins . filter ( p : p . identifier != config . package . identifier ) all . depends ;
314
+ } ;
315
+ description = "The merged dependencies of all other components" ;
316
+ } ;
303
317
} ;
318
+
319
+ # This has one quirk. Manually setting options on the all component
320
+ # will be considered a conflict. This is almost always fine; most
321
+ # settings should be modified in either the package options, or an
322
+ # individual component's options. When this isn't sufficient,
323
+ # mkForce is a reasonable workaround.
324
+ #
325
+ # An alternative solution to mkForce for many of the options where
326
+ # this is relevant would be to switch from the bool type to
327
+ # something like an anyBool type, which would merge definitions by
328
+ # returning true if any is true.
329
+ config . allComponent =
330
+ let allComps = haskellLib . getAllComponents config ;
331
+ in lib . mkMerge (
332
+ builtins . map ( c :
333
+ # Exclude attributes that are likely to have conflicting definitions
334
+ # (a common use case for `all` is in `shellFor` and it only has an
335
+ # install phase).
336
+ builtins . removeAttrs c [ "preCheck" "postCheck" "keepSource" ]
337
+ ) allComps
338
+ ) // {
339
+ # If any one of the components needs us to keep the source
340
+ # then keep it for the `all` component
341
+ keepSource = lib . foldl' ( x : comp : x || comp . keepSource ) false allComps ;
342
+ } ;
304
343
}
0 commit comments