diff options
author | Peter Simons <simons@cryp.to> | 2017-12-29 20:51:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-29 20:51:24 +0100 |
commit | 4a01a175a3a43498915cae113b4cff25e2fc6f13 (patch) | |
tree | ce7332eb5ff4843ad9308b45f69f1572e73c2bf0 /pkgs/development/haskell-modules | |
parent | 89e882f956bcddf01ea2d69a569156bf93dcb9c6 (diff) | |
parent | 1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93 (diff) | |
download | nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar.gz nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar.bz2 nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar.lz nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar.xz nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.tar.zst nixlib-4a01a175a3a43498915cae113b4cff25e2fc6f13.zip |
Merge pull request #33158 from shlevy/hslib-haskell-build-inputs-again
Revert "Revert "hslib: Function to extract the haskell build inputs of a package.""
Diffstat (limited to 'pkgs/development/haskell-modules')
-rw-r--r-- | pkgs/development/haskell-modules/generic-builder.nix | 2 | ||||
-rw-r--r-- | pkgs/development/haskell-modules/lib.nix | 80 |
2 files changed, 82 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index b80c5df68aa0..96de6ab6d3f7 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -356,6 +356,8 @@ stdenv.mkDerivation ({ inherit pname version; + compiler = ghc; + isHaskellLibrary = hasActiveLibrary; # TODO: ask why the split outputs are configurable at all? diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix index 96520dce2b2d..6a724130d254 100644 --- a/pkgs/development/haskell-modules/lib.nix +++ b/pkgs/development/haskell-modules/lib.nix @@ -147,4 +147,84 @@ rec { overrideSrc = drv: { src, version ? drv.version }: overrideCabal drv (_: { inherit src version; editedCabalFile = null; }); + # Extract the haskell build inputs of a haskell package. + # This is useful to build environments for developing on that + # package. + getHaskellBuildInputs = p: + (p.override { mkDerivation = extractBuildInputs p.compiler; + }).haskellBuildInputs; + + ghcInfo = ghc: + rec { isCross = (ghc.cross or null) != null; + isGhcjs = ghc.isGhcjs or false; + nativeGhc = if isCross || isGhcjs + then ghc.bootPkgs.ghc + else ghc; + }; + + ### mkDerivation helpers + # These allow external users of a haskell package to extract + # information about how it is built in the same way that the + # generic haskell builder does, by reusing the same functions. + # Each function here has the same interface as mkDerivation and thus + # can be called for a given package simply by overriding the + # mkDerivation argument it used. See getHaskellBuildInputs above for + # an example of this. + + # Some information about which phases should be run. + controlPhases = ghc: let inherit (ghcInfo ghc) isCross; in + { doCheck ? !isCross && (lib.versionOlder "7.4" ghc.version) + , doBenchmark ? false + , ... + }: { inherit doCheck doBenchmark; }; + + # Divide the build inputs of the package into useful sets. + extractBuildInputs = ghc: + { setupHaskellDepends ? [], extraLibraries ? [] + , librarySystemDepends ? [], executableSystemDepends ? [] + , pkgconfigDepends ? [], libraryPkgconfigDepends ? [] + , executablePkgconfigDepends ? [], testPkgconfigDepends ? [] + , benchmarkPkgconfigDepends ? [], testDepends ? [] + , testHaskellDepends ? [], testSystemDepends ? [] + , testToolDepends ? [], benchmarkDepends ? [] + , benchmarkHaskellDepends ? [], benchmarkSystemDepends ? [] + , benchmarkToolDepends ? [], buildDepends ? [] + , libraryHaskellDepends ? [], executableHaskellDepends ? [] + , ... + }@args: + let inherit (ghcInfo ghc) isGhcjs nativeGhc; + inherit (controlPhases ghc args) doCheck doBenchmark; + isHaskellPkg = x: x ? isHaskellLibrary; + allPkgconfigDepends = + pkgconfigDepends ++ libraryPkgconfigDepends ++ + executablePkgconfigDepends ++ + lib.optionals doCheck testPkgconfigDepends ++ + lib.optionals doBenchmark benchmarkPkgconfigDepends; + otherBuildInputs = + setupHaskellDepends ++ extraLibraries ++ + librarySystemDepends ++ executableSystemDepends ++ + allPkgconfigDepends ++ + lib.optionals doCheck ( testDepends ++ testHaskellDepends ++ + testSystemDepends ++ testToolDepends + ) ++ + # ghcjs's hsc2hs calls out to the native hsc2hs + lib.optional isGhcjs nativeGhc ++ + lib.optionals doBenchmark ( benchmarkDepends ++ + benchmarkHaskellDepends ++ + benchmarkSystemDepends ++ + benchmarkToolDepends + ); + propagatedBuildInputs = + buildDepends ++ libraryHaskellDepends ++ + executableHaskellDepends; + allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; + isHaskellPartition = + lib.partition isHaskellPkg allBuildInputs; + in + { haskellBuildInputs = isHaskellPartition.right; + systemBuildInputs = isHaskellPartition.wrong; + inherit propagatedBuildInputs otherBuildInputs + allPkgconfigDepends; + }; + } |