···11-{ stdenv, ghc, packages, buildEnv, makeWrapper, ignoreCollisions ? false }:
22-33-# This wrapper works only with GHC 6.12 or later.
44-assert stdenv.lib.versionOlder "6.12" ghc.version;
55-66-# It's probably a good idea to include the library "ghc-paths" in the
77-# compiler environment, because we have a specially patched version of
88-# that package in Nix that honors these environment variables
99-#
1010-# NIX_GHC
1111-# NIX_GHCPKG
1212-# NIX_GHC_DOCDIR
1313-# NIX_GHC_LIBDIR
1414-#
1515-# instead of hard-coding the paths. The wrapper sets these variables
1616-# appropriately to configure ghc-paths to point back to the wrapper
1717-# instead of to the pristine GHC package, which doesn't know any of the
1818-# additional libraries.
1919-#
2020-# A good way to import the environment set by the wrapper below into
2121-# your shell is to add the following snippet to your ~/.bashrc:
2222-#
2323-# if [ -e ~/.nix-profile/bin/ghc ]; then
2424-# eval $(grep export ~/.nix-profile/bin/ghc)
2525-# fi
2626-2727-let
2828- ghc761OrLater = stdenv.lib.versionOlder "7.6.1" ghc.version;
2929- packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
3030- libDir = "$out/lib/ghc-${ghc.version}";
3131- docDir = "$out/share/doc/ghc/html";
3232- packageCfgDir = "${libDir}/package.conf.d";
3333- isHaskellPkg = x: (x ? pname) && (x ? version);
3434-in
3535-if packages == [] then ghc else
3636-buildEnv {
3737- name = "haskell-env-${ghc.name}";
3838- paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages) ++ [ghc];
3939- inherit ignoreCollisions;
4040- postBuild = ''
4141- . ${makeWrapper}/nix-support/setup-hook
4242-4343- for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
4444- rm -f $out/bin/$prg
4545- makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
4646- --add-flags '"-B$NIX_GHC_LIBDIR"' \
4747- --set "NIX_GHC" "$out/bin/ghc" \
4848- --set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
4949- --set "NIX_GHC_DOCDIR" "${docDir}" \
5050- --set "NIX_GHC_LIBDIR" "${libDir}"
5151- done
5252-5353- for prg in runghc runhaskell; do
5454- rm -f $out/bin/$prg
5555- makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
5656- --add-flags "-f $out/bin/ghc" \
5757- --set "NIX_GHC" "$out/bin/ghc" \
5858- --set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
5959- --set "NIX_GHC_DOCDIR" "${docDir}" \
6060- --set "NIX_GHC_LIBDIR" "${libDir}"
6161- done
6262-6363- for prg in ghc-pkg ghc-pkg-${ghc.version}; do
6464- rm -f $out/bin/$prg
6565- makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
6666- done
6767-6868- $out/bin/ghc-pkg recache
6969- '';
7070-}