Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05-pre 703 lines 30 kB view raw
1{ lib, stdenv, buildPackages, buildHaskellPackages, ghc 2, jailbreak-cabal, hscolour, cpphs, nodejs 3, ghcWithHoogle, ghcWithPackages 4}: 5 6let 7 isCross = stdenv.buildPlatform != stdenv.hostPlatform; 8 inherit (buildPackages) 9 fetchurl removeReferencesTo 10 pkg-config coreutils gnugrep gnused glibcLocales; 11in 12 13{ pname 14, dontStrip ? (ghc.isGhcjs or false) 15, version, revision ? null 16, sha256 ? null 17, src ? fetchurl { url = "mirror://hackage/${pname}-${version}.tar.gz"; inherit sha256; } 18, buildDepends ? [], setupHaskellDepends ? [], libraryHaskellDepends ? [], executableHaskellDepends ? [] 19, buildTarget ? "" 20, buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? [] 21, configureFlags ? [] 22, buildFlags ? [] 23, haddockFlags ? [] 24, description ? null 25, doCheck ? !isCross && lib.versionOlder "7.4" ghc.version 26, doBenchmark ? false 27, doHoogle ? true 28, doHaddockQuickjump ? doHoogle && lib.versionAtLeast ghc.version "8.6" 29, editedCabalFile ? null 30# aarch64 outputs otherwise exceed 2GB limit 31, enableLibraryProfiling ? !(ghc.isGhcjs or stdenv.targetPlatform.isAarch64 or false) 32, enableExecutableProfiling ? false 33, profilingDetail ? "exported-functions" 34# TODO enable shared libs for cross-compiling 35, enableSharedExecutables ? false 36, enableSharedLibraries ? !stdenv.hostPlatform.isStatic && (ghc.enableShared or false) 37, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin 38, enableStaticLibraries ? !(stdenv.hostPlatform.isWindows or stdenv.hostPlatform.isWasm) 39, enableHsc2hsViaAsm ? stdenv.hostPlatform.isWindows && lib.versionAtLeast ghc.version "8.4" 40, extraLibraries ? [], librarySystemDepends ? [], executableSystemDepends ? [] 41# On macOS, statically linking against system frameworks is not supported; 42# see https://developer.apple.com/library/content/qa/qa1118/_index.html 43# They must be propagated to the environment of any executable linking with the library 44, libraryFrameworkDepends ? [], executableFrameworkDepends ? [] 45, homepage ? "https://hackage.haskell.org/package/${pname}" 46, platforms ? with lib.platforms; all # GHC can cross-compile 47, badPlatforms ? lib.platforms.none 48, hydraPlatforms ? null 49, hyperlinkSource ? true 50, isExecutable ? false, isLibrary ? !isExecutable 51, jailbreak ? false 52, license 53, enableParallelBuilding ? true 54, maintainers ? null 55, changelog ? null 56, mainProgram ? null 57, doCoverage ? false 58, doHaddock ? !(ghc.isHaLVM or false) 59, doHaddockInterfaces ? doHaddock && lib.versionAtLeast ghc.version "9.0.1" 60, passthru ? {} 61, pkg-configDepends ? [], libraryPkgconfigDepends ? [], executablePkgconfigDepends ? [], testPkgconfigDepends ? [], benchmarkPkgconfigDepends ? [] 62, testDepends ? [], testHaskellDepends ? [], testSystemDepends ? [], testFrameworkDepends ? [] 63, benchmarkDepends ? [], benchmarkHaskellDepends ? [], benchmarkSystemDepends ? [], benchmarkFrameworkDepends ? [] 64, testTarget ? "", testFlags ? [] 65, broken ? false 66, preCompileBuildDriver ? null, postCompileBuildDriver ? null 67, preUnpack ? null, postUnpack ? null 68, patches ? null, patchPhase ? null, prePatch ? "", postPatch ? "" 69, preConfigure ? null, postConfigure ? null 70, preBuild ? null, postBuild ? null 71, preHaddock ? null, postHaddock ? null 72, installPhase ? null, preInstall ? null, postInstall ? null 73, checkPhase ? null, preCheck ? null, postCheck ? null 74, preFixup ? null, postFixup ? null 75, shellHook ? "" 76, coreSetup ? false # Use only core packages to build Setup.hs. 77, useCpphs ? false 78, hardeningDisable ? null 79, enableSeparateBinOutput ? false 80, enableSeparateDataOutput ? false 81, enableSeparateDocOutput ? doHaddock 82, # Don't fail at configure time if there are multiple versions of the 83 # same package in the (recursive) dependencies of the package being 84 # built. Will delay failures, if any, to compile time. 85 allowInconsistentDependencies ? false 86, maxBuildCores ? 16 # more cores usually don't improve performance: https://ghc.haskell.org/trac/ghc/ticket/9221 87, # If set to true, this builds a pre-linked .o file for this Haskell library. 88 # This can make it slightly faster to load this library into GHCi, but takes 89 # extra disk space and compile time. 90 enableLibraryForGhci ? false 91} @ args: 92 93assert editedCabalFile != null -> revision != null; 94 95# --enable-static does not work on windows. This is a bug in GHC. 96# --enable-static will pass -staticlib to ghc, which only works for mach-o and elf. 97assert stdenv.hostPlatform.isWindows -> enableStaticLibraries == false; 98assert stdenv.hostPlatform.isWasm -> enableStaticLibraries == false; 99 100let 101 102 inherit (lib) optional optionals optionalString versionOlder versionAtLeast 103 concatStringsSep enableFeature optionalAttrs; 104 105 isGhcjs = ghc.isGhcjs or false; 106 isHaLVM = ghc.isHaLVM or false; 107 packageDbFlag = if isGhcjs || isHaLVM || versionOlder "7.6" ghc.version 108 then "package-db" 109 else "package-conf"; 110 111 # GHC used for building Setup.hs 112 # 113 # Same as our GHC, unless we're cross, in which case it is native GHC with the 114 # same version, or ghcjs, in which case its the ghc used to build ghcjs. 115 nativeGhc = buildHaskellPackages.ghc; 116 nativePackageDbFlag = if versionOlder "7.6" nativeGhc.version 117 then "package-db" 118 else "package-conf"; 119 120 # the target dir for haddock documentation 121 docdir = docoutput: docoutput + "/share/doc/" + pname + "-" + version; 122 123 binDir = if enableSeparateBinOutput then "$bin/bin" else "$out/bin"; 124 125 newCabalFileUrl = "mirror://hackage/${pname}-${version}/revision/${revision}.cabal"; 126 newCabalFile = fetchurl { 127 url = newCabalFileUrl; 128 sha256 = editedCabalFile; 129 name = "${pname}-${version}-r${revision}.cabal"; 130 }; 131 132 defaultSetupHs = builtins.toFile "Setup.hs" '' 133 import Distribution.Simple 134 main = defaultMain 135 ''; 136 137 # This awk expression transforms a package conf file like 138 # 139 # author: John Doe <john-doe@example.com> 140 # description: 141 # The purpose of this library is to do 142 # foo and bar among other things 143 # 144 # into a more easily processeable form: 145 # 146 # author: John Doe <john-doe@example.com> 147 # description: The purpose of this library is to do foo and bar among other things 148 unprettyConf = builtins.toFile "unpretty-cabal-conf.awk" '' 149 /^[^ ]+:/ { 150 # When the line starts with a new field, terminate the previous one with a newline 151 if (started == 1) print "" 152 # to strip leading spaces 153 $1=$1 154 printf "%s", $0 155 started=1 156 } 157 158 /^ +/ { 159 # to strip leading spaces 160 $1=$1 161 printf " %s", $0 162 } 163 164 # Terminate the final field with a newline 165 END { print "" } 166 ''; 167 168 crossCabalFlags = [ 169 "--with-ghc=${ghcCommand}" 170 "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg" 171 # Pass the "wrong" C compiler rather than none at all so packages that just 172 # use the C preproccessor still work, see 173 # https://github.com/haskell/cabal/issues/6466 for details. 174 "--with-gcc=${(if stdenv.hasCC then stdenv else buildPackages.stdenv).cc.targetPrefix}cc" 175 ] ++ optionals stdenv.hasCC [ 176 "--with-ld=${stdenv.cc.bintools.targetPrefix}ld" 177 "--with-ar=${stdenv.cc.bintools.targetPrefix}ar" 178 # use the one that comes with the cross compiler. 179 "--with-hsc2hs=${ghc.targetPrefix}hsc2hs" 180 "--with-strip=${stdenv.cc.bintools.targetPrefix}strip" 181 ] ++ optionals (!isHaLVM) [ 182 "--hsc2hs-option=--cross-compile" 183 (optionalString enableHsc2hsViaAsm "--hsc2hs-option=--via-asm") 184 ]; 185 186 parallelBuildingFlags = "-j$NIX_BUILD_CORES" + optionalString stdenv.isLinux " +RTS -A64M -RTS"; 187 188 crossCabalFlagsString = 189 lib.optionalString isCross (" " + lib.concatStringsSep " " crossCabalFlags); 190 191 buildFlagsString = optionalString (buildFlags != []) (" " + concatStringsSep " " buildFlags); 192 193 defaultConfigureFlags = [ 194 "--verbose" 195 "--prefix=$out" 196 "--libdir=\\$prefix/lib/\\$compiler" 197 "--libsubdir=\\$abi/\\$libname" 198 (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}") 199 (optionalString enableSeparateDocOutput "--docdir=${docdir "$doc"}") 200 ] ++ optionals stdenv.hasCC [ 201 "--with-gcc=$CC" # Clang won't work without that extra information. 202 ] ++ [ 203 "--package-db=$packageConfDir" 204 (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}") 205 (optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names") 206 (optionalString enableParallelBuilding "--ghc-options=${parallelBuildingFlags}") 207 (optionalString useCpphs "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp") 208 (enableFeature (enableDeadCodeElimination && !stdenv.hostPlatform.isAarch32 && !stdenv.hostPlatform.isAarch64 && (versionAtLeast "8.0.1" ghc.version)) "split-objs") 209 (enableFeature enableLibraryProfiling "library-profiling") 210 (optionalString ((enableExecutableProfiling || enableLibraryProfiling) && versionOlder "8" ghc.version) "--profiling-detail=${profilingDetail}") 211 (enableFeature enableExecutableProfiling (if versionOlder ghc.version "8" then "executable-profiling" else "profiling")) 212 (enableFeature enableSharedLibraries "shared") 213 (optionalString (versionAtLeast ghc.version "7.10") (enableFeature doCoverage "coverage")) 214 (optionalString (versionOlder "8.4" ghc.version) (enableFeature enableStaticLibraries "static")) 215 (optionalString (isGhcjs || versionOlder "7.4" ghc.version) (enableFeature enableSharedExecutables "executable-dynamic")) 216 (optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature doCheck "tests")) 217 (enableFeature doBenchmark "benchmarks") 218 "--enable-library-vanilla" # TODO: Should this be configurable? 219 (enableFeature enableLibraryForGhci "library-for-ghci") 220 ] ++ optionals (enableDeadCodeElimination && (lib.versionOlder "8.0.1" ghc.version)) [ 221 "--ghc-option=-split-sections" 222 ] ++ optionals dontStrip [ 223 "--disable-library-stripping" 224 "--disable-executable-stripping" 225 ] ++ optionals isGhcjs [ 226 "--ghcjs" 227 ] ++ optionals isCross ([ 228 "--configure-option=--host=${stdenv.hostPlatform.config}" 229 ] ++ crossCabalFlags 230 ) ++ optionals enableSeparateBinOutput [ 231 "--bindir=${binDir}" 232 ] ++ optionals (doHaddockInterfaces && isLibrary) [ 233 "--ghc-options=-haddock" 234 ]; 235 236 setupCompileFlags = [ 237 (optionalString (!coreSetup) "-${nativePackageDbFlag}=$setupPackageConfDir") 238 (optionalString enableParallelBuilding (parallelBuildingFlags)) 239 "-threaded" # https://github.com/haskell/cabal/issues/2398 240 "-rtsopts" # allow us to pass RTS flags to the generated Setup executable 241 ]; 242 243 isHaskellPkg = x: x ? isHaskellLibrary; 244 245 allPkgconfigDepends = pkg-configDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++ 246 optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends; 247 248 depsBuildBuild = [ nativeGhc ]; 249 collectedToolDepends = 250 buildTools ++ libraryToolDepends ++ executableToolDepends ++ 251 optionals doCheck testToolDepends ++ 252 optionals doBenchmark benchmarkToolDepends; 253 nativeBuildInputs = 254 [ ghc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) pkg-config ++ 255 setupHaskellDepends ++ collectedToolDepends; 256 propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends ++ libraryFrameworkDepends; 257 otherBuildInputsHaskell = 258 optionals doCheck (testDepends ++ testHaskellDepends) ++ 259 optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends); 260 otherBuildInputsSystem = 261 extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ executableFrameworkDepends ++ 262 allPkgconfigDepends ++ 263 optionals doCheck (testSystemDepends ++ testFrameworkDepends) ++ 264 optionals doBenchmark (benchmarkSystemDepends ++ benchmarkFrameworkDepends); 265 # TODO next rebuild just define as `otherBuildInputsHaskell ++ otherBuildInputsSystem` 266 otherBuildInputs = 267 extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++ executableFrameworkDepends ++ 268 allPkgconfigDepends ++ 269 optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testFrameworkDepends) ++ 270 optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkFrameworkDepends); 271 272 setupCommand = "./Setup"; 273 274 ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; 275 ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; 276 277 nativeGhcCommand = "${nativeGhc.targetPrefix}ghc"; 278 279 buildPkgDb = ghcName: packageConfDir: '' 280 # If this dependency has a package database, then copy the contents of it, 281 # unless it is one of our GHCs. These can appear in our dependencies when 282 # we are doing native builds, and they have package databases in them, but 283 # we do not want to copy them over. 284 # 285 # We don't need to, since those packages will be provided by the GHC when 286 # we compile with it, and doing so can result in having multiple copies of 287 # e.g. Cabal in the database with the same name and version, which is 288 # ambiguous. 289 if [ -d "$p/lib/${ghcName}/package.conf.d" ] && [ "$p" != "${ghc}" ] && [ "$p" != "${nativeGhc}" ]; then 290 cp -f "$p/lib/${ghcName}/package.conf.d/"*.conf ${packageConfDir}/ 291 continue 292 fi 293 ''; 294in lib.fix (drv: 295 296assert allPkgconfigDepends != [] -> pkg-config != null; 297 298stdenv.mkDerivation ({ 299 inherit pname version; 300 301 outputs = [ "out" ] 302 ++ (optional enableSeparateDataOutput "data") 303 ++ (optional enableSeparateDocOutput "doc") 304 ++ (optional enableSeparateBinOutput "bin"); 305 setOutputFlags = false; 306 307 pos = builtins.unsafeGetAttrPos "pname" args; 308 309 prePhases = ["setupCompilerEnvironmentPhase"]; 310 preConfigurePhases = ["compileBuildDriverPhase"]; 311 preInstallPhases = ["haddockPhase"]; 312 313 inherit src; 314 315 inherit depsBuildBuild nativeBuildInputs; 316 buildInputs = otherBuildInputs ++ optionals (!isLibrary) propagatedBuildInputs; 317 propagatedBuildInputs = optionals isLibrary propagatedBuildInputs; 318 319 LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase. 320 321 prePatch = optionalString (editedCabalFile != null) '' 322 echo "Replace Cabal file with edited version from ${newCabalFileUrl}." 323 cp ${newCabalFile} ${pname}.cabal 324 '' + prePatch; 325 326 postPatch = optionalString jailbreak '' 327 echo "Run jailbreak-cabal to lift version restrictions on build inputs." 328 ${jailbreak-cabal}/bin/jailbreak-cabal ${pname}.cabal 329 '' + postPatch; 330 331 setupCompilerEnvironmentPhase = '' 332 NIX_BUILD_CORES=$(( NIX_BUILD_CORES < ${toString maxBuildCores} ? NIX_BUILD_CORES : ${toString maxBuildCores} )) 333 runHook preSetupCompilerEnvironment 334 335 echo "Build with ${ghc}." 336 ${optionalString (isLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"} 337 338 setupPackageConfDir="$TMPDIR/setup-package.conf.d" 339 mkdir -p $setupPackageConfDir 340 packageConfDir="$TMPDIR/package.conf.d" 341 mkdir -p $packageConfDir 342 343 setupCompileFlags="${concatStringsSep " " setupCompileFlags}" 344 configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" 345 '' 346 # We build the Setup.hs on the *build* machine, and as such should only add 347 # dependencies for the build machine. 348 # 349 # pkgs* arrays defined in stdenv/setup.hs 350 + '' 351 for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do 352 ${buildPkgDb nativeGhc.name "$setupPackageConfDir"} 353 done 354 ${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache 355 '' 356 # For normal components 357 + '' 358 for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do 359 ${buildPkgDb ghc.name "$packageConfDir"} 360 if [ -d "$p/include" ]; then 361 configureFlags+=" --extra-include-dirs=$p/include" 362 fi 363 if [ -d "$p/lib" ]; then 364 configureFlags+=" --extra-lib-dirs=$p/lib" 365 fi 366 '' 367 # It is not clear why --extra-framework-dirs does work fine on Linux 368 + optionalString (!stdenv.buildPlatform.isDarwin || versionAtLeast nativeGhc.version "8.0") '' 369 if [[ -d "$p/Library/Frameworks" ]]; then 370 configureFlags+=" --extra-framework-dirs=$p/Library/Frameworks" 371 fi 372 '' + '' 373 done 374 '' 375 # only use the links hack if we're actually building dylibs. otherwise, the 376 # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes 377 # "ln -s $out/lib/links", which tries to recreate the links dir and fails 378 + (optionalString (stdenv.isDarwin && (enableSharedLibraries || enableSharedExecutables)) '' 379 # Work around a limit in the macOS Sierra linker on the number of paths 380 # referenced by any one dynamic library: 381 # 382 # Create a local directory with symlinks of the *.dylib (macOS shared 383 # libraries) from all the dependencies. 384 local dynamicLinksDir="$out/lib/links" 385 mkdir -p $dynamicLinksDir 386 387 # Unprettify all package conf files before reading/writing them 388 for d in "$packageConfDir/"*; do 389 # gawk -i inplace seems to strip the last newline 390 gawk -f ${unprettyConf} "$d" > tmp 391 mv tmp "$d" 392 done 393 394 for d in $(grep '^dynamic-library-dirs:' "$packageConfDir"/* | cut -d' ' -f2- | tr ' ' '\n' | sort -u); do 395 for lib in "$d/"*.{dylib,so}; do 396 # Allow overwriting because C libs can be pulled in multiple times. 397 ln -sf "$lib" "$dynamicLinksDir" 398 done 399 done 400 # Edit the local package DB to reference the links directory. 401 for f in "$packageConfDir/"*.conf; do 402 sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," "$f" 403 done 404 '') + '' 405 ${ghcCommand}-pkg --${packageDbFlag}="$packageConfDir" recache 406 407 runHook postSetupCompilerEnvironment 408 ''; 409 410 compileBuildDriverPhase = '' 411 runHook preCompileBuildDriver 412 413 for i in Setup.hs Setup.lhs ${defaultSetupHs}; do 414 test -f $i && break 415 done 416 417 echo setupCompileFlags: $setupCompileFlags 418 ${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i 419 420 runHook postCompileBuildDriver 421 ''; 422 423 # Cabal takes flags like `--configure-option=--host=...` instead 424 configurePlatforms = []; 425 inherit configureFlags; 426 427 # Note: the options here must be always added, regardless of whether the 428 # package specifies `hardeningDisable`. 429 hardeningDisable = lib.optionals (args ? hardeningDisable) hardeningDisable 430 ++ lib.optional (ghc.isHaLVM or false) "all" 431 # Static libraries (ie. all of pkgsStatic.haskellPackages) fail to build 432 # because by default Nix adds `-pie` to the linker flags: this 433 # conflicts with the `-r` and `-no-pie` flags added by GHC (see 434 # https://gitlab.haskell.org/ghc/ghc/-/issues/19580). hardeningDisable 435 # changes the default Nix behavior regarding adding "hardening" flags. 436 ++ lib.optional enableStaticLibraries "pie"; 437 438 configurePhase = '' 439 runHook preConfigure 440 441 unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure. 442 443 echo configureFlags: $configureFlags 444 ${setupCommand} configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log" 445 ${lib.optionalString (!allowInconsistentDependencies) '' 446 if ${gnugrep}/bin/egrep -q -z 'Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then 447 echo >&2 "*** abort because of serious configure-time warning from Cabal" 448 exit 1 449 fi 450 ''} 451 export GHC_PACKAGE_PATH="$packageConfDir:" 452 453 runHook postConfigure 454 ''; 455 456 buildPhase = '' 457 runHook preBuild 458 ${setupCommand} build ${buildTarget}${crossCabalFlagsString}${buildFlagsString} 459 runHook postBuild 460 ''; 461 462 inherit doCheck; 463 464 # Run test suite(s) and pass `checkFlags` as well as `checkFlagsArray`. 465 # `testFlags` are added to `checkFlagsArray` each prefixed with 466 # `--test-option`, so Cabal passes it to the underlying test suite binary. 467 checkPhase = '' 468 runHook preCheck 469 checkFlagsArray+=(${lib.escapeShellArgs (builtins.map (opt: "--test-option=${opt}") testFlags)}) 470 ${setupCommand} test ${testTarget} $checkFlags ''${checkFlagsArray:+"''${checkFlagsArray[@]}"} 471 runHook postCheck 472 ''; 473 474 haddockPhase = '' 475 runHook preHaddock 476 ${optionalString (doHaddock && isLibrary) '' 477 ${setupCommand} haddock --html \ 478 ${optionalString doHoogle "--hoogle"} \ 479 ${optionalString doHaddockQuickjump "--quickjump"} \ 480 ${optionalString (isLibrary && hyperlinkSource) "--hyperlink-source"} \ 481 ${lib.concatStringsSep " " haddockFlags} 482 ''} 483 runHook postHaddock 484 ''; 485 486 installPhase = '' 487 runHook preInstall 488 489 ${if !isLibrary && buildTarget == "" then "${setupCommand} install" 490 # ^^ if the project is not a library, and no build target is specified, we can just use "install". 491 else if !isLibrary then "${setupCommand} copy ${buildTarget}" 492 # ^^ if the project is not a library, and we have a build target, then use "copy" to install 493 # just the target specified; "install" will error here, since not all targets have been built. 494 else '' 495 ${setupCommand} copy ${buildTarget} 496 local packageConfDir="$out/lib/${ghc.name}/package.conf.d" 497 local packageConfFile="$packageConfDir/${pname}-${version}.conf" 498 mkdir -p "$packageConfDir" 499 ${setupCommand} register --gen-pkg-config=$packageConfFile 500 if [ -d "$packageConfFile" ]; then 501 mv "$packageConfFile/"* "$packageConfDir" 502 rmdir "$packageConfFile" 503 fi 504 for packageConfFile in "$packageConfDir/"*; do 505 local pkgId=$(gawk -f ${unprettyConf} "$packageConfFile" \ 506 | grep '^id:' | cut -d' ' -f2) 507 mv "$packageConfFile" "$packageConfDir/$pkgId.conf" 508 done 509 510 # delete confdir if there are no libraries 511 find $packageConfDir -maxdepth 0 -empty -delete; 512 ''} 513 ${optionalString isGhcjs '' 514 for exeDir in "${binDir}/"*.jsexe; do 515 exe="''${exeDir%.jsexe}" 516 printWords '#!${nodejs}/bin/node' > "$exe" 517 echo >> "$exe" 518 cat "$exeDir/all.js" >> "$exe" 519 chmod +x "$exe" 520 done 521 ''} 522 ${optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share"} 523 ${optionalString (enableSharedExecutables && isExecutable && !isGhcjs && stdenv.isDarwin && lib.versionOlder ghc.version "7.10") '' 524 for exe in "${binDir}/"* ; do 525 install_name_tool -add_rpath "$out/lib/ghc-${ghc.version}/${pname}-${version}" "$exe" 526 done 527 ''} 528 529 ${optionalString enableSeparateDocOutput '' 530 for x in ${docdir "$doc"}"/html/src/"*.html; do 531 remove-references-to -t $out $x 532 done 533 mkdir -p $doc 534 ''} 535 ${optionalString enableSeparateDataOutput "mkdir -p $data"} 536 537 runHook postInstall 538 ''; 539 540 passthru = passthru // rec { 541 542 inherit pname version; 543 544 compiler = ghc; 545 546 # All this information is intended just for `shellFor`. It should be 547 # considered unstable and indeed we knew how to keep it private we would. 548 getCabalDeps = { 549 inherit 550 buildDepends 551 buildTools 552 executableFrameworkDepends 553 executableHaskellDepends 554 executablePkgconfigDepends 555 executableSystemDepends 556 executableToolDepends 557 extraLibraries 558 libraryFrameworkDepends 559 libraryHaskellDepends 560 libraryPkgconfigDepends 561 librarySystemDepends 562 libraryToolDepends 563 pkg-configDepends 564 setupHaskellDepends 565 ; 566 } // lib.optionalAttrs doCheck { 567 inherit 568 testDepends 569 testFrameworkDepends 570 testHaskellDepends 571 testPkgconfigDepends 572 testSystemDepends 573 testToolDepends 574 ; 575 } // lib.optionalAttrs doBenchmark { 576 inherit 577 benchmarkDepends 578 benchmarkFrameworkDepends 579 benchmarkHaskellDepends 580 benchmarkPkgconfigDepends 581 benchmarkSystemDepends 582 benchmarkToolDepends 583 ; 584 }; 585 586 # Attributes for the old definition of `shellFor`. Should be removed but 587 # this predates the warning at the top of `getCabalDeps`. 588 getBuildInputs = rec { 589 inherit propagatedBuildInputs otherBuildInputs allPkgconfigDepends; 590 haskellBuildInputs = isHaskellPartition.right; 591 systemBuildInputs = isHaskellPartition.wrong; 592 isHaskellPartition = lib.partition 593 isHaskellPkg 594 (propagatedBuildInputs ++ otherBuildInputs ++ depsBuildBuild ++ nativeBuildInputs); 595 }; 596 597 isHaskellLibrary = isLibrary; 598 599 # TODO: ask why the split outputs are configurable at all? 600 # TODO: include tests for split if possible 601 # Given the haskell package, returns 602 # the directory containing the haddock documentation. 603 # `null' if no haddock documentation was built. 604 # TODO: fetch the self from the fixpoint instead 605 haddockDir = self: if doHaddock then "${docdir self.doc}/html" else null; 606 607 # Creates a derivation containing all of the necessary dependencies for building the 608 # parent derivation. The attribute set that it takes as input can be viewed as: 609 # 610 # { withHoogle } 611 # 612 # The derivation that it builds contains no outpaths because it is meant for use 613 # as an environment 614 # 615 # # Example use 616 # # Creates a shell with all of the dependencies required to build the "hello" package, 617 # # and with python: 618 # 619 # > nix-shell -E 'with (import <nixpkgs> {}); \ 620 # > haskell.packages.ghc865.hello.envFunc { buildInputs = [ python ]; }' 621 envFunc = { withHoogle ? false }: 622 let 623 name = "ghc-shell-for-${drv.name}"; 624 625 withPackages = if withHoogle then ghcWithHoogle else ghcWithPackages; 626 627 # We use the `ghcWithPackages` function from `buildHaskellPackages` if we 628 # want a shell for the sake of cross compiling a package. In the native case 629 # we don't use this at all, and instead put the setupDepends in the main 630 # `ghcWithPackages`. This way we don't have two wrapper scripts called `ghc` 631 # shadowing each other on the PATH. 632 ghcEnvForBuild = 633 assert isCross; 634 buildHaskellPackages.ghcWithPackages (_: setupHaskellDepends); 635 636 ghcEnv = withPackages (_: 637 otherBuildInputsHaskell ++ 638 propagatedBuildInputs ++ 639 lib.optionals (!isCross) setupHaskellDepends); 640 641 ghcCommandCaps = lib.toUpper ghcCommand'; 642 in stdenv.mkDerivation ({ 643 inherit name shellHook; 644 645 depsBuildBuild = lib.optional isCross ghcEnvForBuild; 646 nativeBuildInputs = 647 [ ghcEnv ] ++ optional (allPkgconfigDepends != []) pkg-config ++ 648 collectedToolDepends; 649 buildInputs = 650 otherBuildInputsSystem; 651 phases = ["installPhase"]; 652 installPhase = "echo $nativeBuildInputs $buildInputs > $out"; 653 LANG = "en_US.UTF-8"; 654 LOCALE_ARCHIVE = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "${buildPackages.glibcLocales}/lib/locale/locale-archive"; 655 "NIX_${ghcCommandCaps}" = "${ghcEnv}/bin/${ghcCommand}"; 656 "NIX_${ghcCommandCaps}PKG" = "${ghcEnv}/bin/${ghcCommand}-pkg"; 657 # TODO: is this still valid? 658 "NIX_${ghcCommandCaps}_DOCDIR" = "${ghcEnv}/share/doc/ghc/html"; 659 "NIX_${ghcCommandCaps}_LIBDIR" = if ghc.isHaLVM or false 660 then "${ghcEnv}/lib/HaLVM-${ghc.version}" 661 else "${ghcEnv}/lib/${ghcCommand}-${ghc.version}"; 662 }); 663 664 env = envFunc { }; 665 666 }; 667 668 meta = { inherit homepage license platforms; } 669 // optionalAttrs (args ? broken) { inherit broken; } 670 // optionalAttrs (args ? description) { inherit description; } 671 // optionalAttrs (args ? maintainers) { inherit maintainers; } 672 // optionalAttrs (args ? hydraPlatforms) { inherit hydraPlatforms; } 673 // optionalAttrs (args ? badPlatforms) { inherit badPlatforms; } 674 // optionalAttrs (args ? changelog) { inherit changelog; } 675 // optionalAttrs (args ? mainProgram) { inherit mainProgram; } 676 ; 677 678} 679// optionalAttrs (args ? preCompileBuildDriver) { inherit preCompileBuildDriver; } 680// optionalAttrs (args ? postCompileBuildDriver) { inherit postCompileBuildDriver; } 681// optionalAttrs (args ? preUnpack) { inherit preUnpack; } 682// optionalAttrs (args ? postUnpack) { inherit postUnpack; } 683// optionalAttrs (args ? patches) { inherit patches; } 684// optionalAttrs (args ? patchPhase) { inherit patchPhase; } 685// optionalAttrs (args ? preConfigure) { inherit preConfigure; } 686// optionalAttrs (args ? postConfigure) { inherit postConfigure; } 687// optionalAttrs (args ? preBuild) { inherit preBuild; } 688// optionalAttrs (args ? postBuild) { inherit postBuild; } 689// optionalAttrs (args ? doBenchmark) { inherit doBenchmark; } 690// optionalAttrs (args ? checkPhase) { inherit checkPhase; } 691// optionalAttrs (args ? preCheck) { inherit preCheck; } 692// optionalAttrs (args ? postCheck) { inherit postCheck; } 693// optionalAttrs (args ? preHaddock) { inherit preHaddock; } 694// optionalAttrs (args ? postHaddock) { inherit postHaddock; } 695// optionalAttrs (args ? preInstall) { inherit preInstall; } 696// optionalAttrs (args ? installPhase) { inherit installPhase; } 697// optionalAttrs (args ? postInstall) { inherit postInstall; } 698// optionalAttrs (args ? preFixup) { inherit preFixup; } 699// optionalAttrs (args ? postFixup) { inherit postFixup; } 700// optionalAttrs (args ? dontStrip) { inherit dontStrip; } 701// optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; } 702) 703)