2013-11-07 12:09:38 +01:00
|
|
|
{ stdenv, ghc, packages, buildEnv, makeWrapper, ignoreCollisions ? false }:
|
2011-12-03 17:19:43 +01:00
|
|
|
|
2013-11-09 20:36:25 +01:00
|
|
|
# This wrapper works only with GHC 6.12 or later.
|
|
|
|
assert stdenv.lib.versionOlder "6.12" ghc.version;
|
|
|
|
|
|
|
|
# It's probably a good idea to include the library "ghc-paths" in the
|
|
|
|
# compiler environment, because we have a specially patched version of
|
|
|
|
# that package in Nix that honors these environment variables
|
|
|
|
#
|
|
|
|
# NIX_GHC
|
|
|
|
# NIX_GHCPKG
|
|
|
|
# NIX_GHC_DOCDIR
|
|
|
|
# NIX_GHC_LIBDIR
|
|
|
|
#
|
|
|
|
# instead of hard-coding the paths. The wrapper sets these variables
|
|
|
|
# appropriately to configure ghc-paths to point back to the wrapper
|
|
|
|
# instead of to the pristine GHC package, which doesn't know any of the
|
|
|
|
# additional libraries.
|
|
|
|
#
|
|
|
|
# A good way to import the environment set by the wrapper below into
|
|
|
|
# your shell is to add the following snippet to your ~/.bashrc:
|
|
|
|
#
|
|
|
|
# if [ -e ~/.nix-profile/bin/ghc ]; then
|
|
|
|
# eval $(grep export ~/.nix-profile/bin/ghc)
|
|
|
|
# fi
|
2011-12-03 17:19:43 +01:00
|
|
|
|
2013-10-26 18:33:09 +02:00
|
|
|
let
|
|
|
|
ghc761OrLater = stdenv.lib.versionOlder "7.6.1" ghc.version;
|
2013-11-09 20:36:25 +01:00
|
|
|
packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
|
2013-10-26 18:33:09 +02:00
|
|
|
libDir = "$out/lib/ghc-${ghc.version}";
|
2013-11-09 20:36:25 +01:00
|
|
|
docDir = "$out/share/doc/ghc/html";
|
2013-10-26 18:33:09 +02:00
|
|
|
packageCfgDir = "${libDir}/package.conf.d";
|
2013-11-07 12:02:47 +01:00
|
|
|
isHaskellPkg = x: (x ? pname) && (x ? version);
|
2013-10-26 18:33:09 +02:00
|
|
|
in
|
2013-11-09 20:36:25 +01:00
|
|
|
if packages == [] then ghc else
|
2013-10-26 18:33:09 +02:00
|
|
|
buildEnv {
|
|
|
|
name = "haskell-env-${ghc.name}";
|
2013-11-07 12:02:47 +01:00
|
|
|
paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages) ++ [ghc];
|
2013-11-07 12:09:38 +01:00
|
|
|
inherit ignoreCollisions;
|
2013-10-26 18:33:09 +02:00
|
|
|
postBuild = ''
|
|
|
|
. ${makeWrapper}/nix-support/setup-hook
|
2011-12-03 17:19:43 +01:00
|
|
|
|
2011-12-04 17:07:39 +01:00
|
|
|
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
|
2013-10-26 18:33:09 +02:00
|
|
|
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" \
|
2013-11-09 20:36:25 +01:00
|
|
|
--set "NIX_GHC_DOCDIR" "${docDir}" \
|
2013-10-26 18:33:09 +02:00
|
|
|
--set "NIX_GHC_LIBDIR" "${libDir}"
|
2011-12-04 17:07:39 +01:00
|
|
|
done
|
2011-12-03 17:19:43 +01:00
|
|
|
|
2011-12-04 17:07:39 +01:00
|
|
|
for prg in runghc runhaskell; do
|
2013-10-26 18:33:09 +02:00
|
|
|
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" \
|
2013-11-09 20:36:25 +01:00
|
|
|
--set "NIX_GHC_DOCDIR" "${docDir}" \
|
2013-10-26 18:33:09 +02:00
|
|
|
--set "NIX_GHC_LIBDIR" "${libDir}"
|
2011-12-03 17:19:43 +01:00
|
|
|
done
|
|
|
|
|
2011-12-04 17:07:39 +01:00
|
|
|
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
|
2013-10-26 18:33:09 +02:00
|
|
|
rm -f $out/bin/$prg
|
2013-11-09 20:36:25 +01:00
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
|
2011-12-04 17:07:39 +01:00
|
|
|
done
|
2011-12-03 17:19:43 +01:00
|
|
|
|
2013-10-26 18:33:09 +02:00
|
|
|
$out/bin/ghc-pkg recache
|
2011-12-03 17:19:43 +01:00
|
|
|
'';
|
|
|
|
}
|