forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.nix
More file actions
877 lines (779 loc) · 28 KB
/
compose.nix
File metadata and controls
877 lines (779 loc) · 28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# TODO(@Ericson2314): Remove `pkgs` param, which is only used for
# `buildStackProject`, `justStaticExecutables` and `checkUnusedPackages`
{ pkgs, lib }:
rec {
/*
This function takes a file like `hackage-packages.nix` and constructs
a full package set out of that.
*/
makePackageSet = import ../make-package-set.nix;
/*
The function overrideCabal lets you alter the arguments to the
mkDerivation function.
Example:
First, note how the aeson package is constructed in hackage-packages.nix:
"aeson" = callPackage ({ mkDerivation, attoparsec, <snip>
}:
mkDerivation {
pname = "aeson";
<snip>
homepage = "https://github.com/bos/aeson";
})
The mkDerivation function of haskellPackages will take care of putting
the homepage in the right place, in meta.
> haskellPackages.aeson.meta.homepage
"https://github.com/bos/aeson"
> x = haskell.lib.compose.overrideCabal (old: { homepage = old.homepage + "#readme"; }) haskellPackages.aeson
> x.meta.homepage
"https://github.com/bos/aeson#readme"
*/
overrideCabal =
f: drv:
(drv.override (
args:
args
// {
mkDerivation = drv: (args.mkDerivation drv).override f;
}
))
// {
overrideScope = scope: overrideCabal f (drv.overrideScope scope);
};
# : Map Name (Either Path VersionNumber) -> HaskellPackageOverrideSet
# Given a set whose values are either paths or version strings, produces
# a package override set (i.e. (self: super: { etc. })) that sets
# the packages named in the input set to the corresponding versions
packageSourceOverrides =
overrides: self: super:
pkgs.lib.mapAttrs (
name: src:
let
isPath = x: builtins.substring 0 1 (toString x) == "/";
generateExprs = if isPath src then self.callCabal2nix else self.callHackage;
in
generateExprs name src { }
) overrides;
/*
doCoverage modifies a haskell package to enable the generation
and installation of a coverage report.
See https://wiki.haskell.org/Haskell_program_coverage
*/
doCoverage = overrideCabal (drv: {
doCoverage = true;
});
/*
dontCoverage modifies a haskell package to disable the generation
and installation of a coverage report.
*/
dontCoverage = overrideCabal (drv: {
doCoverage = false;
});
/*
doHaddock modifies a haskell package to enable the generation and
installation of API documentation from code comments using the
haddock tool.
*/
doHaddock = overrideCabal (drv: {
doHaddock = true;
});
/*
dontHaddock modifies a haskell package to disable the generation and
installation of API documentation from code comments using the
haddock tool.
*/
dontHaddock = overrideCabal (drv: {
doHaddock = false;
});
/*
doJailbreak enables the removal of version bounds from the cabal
file. You may want to avoid this function.
This is useful when a package reports that it can not be built
due to version mismatches. In some cases, removing the version
bounds entirely is an easy way to make a package build, but at
the risk of breaking software in non-obvious ways now or in the
future.
Instead of jailbreaking, you can patch the cabal file.
Note that jailbreaking at this time, doesn't lift bounds on
conditional branches.
https://github.com/peti/jailbreak-cabal/issues/7 has further details.
*/
doJailbreak = overrideCabal (drv: {
jailbreak = true;
});
/*
dontJailbreak restores the use of the version bounds the check
the use of dependencies in the package description.
*/
dontJailbreak = overrideCabal (drv: {
jailbreak = false;
});
/*
doCheck enables dependency checking, compilation and execution
of test suites listed in the package description file.
*/
doCheck = overrideCabal (drv: {
doCheck = true;
});
/*
dontCheck disables dependency checking, compilation and execution
of test suites listed in the package description file.
*/
dontCheck = overrideCabal (drv: {
doCheck = false;
});
/*
The dontCheckIf variant sets doCheck = false if the condition
applies. In any other case the previously set/default value is used.
This prevents accidentally re-enabling tests in a later override.
*/
dontCheckIf = condition: if condition then dontCheck else lib.id;
/*
doBenchmark enables dependency checking and compilation
for benchmarks listed in the package description file.
Benchmarks are, however, not executed at the moment.
*/
doBenchmark = overrideCabal (drv: {
doBenchmark = true;
});
/*
dontBenchmark disables dependency checking, compilation and execution
for benchmarks listed in the package description file.
*/
dontBenchmark = overrideCabal (drv: {
doBenchmark = false;
});
/*
doDistribute enables the distribution of binaries for the package
via hydra.
*/
doDistribute = overrideCabal (drv: {
# lib.platforms.all is the default value for platforms (since GHC can cross-compile)
hydraPlatforms = lib.subtractLists (drv.badPlatforms or [ ]) (drv.platforms or lib.platforms.all);
});
/*
dontDistribute disables the distribution of binaries for the package
via hydra.
*/
dontDistribute = overrideCabal (drv: {
hydraPlatforms = [ ];
});
/*
appendConfigureFlag adds a single argument that will be passed to the
cabal configure command, after the arguments that have been defined
in the initial declaration or previous overrides.
Example:
> haskell.lib.compose.appendConfigureFlag "--profiling-detail=all-functions" haskellPackages.servant
*/
appendConfigureFlag = x: appendConfigureFlags [ x ];
appendConfigureFlags =
xs:
overrideCabal (drv: {
configureFlags = (drv.configureFlags or [ ]) ++ xs;
});
appendBuildFlag =
x:
overrideCabal (drv: {
buildFlags = (drv.buildFlags or [ ]) ++ [ x ];
});
appendBuildFlags =
xs:
overrideCabal (drv: {
buildFlags = (drv.buildFlags or [ ]) ++ xs;
});
/*
removeConfigureFlag drv x is a Haskell package like drv, but with
all cabal configure arguments that are equal to x removed.
> haskell.lib.compose.removeConfigureFlag "--verbose" haskellPackages.servant
*/
removeConfigureFlag =
x:
overrideCabal (drv: {
configureFlags = lib.remove x (drv.configureFlags or [ ]);
});
addBuildTool = x: addBuildTools [ x ];
addBuildTools =
xs:
overrideCabal (drv: {
buildTools = (drv.buildTools or [ ]) ++ xs;
});
addExtraLibrary = x: addExtraLibraries [ x ];
addExtraLibraries =
xs:
overrideCabal (drv: {
extraLibraries = (drv.extraLibraries or [ ]) ++ xs;
});
addBuildDepend = x: addBuildDepends [ x ];
addBuildDepends =
xs:
overrideCabal (drv: {
buildDepends = (drv.buildDepends or [ ]) ++ xs;
});
addTestToolDepend = x: addTestToolDepends [ x ];
addTestToolDepends =
xs:
overrideCabal (drv: {
testToolDepends = (drv.testToolDepends or [ ]) ++ xs;
});
addPkgconfigDepend = x: addPkgconfigDepends [ x ];
addPkgconfigDepends =
xs:
overrideCabal (drv: {
pkg-configDepends = (drv.pkg-configDepends or [ ]) ++ xs;
});
addSetupDepend = x: addSetupDepends [ x ];
addSetupDepends =
xs:
overrideCabal (drv: {
setupHaskellDepends = (drv.setupHaskellDepends or [ ]) ++ xs;
});
enableCabalFlag = x: drv: appendConfigureFlag "-f${x}" (removeConfigureFlag "-f-${x}" drv);
disableCabalFlag = x: drv: appendConfigureFlag "-f-${x}" (removeConfigureFlag "-f${x}" drv);
markBroken = overrideCabal (drv: {
broken = true;
hydraPlatforms = [ ];
});
unmarkBroken = overrideCabal (drv: {
broken = false;
});
markBrokenVersion =
version: drv:
assert drv.version == version;
markBroken drv;
markUnbroken = overrideCabal (drv: {
broken = false;
});
/*
disableParallelBuilding drops the -j<n> option from the GHC
command line for the given package. This can be useful in rare
situations where parallel building of a package causes GHC to
fail for some reason.
*/
disableParallelBuilding = overrideCabal (drv: {
enableParallelBuilding = false;
});
enableLibraryProfiling = overrideCabal (drv: {
enableLibraryProfiling = true;
});
disableLibraryProfiling = overrideCabal (drv: {
enableLibraryProfiling = false;
});
enableExecutableProfiling = overrideCabal (drv: {
enableExecutableProfiling = true;
});
disableExecutableProfiling = overrideCabal (drv: {
enableExecutableProfiling = false;
});
enableSharedExecutables = overrideCabal (drv: {
enableSharedExecutables = true;
});
disableSharedExecutables = overrideCabal (drv: {
enableSharedExecutables = false;
});
enableSharedLibraries = overrideCabal (drv: {
enableSharedLibraries = true;
});
disableSharedLibraries = overrideCabal (drv: {
enableSharedLibraries = false;
});
enableDeadCodeElimination = overrideCabal (drv: {
enableDeadCodeElimination = true;
});
disableDeadCodeElimination = overrideCabal (drv: {
enableDeadCodeElimination = false;
});
enableStaticLibraries = overrideCabal (drv: {
enableStaticLibraries = true;
});
disableStaticLibraries = overrideCabal (drv: {
enableStaticLibraries = false;
});
enableSeparateBinOutput = overrideCabal (drv: {
enableSeparateBinOutput = true;
});
appendPatch = x: appendPatches [ x ];
appendPatches =
xs:
overrideCabal (drv: {
patches = (drv.patches or [ ]) ++ xs;
});
/*
Set a specific build target instead of compiling all targets in the package.
For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server".
We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows:
> setBuildTarget "server" (callCabal2nix "thePackageName" thePackageSrc {})
*/
setBuildTargets =
xs:
overrideCabal (drv: {
buildTarget = lib.concatStringsSep " " xs;
});
setBuildTarget = x: setBuildTargets [ x ];
doHyperlinkSource = overrideCabal (drv: {
hyperlinkSource = true;
});
dontHyperlinkSource = overrideCabal (drv: {
hyperlinkSource = false;
});
disableHardening =
flags:
overrideCabal (drv: {
hardeningDisable = flags;
});
/*
Let Nix strip the binary files.
This removes debugging symbols.
*/
doStrip = overrideCabal (drv: {
dontStrip = false;
});
/*
Stop Nix from stripping the binary files.
This keeps debugging symbols.
*/
dontStrip = overrideCabal (drv: {
dontStrip = true;
});
/*
Useful for debugging segfaults with gdb.
This includes dontStrip.
*/
enableDWARFDebugging =
drv:
# -g: enables debugging symbols
# --disable-*-stripping: tell GHC not to strip resulting binaries
# dontStrip: see above
appendConfigureFlag "--ghc-options=-g --disable-executable-stripping --disable-library-stripping" (
dontStrip drv
);
/*
Create a source distribution tarball like those found on hackage,
instead of building the package.
*/
sdistTarball =
pkg:
lib.overrideDerivation pkg (drv: {
name = "${drv.pname}-source-${drv.version}";
# Since we disable the haddock phase, we also need to override the
# outputs since the separate doc output will not be produced.
outputs = [ "out" ];
buildPhase = "./Setup sdist";
haddockPhase = ":";
checkPhase = ":";
installPhase = "install -D dist/${drv.pname}-*.tar.gz $out/${drv.pname}-${drv.version}.tar.gz";
fixupPhase = ":";
});
/*
Create a documentation tarball suitable for uploading to Hackage instead
of building the package.
*/
documentationTarball =
pkg:
pkgs.lib.overrideDerivation pkg (drv: {
name = "${drv.name}-docs";
# Like sdistTarball, disable the "doc" output here.
outputs = [ "out" ];
buildPhase = ''
runHook preHaddock
./Setup haddock --for-hackage
runHook postHaddock
'';
haddockPhase = ":";
checkPhase = ":";
installPhase = ''
runHook preInstall
mkdir -p "$out"
tar --format=ustar \
-czf "$out/${drv.name}-docs.tar.gz" \
-C dist/doc/html "${drv.name}-docs"
runHook postInstall
'';
});
/*
Use the gold linker. It is a linker for ELF that is designed
"to run as fast as possible on modern systems"
*/
linkWithGold = appendConfigureFlag "--ghc-option=-optl-fuse-ld=gold --ld-option=-fuse-ld=gold --with-ld=ld.gold";
/*
link executables statically against haskell libs to reduce
closure size
*/
justStaticExecutables = overrideCabal (drv: {
enableSharedExecutables = false;
enableLibraryProfiling = drv.enableExecutableProfiling or false;
isLibrary = false;
doHaddock = false;
postFixup =
drv.postFixup or ""
+ ''
# Remove every directory which could have links to other store paths.
rm -rf $out/lib $out/nix-support $out/share/doc
'';
disallowGhcReference = true;
});
/*
Build a source distribution tarball instead of using the source files
directly. The effect is that the package is built as if it were published
on hackage. This can be used as a test for the source distribution,
assuming the build fails when packaging mistakes are in the cabal file.
A faster implementation using `cabal-install` is available as
`buildFromCabalSdist` in your Haskell package set.
*/
buildFromSdist =
pkg:
overrideCabal (drv: {
src = "${sdistTarball pkg}/${pkg.pname}-${pkg.version}.tar.gz";
# Revising and jailbreaking the cabal file has been handled in sdistTarball
revision = null;
editedCabalFile = null;
jailbreak = false;
}) pkg;
/*
Build the package in a strict way to uncover potential problems.
This includes buildFromSdist and failOnAllWarnings.
*/
buildStrictly = pkg: buildFromSdist (failOnAllWarnings pkg);
# Disable core optimizations, significantly speeds up build time
disableOptimization = appendConfigureFlag "--disable-optimization";
/*
Turn on most of the compiler warnings and fail the build if any
of them occur.
*/
failOnAllWarnings = appendConfigureFlag "--ghc-option=-Wall --ghc-option=-Werror";
/*
Add a post-build check to verify that dependencies declared in
the cabal file are actually used.
The first attrset argument can be used to configure the strictness
of this check and a list of ignored package names that would otherwise
cause false alarms.
*/
checkUnusedPackages =
{
ignoreEmptyImports ? false,
ignoreMainModule ? false,
ignorePackages ? [ ],
}:
drv:
overrideCabal (_drv: {
postBuild =
let
args = lib.concatStringsSep " " (
lib.optional ignoreEmptyImports "--ignore-empty-imports"
++ lib.optional ignoreMainModule "--ignore-main-module"
++ map (pkg: "--ignore-package ${pkg}") ignorePackages
);
in
"${pkgs.haskellPackages.packunused}/bin/packunused" + lib.optionalString (args != "") " ${args}";
}) (appendConfigureFlag "--ghc-option=-ddump-minimal-imports" drv);
buildStackProject = pkgs.callPackage ../generic-stack-builder.nix { };
/*
Add a dummy command to trigger a build despite an equivalent
earlier build that is present in the store or cache.
*/
triggerRebuild =
i:
overrideCabal (drv: {
postUnpack =
drv.postUnpack or ""
+ ''
# trigger rebuild ${toString i}
'';
});
/*
Override the sources for the package and optionally the version.
This also takes of removing editedCabalFile.
*/
overrideSrc =
{
src,
version ? null,
}:
drv:
overrideCabal (_: {
inherit src;
version = if version == null then drv.version else version;
editedCabalFile = null;
}) drv;
# Get all of the build inputs of a haskell package, divided by category.
getBuildInputs = p: p.getBuildInputs;
# Extract the haskell build inputs of a haskell package.
# This is useful to build environments for developing on that
# package.
getHaskellBuildInputs = p: (getBuildInputs p).haskellBuildInputs;
# Under normal evaluation, simply return the original package. Under
# nix-shell evaluation, return a nix-shell optimized environment.
shellAware = p: if lib.inNixShell then p.env else p;
ghcInfo = ghc: rec {
isCross = (ghc.cross or null) != null;
isGhcjs = ghc.isGhcjs or false;
nativeGhc = if isCross || isGhcjs then ghc.bootPkgs.ghc else ghc;
};
### mkDerivation helpers
# These allow external users of a haskell package to extract
# information about how it is built in the same way that the
# generic haskell builder does, by reusing the same functions.
# Each function here has the same interface as mkDerivation and thus
# can be called for a given package simply by overriding the
# mkDerivation argument it used. See getHaskellBuildInputs above for
# an example of this.
# Some information about which phases should be run.
controlPhases =
ghc:
let
inherit (ghcInfo ghc) isCross;
in
{
doCheck ? !isCross,
doBenchmark ? false,
...
}:
{
inherit doCheck doBenchmark;
};
# Utility to convert a directory full of `cabal2nix`-generated files into a
# package override set
#
# packagesFromDirectory : { directory : Directory, ... } -> HaskellPackageOverrideSet
packagesFromDirectory =
{ directory, ... }:
self: super:
let
haskellPaths = lib.filter (lib.hasSuffix ".nix") (builtins.attrNames (builtins.readDir directory));
toKeyVal = file: {
name = builtins.replaceStrings [ ".nix" ] [ "" ] file;
value = self.callPackage (directory + "/${file}") { };
};
in
builtins.listToAttrs (map toKeyVal haskellPaths);
/*
INTERNAL function retained for backwards compatibility, use
haskell.packages.*.generateOptparseApplicativeCompletions instead!
*/
__generateOptparseApplicativeCompletion =
exeName:
overrideCabal (drv: {
postInstall =
(drv.postInstall or "")
+ ''
bashCompDir="''${!outputBin}/share/bash-completion/completions"
zshCompDir="''${!outputBin}/share/zsh/vendor-completions"
fishCompDir="''${!outputBin}/share/fish/vendor_completions.d"
mkdir -p "$bashCompDir" "$zshCompDir" "$fishCompDir"
"''${!outputBin}/bin/${exeName}" --bash-completion-script "''${!outputBin}/bin/${exeName}" >"$bashCompDir/${exeName}"
"''${!outputBin}/bin/${exeName}" --zsh-completion-script "''${!outputBin}/bin/${exeName}" >"$zshCompDir/_${exeName}"
"''${!outputBin}/bin/${exeName}" --fish-completion-script "''${!outputBin}/bin/${exeName}" >"$fishCompDir/${exeName}.fish"
# Sanity check
grep -F ${exeName} <$bashCompDir/${exeName} >/dev/null || {
echo 'Could not find ${exeName} in completion script.'
exit 1
}
'';
});
/*
Retained for backwards compatibility.
Use haskell.packages.*.generateOptparseApplicativeCompletions
which is cross aware instead.
*/
generateOptparseApplicativeCompletions =
commands: pkg:
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211)
"haskellLib.generateOptparseApplicativeCompletions is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions. Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
(pkgs.lib.foldr __generateOptparseApplicativeCompletion pkg commands);
/*
Retained for backwards compatibility.
Use haskell.packages.*.generateOptparseApplicativeCompletions
which is cross aware instead.
*/
generateOptparseApplicativeCompletion =
command: pkg:
lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2211)
"haskellLib.generateOptparseApplicativeCompletion is deprecated in favor of haskellPackages.generateOptparseApplicativeCompletions (plural!). Please change ${pkg.name} to use the latter and make sure it uses its matching haskell.packages set!"
(__generateOptparseApplicativeCompletion command pkg);
# Don't fail at configure time if there are multiple versions of the
# same package in the (recursive) dependencies of the package being
# built. Will delay failures, if any, to compile time.
allowInconsistentDependencies = overrideCabal (drv: {
allowInconsistentDependencies = true;
});
# Work around a Cabal bug requiring pkg-config --static --libs to work even
# when linking dynamically, affecting Cabal 3.8 and 3.9.
# https://github.com/haskell/cabal/issues/8455
#
# For this, we treat the runtime system/pkg-config dependencies of a Haskell
# derivation as if they were propagated from their dependencies which allows
# pkg-config --static to work in most cases.
#
# Warning: This function may change or be removed at any time, e.g. if we find
# a different workaround, upstream fixes the bug or we patch Cabal.
__CabalEagerPkgConfigWorkaround =
let
# Take list of derivations and return list of the transitive dependency
# closure, only taking into account buildInputs. Loosely based on
# closePropagationFast.
propagatedPlainBuildInputs =
drvs:
builtins.map (i: i.val) (
builtins.genericClosure {
startSet = builtins.map (drv: {
key = drv.outPath;
val = drv;
}) drvs;
operator =
{ val, ... }:
if !lib.isDerivation val then
[ ]
else
builtins.concatMap (
drv:
if !lib.isDerivation drv then
[ ]
else
[
{
key = drv.outPath;
val = drv;
}
]
) (val.buildInputs or [ ] ++ val.propagatedBuildInputs or [ ]);
}
);
in
overrideCabal (old: {
benchmarkPkgconfigDepends = propagatedPlainBuildInputs old.benchmarkPkgconfigDepends or [ ];
executablePkgconfigDepends = propagatedPlainBuildInputs old.executablePkgconfigDepends or [ ];
libraryPkgconfigDepends = propagatedPlainBuildInputs old.libraryPkgconfigDepends or [ ];
testPkgconfigDepends = propagatedPlainBuildInputs old.testPkgconfigDepends or [ ];
});
/*
Get the combined build inputs for a list of Haskell packages.
This combines all of the build input attributes of the packages
(`buildDepends`, `libraryHaskellDepends`, etc.) while being careful to
filter out packages from the arguments from the result.
This returns an attribute set where each key corresponds to a
`haskellPackages.mkDerivation` argument accepting a list of build inputs.
This logic is used by `haskellPackages.shellFor` to determine the packages
which are needed to build a particular set of packages.
```
> combineInputs { packages = [haskellPackages.lens haskellPackages.aeson]; }
{
buildTools = [ ];
# ...
libraryHaskellDepends = [
«derivation /nix/store/pha8fwh6lc05nm2vvg1sivhyb5nmnkic-assoc-1.1.1.drv»
«derivation /nix/store/9j5w6q1hmf50r9jydj9n7vcplknw4fvv-base-orphans-0.9.3.drv»
# ...
«derivation /nix/store/r28dlymqid6q31dh5a46k36bag60ca52-witherable-0.5.drv»
];
# ...
testHaskellDepends = [
«derivation /nix/store/rl0kfrl05z94in9f2fk8hl44r9pfyh44-HUnit-1.6.2.0.drv»
«derivation /nix/store/0dbqnww1fb3ml9f4s21phkw901yszd48-QuickCheck-2.14.3.drv»
# ...
«derivation /nix/store/0dml0xsw6s1v1d2qqhyk3qjyl4lw2fi4-vector-0.13.2.0.drv»
];
}
```
*/
combineInputs =
{
# A list of packages to get the transitive inputs for.
#
# Note that while the `packages` parameter to `haskellPackages.shellFor`
# is a function from the Haskell package set to a list of packages, this
# function takes the list of packages directly.
packages,
# Extra dependencies, in the form of `haskellPackages.mkDerivation` build
# attributes.
#
# An example use case is when you have Haskell scripts that use
# libraries that don't occur in the dependencies of `packages`.
#
# Example:
#
# extraDependencies = p: {
# libraryHaskellDepends = [ p.releaser ];
# };
extraDependencies ? { },
...
}:
let
# This is a list of attribute sets, where each attribute set
# corresponds to the build inputs of one of the packages input to shellFor.
#
# Each attribute has keys like buildDepends, executableHaskellDepends,
# testPkgconfigDepends, etc. The values for the keys of the attribute
# set are lists of dependencies.
#
# Example:
# cabalDepsForSelected
# => [
# # This may be the attribute set corresponding to the `backend`
# # package in the example above.
# { buildDepends = [ gcc ... ];
# libraryHaskellDepends = [ lens conduit ... ];
# ...
# }
# # This may be the attribute set corresponding to the `common`
# # package in the example above.
# { testHaskellDepends = [ tasty hspec ... ];
# libraryHaskellDepends = [ lens aeson ];
# benchmarkHaskellDepends = [ criterion ... ];
# ...
# }
# ...
# ]
cabalDepsForSelected = builtins.map (p: p.getCabalDeps) (builtins.filter (p: p != null) packages);
# A predicate that takes a derivation as input, and tests whether it is
# the same as any of the `packages`.
#
# Returns true if the input derivation is not in the list of `packages`.
#
# isNotSelected :: Derivation -> Bool
#
# Example:
#
# isNotSelected common [ frontend backend common ]
# => false
#
# isNotSelected lens [ frontend backend common ]
# => true
isNotSelected = input: pkgs.lib.all (p: input.outPath or null != p.outPath) packages;
# A function that takes a list of list of derivations, filters out all
# the `packages` from each list, and concats the results.
#
# zipperCombinedPkgs :: [[Derivation]] -> [Derivation]
#
# Example:
# zipperCombinedPkgs [ [ lens conduit ] [ aeson frontend ] ]
# => [ lens conduit aeson ]
#
# Note: The reason this isn't just the function `pkgs.lib.concat` is
# that we need to be careful to remove dependencies that are in the
# `packages` list.
#
# For instance, in the above example, if `common` is a dependency of
# `backend`, then zipperCombinedPkgs needs to be careful to filter out
# `common`, because cabal will end up ignoring that built version,
# assuming new-style commands.
zipperCombinedPkgs = vals: pkgs.lib.concatMap (drvList: pkgs.lib.filter isNotSelected drvList) vals;
# Zip `cabalDepsForSelected` into a single attribute list, combining
# the derivations in all the individual attributes.
#
# Example:
# packageInputs
# => # Assuming the value of cabalDepsForSelected is the same as
# # the example in cabalDepsForSelected:
# { buildDepends = [ gcc ... ];
# libraryHaskellDepends = [ lens conduit aeson ... ];
# testHaskellDepends = [ tasty hspec ... ];
# benchmarkHaskellDepends = [ criterion ... ];
# ...
# }
#
# See the Note in `zipperCombinedPkgs` for what gets filtered out from
# each of these dependency lists.
packageInputs = pkgs.lib.zipAttrsWith (_name: zipperCombinedPkgs) (
cabalDepsForSelected ++ [ extraDependencies ]
);
in
packageInputs;
}