nixpkgs/pkgs/development/compilers/ghc/with-packages.nix
Peter Simons 89c566fcfd pkgs/development/compilers/ghc/with-packages.nix: improve recognition of Haskell packages
Haskell packages -- i.e. packages built by our Cabal builder -- invariably have
the attributes 'pname' and 'version'. We use the absence of these attributes to
recognize non-Haskell packages and filter them from the closed package set
generated by closePropagation. We do this so that the generated Haskell
environment won't contain paths like "/lib/libz.a", which are part of the
closure but have nothing to do with Haskell.

The previous scheme used the attribute 'ghc' to accomplish the same thing, but
unfortunately other packages to contain a 'ghc' attribute, too, like the
old-style ghc-wrapper. Including the ghc-wrapper in this environment is
pointless, obviously. The new approach filters the ghc-wrapper successfully.
2013-11-07 12:14:19 +01:00

44 lines
1.5 KiB
Nix

{ stdenv, ghc, packages, buildEnv, makeWrapper }:
assert packages != [];
let
ghc761OrLater = stdenv.lib.versionOlder "7.6.1" ghc.version;
packageDBFlag = if ghc761OrLater then "--package-db" else "--package-conf";
libDir = "$out/lib/ghc-${ghc.version}";
packageCfgDir = "${libDir}/package.conf.d";
isHaskellPkg = x: (x ? pname) && (x ? version);
in
buildEnv {
name = "haskell-env-${ghc.name}";
paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages) ++ [ghc];
postBuild = ''
. ${makeWrapper}/nix-support/setup-hook
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
--add-flags '"-B$NIX_GHC_LIBDIR"' \
--set "NIX_GHC" "$out/bin/ghc" \
--set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
--set "NIX_GHC_LIBDIR" "${libDir}"
done
for prg in runghc runhaskell; do
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
--add-flags "-f $out/bin/ghc" \
--set "NIX_GHC" "$out/bin/ghc" \
--set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
--set "NIX_GHC_LIBDIR" "${libDir}"
done
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
rm -f $out/bin/$prg
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag} ${packageCfgDir}"
done
$out/bin/ghc-pkg recache
'';
}