Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 24.05-beta 362 lines 14 kB view raw
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 /* 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. 111 */ 112 dontCheckIf = drv: condition: compose.dontCheckIf condition drv; 113 114 /* doBenchmark enables dependency checking, compilation and execution 115 for benchmarks listed in the package description file. 116 */ 117 doBenchmark = compose.doBenchmark; 118 /* dontBenchmark disables dependency checking, compilation and execution 119 for benchmarks listed in the package description file. 120 */ 121 dontBenchmark = compose.dontBenchmark; 122 123 /* doDistribute enables the distribution of binaries for the package 124 via hydra. 125 */ 126 doDistribute = compose.doDistribute; 127 /* dontDistribute disables the distribution of binaries for the package 128 via hydra. 129 */ 130 dontDistribute = compose.dontDistribute; 131 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. 135 136 Example: 137 138 > haskell.lib.appendConfigureFlag haskellPackages.servant "--profiling-detail=all-functions" 139 */ 140 appendConfigureFlag = drv: x: compose.appendConfigureFlag x drv; 141 appendConfigureFlags = drv: xs: compose.appendConfigureFlags xs drv; 142 143 appendBuildFlag = drv: x: compose.appendBuildFlag x drv; 144 appendBuildFlags = drv: xs: compose.appendBuildFlags xs drv; 145 146 /* removeConfigureFlag drv x is a Haskell package like drv, but with 147 all cabal configure arguments that are equal to x removed. 148 149 > haskell.lib.removeConfigureFlag haskellPackages.servant "--verbose" 150 */ 151 removeConfigureFlag = drv: x: compose.removeConfigureFlag x drv; 152 153 addBuildTool = drv: x: compose.addBuildTool x drv; 154 addBuildTools = drv: xs: compose.addBuildTools xs drv; 155 156 addExtraLibrary = drv: x: compose.addExtraLibrary x drv; 157 addExtraLibraries = drv: xs: compose.addExtraLibraries xs drv; 158 159 addBuildDepend = drv: x: compose.addBuildDepend x drv; 160 addBuildDepends = drv: xs: compose.addBuildDepends xs drv; 161 162 addTestToolDepend = drv: x: compose.addTestToolDepend x drv; 163 addTestToolDepends = drv: xs: compose.addTestToolDepends xs drv; 164 165 addPkgconfigDepend = drv: x: compose.addPkgconfigDepend x drv; 166 addPkgconfigDepends = drv: xs: compose.addPkgconfigDepends xs drv; 167 168 addSetupDepend = drv: x: compose.addSetupDepend x drv; 169 addSetupDepends = drv: xs: compose.addSetupDepends xs drv; 170 171 enableCabalFlag = drv: x: compose.enableCabalFlag x drv; 172 disableCabalFlag = drv: x: compose.disableCabalFlag x drv; 173 174 markBroken = compose.markBroken; 175 unmarkBroken = compose.unmarkBroken; 176 markBrokenVersion = compose.markBrokenVersion; 177 markUnbroken = compose.markUnbroken; 178 179 enableLibraryProfiling = compose.enableLibraryProfiling; 180 disableLibraryProfiling = compose.disableLibraryProfiling; 181 182 enableExecutableProfiling = compose.enableExecutableProfiling; 183 disableExecutableProfiling = compose.disableExecutableProfiling; 184 185 enableSharedExecutables = compose.enableSharedExecutables; 186 disableSharedExecutables = compose.disableSharedExecutables; 187 188 enableSharedLibraries = compose.enableSharedLibraries; 189 disableSharedLibraries = compose.disableSharedLibraries; 190 191 enableDeadCodeElimination = compose.enableDeadCodeElimination; 192 disableDeadCodeElimination = compose.disableDeadCodeElimination; 193 194 enableStaticLibraries = compose.enableStaticLibraries; 195 disableStaticLibraries = compose.disableStaticLibraries; 196 197 enableSeparateBinOutput = compose.enableSeparateBinOutput; 198 199 appendPatch = drv: x: compose.appendPatch x drv; 200 appendPatches = drv: xs: compose.appendPatches xs drv; 201 202 /* Set a specific build target instead of compiling all targets in the package. 203 * For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server". 204 * We can build only "server" and not wait on the compilation of "dev" by using setBuildTarget as follows: 205 * 206 * setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server" 207 * 208 */ 209 setBuildTargets = drv: xs: compose.setBuildTargets xs drv; 210 setBuildTarget = drv: x: compose.setBuildTarget x drv; 211 212 doHyperlinkSource = compose.doHyperlinkSource; 213 dontHyperlinkSource = compose.dontHyperlinkSource; 214 215 disableHardening = drv: flags: compose.disableHardening flags drv; 216 217 /* Let Nix strip the binary files. 218 * This removes debugging symbols. 219 */ 220 doStrip = compose.doStrip; 221 222 /* Stop Nix from stripping the binary files. 223 * This keeps debugging symbols. 224 */ 225 dontStrip = compose.dontStrip; 226 227 /* Useful for debugging segfaults with gdb. 228 * This includes dontStrip. 229 */ 230 enableDWARFDebugging = compose.enableDWARFDebugging; 231 232 /* Create a source distribution tarball like those found on hackage, 233 instead of building the package. 234 */ 235 sdistTarball = compose.sdistTarball; 236 237 /* Create a documentation tarball suitable for uploading to Hackage instead 238 of building the package. 239 */ 240 documentationTarball = compose.documentationTarball; 241 242 /* Use the gold linker. It is a linker for ELF that is designed 243 "to run as fast as possible on modern systems" 244 */ 245 linkWithGold = compose.linkWithGold; 246 247 /* link executables statically against haskell libs to reduce 248 closure size 249 */ 250 justStaticExecutables = compose.justStaticExecutables; 251 252 /* Build a source distribution tarball instead of using the source files 253 directly. The effect is that the package is built as if it were published 254 on hackage. This can be used as a test for the source distribution, 255 assuming the build fails when packaging mistakes are in the cabal file. 256 */ 257 buildFromSdist = compose.buildFromSdist; 258 259 /* Build the package in a strict way to uncover potential problems. 260 This includes buildFromSdist and failOnAllWarnings. 261 */ 262 buildStrictly = compose.buildStrictly; 263 264 /* Disable core optimizations, significantly speeds up build time */ 265 disableOptimization = compose.disableOptimization; 266 267 /* Turn on most of the compiler warnings and fail the build if any 268 of them occur. */ 269 failOnAllWarnings = compose.failOnAllWarnings; 270 271 /* Add a post-build check to verify that dependencies declared in 272 the cabal file are actually used. 273 274 The first attrset argument can be used to configure the strictness 275 of this check and a list of ignored package names that would otherwise 276 cause false alarms. 277 */ 278 checkUnusedPackages = compose.checkUnusedPackages; 279 280 buildStackProject = compose.buildStackProject; 281 282 /* Add a dummy command to trigger a build despite an equivalent 283 earlier build that is present in the store or cache. 284 */ 285 triggerRebuild = drv: i: compose.triggerRebuild i drv; 286 287 /* Override the sources for the package and optionally the version. 288 This also takes of removing editedCabalFile. 289 */ 290 overrideSrc = drv: src: compose.overrideSrc src drv; 291 292 # Get all of the build inputs of a haskell package, divided by category. 293 getBuildInputs = compose.getBuildInputs; 294 295 # Extract the haskell build inputs of a haskell package. 296 # This is useful to build environments for developing on that 297 # package. 298 getHaskellBuildInputs = compose.getHaskellBuildInputs; 299 300 # Under normal evaluation, simply return the original package. Under 301 # nix-shell evaluation, return a nix-shell optimized environment. 302 shellAware = compose.shellAware; 303 304 ghcInfo = compose.ghcInfo; 305 306 ### mkDerivation helpers 307 # These allow external users of a haskell package to extract 308 # information about how it is built in the same way that the 309 # generic haskell builder does, by reusing the same functions. 310 # Each function here has the same interface as mkDerivation and thus 311 # can be called for a given package simply by overriding the 312 # mkDerivation argument it used. See getHaskellBuildInputs above for 313 # an example of this. 314 315 # Some information about which phases should be run. 316 controlPhases = compose.controlPhases; 317 318 # Utility to convert a directory full of `cabal2nix`-generated files into a 319 # package override set 320 # 321 # packagesFromDirectory : { directory : Directory, ... } -> HaskellPackageOverrideSet 322 packagesFromDirectory = compose.packagesFromDirectory; 323 324 addOptparseApplicativeCompletionScripts = exeName: pkg: 325 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!" 326 (compose.__generateOptparseApplicativeCompletion exeName pkg); 327 328 /* 329 Modify a Haskell package to add shell completion scripts for the 330 given executable produced by it. These completion scripts will be 331 picked up automatically if the resulting derivation is installed, 332 e.g. by `nix-env -i`. 333 334 Invocation: 335 generateOptparseApplicativeCompletions command pkg 336 337 338 command: name of an executable 339 pkg: Haskell package that builds the executables 340 */ 341 generateOptparseApplicativeCompletion = compose.generateOptparseApplicativeCompletion; 342 343 /* 344 Modify a Haskell package to add shell completion scripts for the 345 given executables produced by it. These completion scripts will be 346 picked up automatically if the resulting derivation is installed, 347 e.g. by `nix-env -i`. 348 349 Invocation: 350 generateOptparseApplicativeCompletions commands pkg 351 352 353 commands: name of an executable 354 pkg: Haskell package that builds the executables 355 */ 356 generateOptparseApplicativeCompletions = compose.generateOptparseApplicativeCompletions; 357 358 # Don't fail at configure time if there are multiple versions of the 359 # same package in the (recursive) dependencies of the package being 360 # built. Will delay failures, if any, to compile time. 361 allowInconsistentDependencies = compose.allowInconsistentDependencies; 362}