summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/lib.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2017-12-28 21:29:23 -0500
committerShea Levy <shea@shealevy.com>2017-12-29 14:37:24 -0500
commit1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93 (patch)
treebf2cd7284d58fa95fec72bab00774475f0754f92 /pkgs/development/haskell-modules/lib.nix
parent59087261172d07e377c81e2ab799f1633d35039c (diff)
downloadnixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar
nixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.gz
nixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.bz2
nixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.lz
nixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.xz
nixpkgs-1ee61d8f2339bd88205bd45b4dfdbb577f3dfd93.tar.zst
nixpkgs-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/lib.nix')
-rw-r--r--pkgs/development/haskell-modules/lib.nix80
1 files changed, 80 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix
index 96520dce2b2..6a724130d25 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;
+      };
+
 }