Add callCabal2nix to haskell packages

Closes https://github.com/NixOS/nixpkgs/pull/22191.
This commit is contained in:
3noch 2017-01-26 21:22:06 -05:00 committed by Peter Simons
parent dd934beb9f
commit 05ee54782e

View File

@ -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,12 @@ let
callHackage = name: version: self.callPackage (hackage2nix name version);
# Creates a Haskell package from a source package by calling cabal2nix on the source.
callCabal2nix = src: self.callPackage (haskellSrc2nix {
inherit src;
name = src.name;
});
ghcWithPackages = selectFrom: withPackages (selectFrom self);
ghcWithHoogle = selectFrom: