diff options
author | Shea Levy <shea@shealevy.com> | 2017-12-28 21:29:23 -0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2017-12-29 14:37:24 -0500 |
commit | 1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93 (patch) | |
tree | bf2cd7284d58fa95fec72bab00774475f0754f92 /pkgs/development/haskell-modules | |
parent | 59087261172d07e377c81e2ab799f1633d35039c (diff) | |
download | nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.gz nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.bz2 nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.lz nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.xz nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.zst nixlib-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.zip |
Revert "Revert "hslib: Function to extract the haskell build inputs of a package.""
Trying again, without changing the generic builder. This reverts commit 65138e8a411244c81aefa21be280323d30010b96.
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 3182b4846c0f..b9aff5ece083 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -350,6 +350,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; + }; + } |