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