about summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/haskell-modules/default.nix')
-rw-r--r--pkgs/development/haskell-modules/default.nix39
1 files changed, 26 insertions, 13 deletions
diff --git a/pkgs/development/haskell-modules/default.nix b/pkgs/development/haskell-modules/default.nix
index ef73e47f537e..d2ecc3381287 100644
--- a/pkgs/development/haskell-modules/default.nix
+++ b/pkgs/development/haskell-modules/default.nix
@@ -55,18 +55,26 @@ let
         inherit packages;
       };
 
-      hackage2nix = name: version: pkgs.stdenv.mkDerivation {
-        name = "cabal2nix-${name}-${version}";
-        buildInputs = [ pkgs.cabal2nix ];
-        phases = ["installPhase"];
-        LANG = "en_US.UTF-8";
-        LOCALE_ARCHIVE = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive";
-        installPhase = ''
-          export HOME="$TMP"
-          mkdir $out
-          hash=$(sed -e 's/.*"SHA256":"//' -e 's/".*$//' ${all-cabal-hashes}/${name}/${version}/${name}.json)
-          cabal2nix --compiler=${self.ghc.name} --system=${stdenv.system} --sha256=$hash ${all-cabal-hashes}/${name}/${version}/${name}.cabal >$out/default.nix
-        '';
+      haskellSrc2nix = { name, src, sha256 ? null }:
+        let
+          sha256Arg = if isNull sha256 then "" else ''--sha256="${sha256}"'';
+        in pkgs.stdenv.mkDerivation {
+          name = "cabal2nix-${name}";
+          buildInputs = [ pkgs.cabal2nix ];
+          phases = ["installPhase"];
+          LANG = "en_US.UTF-8";
+          LOCALE_ARCHIVE = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive";
+          installPhase = ''
+            export HOME="$TMP"
+            mkdir -p "$out"
+            cabal2nix --compiler=${self.ghc.name} --system=${stdenv.system} ${sha256Arg} "${src}" > "$out/default.nix"
+          '';
+      };
+
+      hackage2nix = name: version: haskellSrc2nix {
+        name   = "${name}-${version}";
+        sha256 = ''$(sed -e 's/.*"SHA256":"//' -e 's/".*$//' "${all-cabal-hashes}/${name}/${version}/${name}.json")'';
+        src    = "${all-cabal-hashes}/${name}/${version}/${name}.cabal";
       };
 
     in
@@ -76,6 +84,9 @@ let
 
         callHackage = name: version: self.callPackage (hackage2nix name version);
 
+        # Creates a Haskell package from a source package by calling cabal2nix on the source.
+        callCabal2nix = name: src: self.callPackage (haskellSrc2nix { inherit src name; });
+
         ghcWithPackages = selectFrom: withPackages (selectFrom self);
 
         ghcWithHoogle = selectFrom:
@@ -94,6 +105,7 @@ let
       };
 
   commonConfiguration = import ./configuration-common.nix { inherit pkgs; };
+  nixConfiguration = import ./configuration-nix.nix { inherit pkgs; };
 
 in
 
@@ -101,4 +113,5 @@ in
     (extends overrides
       (extends packageSetConfig
         (extends compilerConfig
-          (extends commonConfiguration haskellPackages))))
+          (extends commonConfiguration
+            (extends nixConfiguration haskellPackages)))))