1 # TODO(@Ericson2314): Remove `pkgs` param, which is only used for
2 # `buildStackProject`, `justStaticExecutables` and `checkUnusedPackages`
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.
12 compose = import ./compose.nix { inherit pkgs lib; };
14 /* This function takes a file like `hackage-packages.nix` and constructs
15 a full package set out of that.
17 makePackageSet = compose.makePackageSet;
19 /* The function overrideCabal lets you alter the arguments to the
20 mkDerivation function.
24 First, note how the aeson package is constructed in hackage-packages.nix:
26 "aeson" = callPackage ({ mkDerivation, attoparsec, <snip>
31 homepage = "https://github.com/bos/aeson";
34 The mkDerivation function of haskellPackages will take care of putting
35 the homepage in the right place, in meta.
37 > haskellPackages.aeson.meta.homepage
38 "https://github.com/bos/aeson"
40 > x = haskell.lib.overrideCabal haskellPackages.aeson (old: { homepage = old.homepage + "#readme"; })
42 "https://github.com/bos/aeson#readme"
45 overrideCabal = drv: f: compose.overrideCabal f drv;
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;
53 /* doCoverage modifies a haskell package to enable the generation
54 and installation of a coverage report.
56 See https://wiki.haskell.org/Haskell_program_coverage
58 doCoverage = compose.doCoverage;
60 /* dontCoverage modifies a haskell package to disable the generation
61 and installation of a coverage report.
63 dontCoverage = compose.dontCoverage;
65 /* doHaddock modifies a haskell package to enable the generation and
66 installation of API documentation from code comments using the
69 doHaddock = compose.doHaddock;
71 /* dontHaddock modifies a haskell package to disable the generation and
72 installation of API documentation from code comments using the
75 dontHaddock = compose.dontHaddock;
77 /* doJailbreak enables the removal of version bounds from the cabal
78 file. You may want to avoid this function.
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
86 Instead of jailbreaking, you can patch the cabal file.
88 Note that jailbreaking at this time, doesn't lift bounds on
90 https://github.com/peti/jailbreak-cabal/issues/7 has further details.
93 doJailbreak = compose.doJailbreak;
95 /* dontJailbreak restores the use of the version bounds the check
96 the use of dependencies in the package description.
98 dontJailbreak = compose.dontJailbreak;
100 /* doCheck enables dependency checking, compilation and execution
101 of test suites listed in the package description file.
103 doCheck = compose.doCheck;
104 /* dontCheck disables dependency checking, compilation and execution
105 of test suites listed in the package description file.
107 dontCheck = compose.dontCheck;
108 /* The dontCheckIf variant sets doCheck = false if the condition
109 applies. In any other case the previously set/default value is used.
110 This prevents accidentally re-enabling tests in a later override.
112 dontCheckIf = drv: condition: compose.dontCheckIf condition drv;
114 /* doBenchmark enables dependency checking, compilation and execution
115 for benchmarks listed in the package description file.
117 doBenchmark = compose.doBenchmark;
118 /* dontBenchmark disables dependency checking, compilation and execution
119 for benchmarks listed in the package description file.
121 dontBenchmark = compose.dontBenchmark;
123 /* doDistribute enables the distribution of binaries for the package
126 doDistribute = compose.doDistribute;
127 /* dontDistribute disables the distribution of binaries for the package
130 dontDistribute = compose.dontDistribute;
132 /* appendConfigureFlag adds a single argument that will be passed to the
133 cabal configure command, after the arguments that have been defined
134 in the initial declaration or previous overrides.
138 > haskell.lib.appendConfigureFlag haskellPackages.servant "--profiling-detail=all-functions"
140 appendConfigureFlag = drv: x: compose.appendConfigureFlag x drv;
141 appendConfigureFlags = drv: xs: compose.appendConfigureFlags xs drv;
143 appendBuildFlag = drv: x: compose.appendBuildFlag x drv;
144 appendBuildFlags = drv: xs: compose.appendBuildFlags xs drv;
146 /* removeConfigureFlag drv x is a Haskell package like drv, but with
147 all cabal configure arguments that are equal to x removed.
149 > haskell.lib.removeConfigureFlag haskellPackages.servant "--verbose"
151 removeConfigureFlag = drv: x: compose.removeConfigureFlag x drv;
153 addBuildTool = drv: x: compose.addBuildTool x drv;
154 addBuildTools = drv: xs: compose.addBuildTools xs drv;
156 addExtraLibrary = drv: x: compose.addExtraLibrary x drv;
157 addExtraLibraries = drv: xs: compose.addExtraLibraries xs drv;
159 addBuildDepend = drv: x: compose.addBuildDepend x drv;
160 addBuildDepends = drv: xs: compose.addBuildDepends xs drv;
162 addTestToolDepend = drv: x: compose.addTestToolDepend x drv;
163 addTestToolDepends = drv: xs: compose.addTestToolDepends xs drv;
165 addPkgconfigDepend = drv: x: compose.addPkgconfigDepend x drv;
166 addPkgconfigDepends = drv: xs: compose.addPkgconfigDepends xs drv;
168 addSetupDepend = drv: x: compose.addSetupDepend x drv;
169 addSetupDepends = drv: xs: compose.addSetupDepends xs drv;
171 enableCabalFlag = drv: x: compose.enableCabalFlag x drv;
172 disableCabalFlag = drv: x: compose.disableCabalFlag x drv;
174 markBroken = compose.markBroken;
175 unmarkBroken = compose.unmarkBroken;
176 markBrokenVersion = compose.markBrokenVersion;
177 markUnbroken = compose.markUnbroken;
179 disableParallelBuilding = compose.disableParallelBuilding;
181 enableLibraryProfiling = compose.enableLibraryProfiling;
182 disableLibraryProfiling = compose.disableLibraryProfiling;
184 enableExecutableProfiling = compose.enableExecutableProfiling;
185 disableExecutableProfiling = compose.disableExecutableProfiling;
187 enableSharedExecutables = compose.enableSharedExecutables;
188 disableSharedExecutables = compose.disableSharedExecutables;
190 enableSharedLibraries = compose.enableSharedLibraries;
191 disableSharedLibraries = compose.disableSharedLibraries;
193 enableDeadCodeElimination = compose.enableDeadCodeElimination;
194 disableDeadCodeElimination = compose.disableDeadCodeElimination;
196 enableStaticLibraries = compose.enableStaticLibraries;
197 disableStaticLibraries = compose.disableStaticLibraries;
199 enableSeparateBinOutput = compose.enableSeparateBinOutput;
201 appendPatch = drv: x: compose.appendPatch x drv;
202 appendPatches = drv: xs: compose.appendPatches xs drv;
204 /* Set a specific build target instead of compiling all targets in the package.
205 * For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server".
206 * We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows:
208 * setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server"
211 setBuildTargets = drv: xs: compose.setBuildTargets xs drv;
212 setBuildTarget = drv: x: compose.setBuildTarget x drv;
214 doHyperlinkSource = compose.doHyperlinkSource;
215 dontHyperlinkSource = compose.dontHyperlinkSource;
217 disableHardening = drv: flags: compose.disableHardening flags drv;
219 /* Let Nix strip the binary files.
220 * This removes debugging symbols.
222 doStrip = compose.doStrip;
224 /* Stop Nix from stripping the binary files.
225 * This keeps debugging symbols.
227 dontStrip = compose.dontStrip;
229 /* Useful for debugging segfaults with gdb.
230 * This includes dontStrip.
232 enableDWARFDebugging = compose.enableDWARFDebugging;
234 /* Create a source distribution tarball like those found on hackage,
235 instead of building the package.
237 sdistTarball = compose.sdistTarball;
239 /* Create a documentation tarball suitable for uploading to Hackage instead
240 of building the package.
242 documentationTarball = compose.documentationTarball;
244 /* Use the gold linker. It is a linker for ELF that is designed
245 "to run as fast as possible on modern systems"
247 linkWithGold = compose.linkWithGold;
249 /* link executables statically against haskell libs to reduce
252 justStaticExecutables = compose.justStaticExecutables;
254 /* Build a source distribution tarball instead of using the source files
255 directly. The effect is that the package is built as if it were published
256 on hackage. This can be used as a test for the source distribution,
257 assuming the build fails when packaging mistakes are in the cabal file.
259 buildFromSdist = compose.buildFromSdist;
261 /* Build the package in a strict way to uncover potential problems.
262 This includes buildFromSdist and failOnAllWarnings.
264 buildStrictly = compose.buildStrictly;
266 /* Disable core optimizations, significantly speeds up build time */
267 disableOptimization = compose.disableOptimization;
269 /* Turn on most of the compiler warnings and fail the build if any
271 failOnAllWarnings = compose.failOnAllWarnings;
273 /* Add a post-build check to verify that dependencies declared in
274 the cabal file are actually used.
276 The first attrset argument can be used to configure the strictness
277 of this check and a list of ignored package names that would otherwise
280 checkUnusedPackages = compose.checkUnusedPackages;
282 buildStackProject = compose.buildStackProject;
284 /* Add a dummy command to trigger a build despite an equivalent
285 earlier build that is present in the store or cache.
287 triggerRebuild = drv: i: compose.triggerRebuild i drv;
289 /* Override the sources for the package and optionally the version.
290 This also takes of removing editedCabalFile.
292 overrideSrc = drv: src: compose.overrideSrc src drv;
294 # Get all of the build inputs of a haskell package, divided by category.
295 getBuildInputs = compose.getBuildInputs;
297 # Extract the haskell build inputs of a haskell package.
298 # This is useful to build environments for developing on that
300 getHaskellBuildInputs = compose.getHaskellBuildInputs;
302 # Under normal evaluation, simply return the original package. Under
303 # nix-shell evaluation, return a nix-shell optimized environment.
304 shellAware = compose.shellAware;
306 ghcInfo = compose.ghcInfo;
308 ### mkDerivation helpers
309 # These allow external users of a haskell package to extract
310 # information about how it is built in the same way that the
311 # generic haskell builder does, by reusing the same functions.
312 # Each function here has the same interface as mkDerivation and thus
313 # can be called for a given package simply by overriding the
314 # mkDerivation argument it used. See getHaskellBuildInputs above for
315 # an example of this.
317 # Some information about which phases should be run.
318 controlPhases = compose.controlPhases;
320 # Utility to convert a directory full of `cabal2nix`-generated files into a
321 # package override set
323 # packagesFromDirectory : { directory : Directory, ... } -> HaskellPackageOverrideSet
324 packagesFromDirectory = compose.packagesFromDirectory;
326 addOptparseApplicativeCompletionScripts = exeName: pkg:
327 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!"
328 (compose.__generateOptparseApplicativeCompletion exeName pkg);
331 Modify a Haskell package to add shell completion scripts for the
332 given executable produced by it. These completion scripts will be
333 picked up automatically if the resulting derivation is installed,
334 e.g. by `nix-env -i`.
337 generateOptparseApplicativeCompletions command pkg
340 command: name of an executable
341 pkg: Haskell package that builds the executables
343 generateOptparseApplicativeCompletion = compose.generateOptparseApplicativeCompletion;
346 Modify a Haskell package to add shell completion scripts for the
347 given executables produced by it. These completion scripts will be
348 picked up automatically if the resulting derivation is installed,
349 e.g. by `nix-env -i`.
352 generateOptparseApplicativeCompletions commands pkg
355 commands: name of an executable
356 pkg: Haskell package that builds the executables
358 generateOptparseApplicativeCompletions = compose.generateOptparseApplicativeCompletions;
360 # Don't fail at configure time if there are multiple versions of the
361 # same package in the (recursive) dependencies of the package being
362 # built. Will delay failures, if any, to compile time.
363 allowInconsistentDependencies = compose.allowInconsistentDependencies;