1# TODO(@Ericson2314): Remove `pkgs` param, which is only used for
2# `buildStackProject`, `justStaticExecutables` and `checkUnusedPackages`
3{ pkgs, lib }:
4
5rec {
6 /*
7 The same functionality as this haskell.lib, except that the derivation
8 being overridden is always the last parameter. This permits more natural
9 composition of several overrides, i.e. without having to nestle one call
10 between the function name and argument of another. haskell.lib.compose is
11 preferred for any new code.
12 */
13 compose = import ./compose.nix { inherit pkgs lib; };
14
15 /*
16 This function takes a file like `hackage-packages.nix` and constructs
17 a full package set out of that.
18 */
19 makePackageSet = compose.makePackageSet;
20
21 /*
22 The function overrideCabal lets you alter the arguments to the
23 mkDerivation function.
24
25 Example:
26
27 First, note how the aeson package is constructed in hackage-packages.nix:
28
29 "aeson" = callPackage ({ mkDerivation, attoparsec, <snip>
30 }:
31 mkDerivation {
32 pname = "aeson";
33 <snip>
34 homepage = "https://github.com/bos/aeson";
35 })
36
37 The mkDerivation function of haskellPackages will take care of putting
38 the homepage in the right place, in meta.
39
40 > haskellPackages.aeson.meta.homepage
41 "https://github.com/bos/aeson"
42
43 > x = haskell.lib.overrideCabal haskellPackages.aeson (old: { homepage = old.homepage + "#readme"; })
44 > x.meta.homepage
45 "https://github.com/bos/aeson#readme"
46 */
47 overrideCabal = drv: f: compose.overrideCabal f drv;
48
49 # : Map Name (Either Path VersionNumber) -> HaskellPackageOverrideSet
50 # Given a set whose values are either paths or version strings, produces
51 # a package override set (i.e. (self: super: { etc. })) that sets
52 # the packages named in the input set to the corresponding versions
53 packageSourceOverrides = compose.packageSourceOverrides;
54
55 /*
56 doCoverage modifies a haskell package to enable the generation
57 and installation of a coverage report.
58
59 See https://wiki.haskell.org/Haskell_program_coverage
60 */
61 doCoverage = compose.doCoverage;
62
63 /*
64 dontCoverage modifies a haskell package to disable the generation
65 and installation of a coverage report.
66 */
67 dontCoverage = compose.dontCoverage;
68
69 /*
70 doHaddock modifies a haskell package to enable the generation and
71 installation of API documentation from code comments using the
72 haddock tool.
73 */
74 doHaddock = compose.doHaddock;
75
76 /*
77 dontHaddock modifies a haskell package to disable the generation and
78 installation of API documentation from code comments using the
79 haddock tool.
80 */
81 dontHaddock = compose.dontHaddock;
82
83 /*
84 doJailbreak enables the removal of version bounds from the cabal
85 file. You may want to avoid this function.
86
87 This is useful when a package reports that it can not be built
88 due to version mismatches. In some cases, removing the version
89 bounds entirely is an easy way to make a package build, but at
90 the risk of breaking software in non-obvious ways now or in the
91 future.
92
93 Instead of jailbreaking, you can patch the cabal file.
94
95 Note that jailbreaking at this time, doesn't lift bounds on
96 conditional branches.
97 https://github.com/peti/jailbreak-cabal/issues/7 has further details.
98 */
99 doJailbreak = compose.doJailbreak;
100
101 /*
102 dontJailbreak restores the use of the version bounds the check
103 the use of dependencies in the package description.
104 */
105 dontJailbreak = compose.dontJailbreak;
106
107 /*
108 doCheck enables dependency checking, compilation and execution
109 of test suites listed in the package description file.
110 */
111 doCheck = compose.doCheck;
112 /*
113 dontCheck disables dependency checking, compilation and execution
114 of test suites listed in the package description file.
115 */
116 dontCheck = compose.dontCheck;
117 /*
118 The dontCheckIf variant sets doCheck = false if the condition
119 applies. In any other case the previously set/default value is used.
120 This prevents accidentally re-enabling tests in a later override.
121 */
122 dontCheckIf = drv: condition: compose.dontCheckIf condition drv;
123
124 /*
125 doBenchmark enables dependency checking, compilation and execution
126 for benchmarks listed in the package description file.
127 */
128 doBenchmark = compose.doBenchmark;
129 /*
130 dontBenchmark disables dependency checking, compilation and execution
131 for benchmarks listed in the package description file.
132 */
133 dontBenchmark = compose.dontBenchmark;
134
135 /*
136 doDistribute enables the distribution of binaries for the package
137 via hydra.
138 */
139 doDistribute = compose.doDistribute;
140 /*
141 dontDistribute disables the distribution of binaries for the package
142 via hydra.
143 */
144 dontDistribute = compose.dontDistribute;
145
146 /*
147 appendConfigureFlag adds a single argument that will be passed to the
148 cabal configure command, after the arguments that have been defined
149 in the initial declaration or previous overrides.
150
151 Example:
152
153 > haskell.lib.appendConfigureFlag haskellPackages.servant "--profiling-detail=all-functions"
154 */
155 appendConfigureFlag = drv: x: compose.appendConfigureFlag x drv;
156 appendConfigureFlags = drv: xs: compose.appendConfigureFlags xs drv;
157
158 appendBuildFlag = drv: x: compose.appendBuildFlag x drv;
159 appendBuildFlags = drv: xs: compose.appendBuildFlags xs drv;
160
161 /*
162 removeConfigureFlag drv x is a Haskell package like drv, but with
163 all cabal configure arguments that are equal to x removed.
164
165 > haskell.lib.removeConfigureFlag haskellPackages.servant "--verbose"
166 */
167 removeConfigureFlag = drv: x: compose.removeConfigureFlag x drv;
168
169 addBuildTool = drv: x: compose.addBuildTool x drv;
170 addBuildTools = drv: xs: compose.addBuildTools xs drv;
171
172 addExtraLibrary = drv: x: compose.addExtraLibrary x drv;
173 addExtraLibraries = drv: xs: compose.addExtraLibraries xs drv;
174
175 addBuildDepend = drv: x: compose.addBuildDepend x drv;
176 addBuildDepends = drv: xs: compose.addBuildDepends xs drv;
177
178 addTestToolDepend = drv: x: compose.addTestToolDepend x drv;
179 addTestToolDepends = drv: xs: compose.addTestToolDepends xs drv;
180
181 addPkgconfigDepend = drv: x: compose.addPkgconfigDepend x drv;
182 addPkgconfigDepends = drv: xs: compose.addPkgconfigDepends xs drv;
183
184 addSetupDepend = drv: x: compose.addSetupDepend x drv;
185 addSetupDepends = drv: xs: compose.addSetupDepends xs drv;
186
187 enableCabalFlag = drv: x: compose.enableCabalFlag x drv;
188 disableCabalFlag = drv: x: compose.disableCabalFlag x drv;
189
190 markBroken = compose.markBroken;
191 unmarkBroken = compose.unmarkBroken;
192 markBrokenVersion = compose.markBrokenVersion;
193 markUnbroken = compose.markUnbroken;
194
195 disableParallelBuilding = compose.disableParallelBuilding;
196
197 enableLibraryProfiling = compose.enableLibraryProfiling;
198 disableLibraryProfiling = compose.disableLibraryProfiling;
199
200 enableExecutableProfiling = compose.enableExecutableProfiling;
201 disableExecutableProfiling = compose.disableExecutableProfiling;
202
203 enableSharedExecutables = compose.enableSharedExecutables;
204 disableSharedExecutables = compose.disableSharedExecutables;
205
206 enableSharedLibraries = compose.enableSharedLibraries;
207 disableSharedLibraries = compose.disableSharedLibraries;
208
209 enableDeadCodeElimination = compose.enableDeadCodeElimination;
210 disableDeadCodeElimination = compose.disableDeadCodeElimination;
211
212 enableStaticLibraries = compose.enableStaticLibraries;
213 disableStaticLibraries = compose.disableStaticLibraries;
214
215 enableSeparateBinOutput = compose.enableSeparateBinOutput;
216
217 appendPatch = drv: x: compose.appendPatch x drv;
218 appendPatches = drv: xs: compose.appendPatches xs drv;
219
220 /*
221 Set a specific build target instead of compiling all targets in the package.
222 For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server".
223 We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows:
224
225 setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server"
226 */
227 setBuildTargets = drv: xs: compose.setBuildTargets xs drv;
228 setBuildTarget = drv: x: compose.setBuildTarget x drv;
229
230 doHyperlinkSource = compose.doHyperlinkSource;
231 dontHyperlinkSource = compose.dontHyperlinkSource;
232
233 disableHardening = drv: flags: compose.disableHardening flags drv;
234
235 /*
236 Let Nix strip the binary files.
237 This removes debugging symbols.
238 */
239 doStrip = compose.doStrip;
240
241 /*
242 Stop Nix from stripping the binary files.
243 This keeps debugging symbols.
244 */
245 dontStrip = compose.dontStrip;
246
247 /*
248 Useful for debugging segfaults with gdb.
249 This includes dontStrip.
250 */
251 enableDWARFDebugging = compose.enableDWARFDebugging;
252
253 /*
254 Create a source distribution tarball like those found on hackage,
255 instead of building the package.
256 */
257 sdistTarball = compose.sdistTarball;
258
259 /*
260 Create a documentation tarball suitable for uploading to Hackage instead
261 of building the package.
262 */
263 documentationTarball = compose.documentationTarball;
264
265 /*
266 Use the gold linker. It is a linker for ELF that is designed
267 "to run as fast as possible on modern systems"
268 */
269 linkWithGold = compose.linkWithGold;
270
271 /*
272 link executables statically against haskell libs to reduce
273 closure size
274 */
275 justStaticExecutables = compose.justStaticExecutables;
276
277 /*
278 Build a source distribution tarball instead of using the source files
279 directly. The effect is that the package is built as if it were published
280 on hackage. This can be used as a test for the source distribution,
281 assuming the build fails when packaging mistakes are in the cabal file.
282 */
283 buildFromSdist = compose.buildFromSdist;
284
285 /*
286 Build the package in a strict way to uncover potential problems.
287 This includes buildFromSdist and failOnAllWarnings.
288 */
289 buildStrictly = compose.buildStrictly;
290
291 # Disable core optimizations, significantly speeds up build time
292 disableOptimization = compose.disableOptimization;
293
294 /*
295 Turn on most of the compiler warnings and fail the build if any
296 of them occur.
297 */
298 failOnAllWarnings = compose.failOnAllWarnings;
299
300 /*
301 Add a post-build check to verify that dependencies declared in
302 the cabal file are actually used.
303
304 The first attrset argument can be used to configure the strictness
305 of this check and a list of ignored package names that would otherwise
306 cause false alarms.
307 */
308 checkUnusedPackages = compose.checkUnusedPackages;
309
310 buildStackProject = compose.buildStackProject;
311
312 /*
313 Add a dummy command to trigger a build despite an equivalent
314 earlier build that is present in the store or cache.
315 */
316 triggerRebuild = drv: i: compose.triggerRebuild i drv;
317
318 /*
319 Override the sources for the package and optionally the version.
320 This also takes of removing editedCabalFile.
321 */
322 overrideSrc = drv: src: compose.overrideSrc src drv;
323
324 # Get all of the build inputs of a haskell package, divided by category.
325 getBuildInputs = compose.getBuildInputs;
326
327 # Extract the haskell build inputs of a haskell package.
328 # This is useful to build environments for developing on that
329 # package.
330 getHaskellBuildInputs = compose.getHaskellBuildInputs;
331
332 # Under normal evaluation, simply return the original package. Under
333 # nix-shell evaluation, return a nix-shell optimized environment.
334 shellAware = compose.shellAware;
335
336 # Utility to convert a directory full of `cabal2nix`-generated files into a
337 # package override set
338 #
339 # packagesFromDirectory : { directory : Directory, ... } -> HaskellPackageOverrideSet
340 packagesFromDirectory = compose.packagesFromDirectory;
341
342 addOptparseApplicativeCompletionScripts =
343 exeName: pkg:
344 lib.warn "addOptparseApplicativeCompletionScripts 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!" (
345 compose.__generateOptparseApplicativeCompletion exeName pkg
346 );
347
348 /*
349 Modify a Haskell package to add shell completion scripts for the
350 given executable produced by it. These completion scripts will be
351 picked up automatically if the resulting derivation is installed,
352 e.g. by `nix-env -i`.
353
354 Invocation:
355 generateOptparseApplicativeCompletions command pkg
356
357 command: name of an executable
358 pkg: Haskell package that builds the executables
359 */
360 generateOptparseApplicativeCompletion = compose.generateOptparseApplicativeCompletion;
361
362 /*
363 Modify a Haskell package to add shell completion scripts for the
364 given executables produced by it. These completion scripts will be
365 picked up automatically if the resulting derivation is installed,
366 e.g. by `nix-env -i`.
367
368 Invocation:
369 generateOptparseApplicativeCompletions commands pkg
370
371 commands: name of an executable
372 pkg: Haskell package that builds the executables
373 */
374 generateOptparseApplicativeCompletions = compose.generateOptparseApplicativeCompletions;
375
376 # Don't fail at configure time if there are multiple versions of the
377 # same package in the (recursive) dependencies of the package being
378 # built. Will delay failures, if any, to compile time.
379 allowInconsistentDependencies = compose.allowInconsistentDependencies;
380}