From 1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Thu, 28 Dec 2017 21:29:23 -0500 Subject: [PATCH] Revert "Revert "hslib: Function to extract the haskell build inputs of a package."" Trying again, without changing the generic builder. This reverts commit 65138e8a411244c81aefa21be280323d30010b96. --- .../haskell-modules/generic-builder.nix | 2 + pkgs/development/haskell-modules/lib.nix | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+) 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; + }; + }