···1-{ stdenv, ghc, packages, buildEnv, makeWrapper, ignoreCollisions ? false }:
2-3-# This wrapper works only with GHC 6.12 or later.
4-assert stdenv.lib.versionOlder "6.12" ghc.version;
5-6-# It's probably a good idea to include the library "ghc-paths" in the
7-# compiler environment, because we have a specially patched version of
8-# that package in Nix that honors these environment variables
9-#
10-# NIX_GHC
11-# NIX_GHCPKG
12-# NIX_GHC_DOCDIR
13-# NIX_GHC_LIBDIR
14-#
15-# instead of hard-coding the paths. The wrapper sets these variables
16-# appropriately to configure ghc-paths to point back to the wrapper
17-# instead of to the pristine GHC package, which doesn't know any of the
18-# additional libraries.
19-#
20-# A good way to import the environment set by the wrapper below into
21-# your shell is to add the following snippet to your ~/.bashrc:
22-#
23-# if [ -e ~/.nix-profile/bin/ghc ]; then
24-# eval $(grep export ~/.nix-profile/bin/ghc)
25-# fi
26-27-let
28- ghc761OrLater = stdenv.lib.versionOlder "7.6.1" ghc.version;
29- packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
30- libDir = "$out/lib/ghc-${ghc.version}";
31- docDir = "$out/share/doc/ghc/html";
32- packageCfgDir = "${libDir}/package.conf.d";
33- isHaskellPkg = x: (x ? pname) && (x ? version);
34-in
35-if packages == [] then ghc else
36-buildEnv {
37- name = "haskell-env-${ghc.name}";
38- paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages) ++ [ghc];
39- inherit ignoreCollisions;
40- postBuild = ''
41- . ${makeWrapper}/nix-support/setup-hook
42-43- for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
44- rm -f $out/bin/$prg
45- makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
46- --add-flags '"-B$NIX_GHC_LIBDIR"' \
47- --set "NIX_GHC" "$out/bin/ghc" \
48- --set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
49- --set "NIX_GHC_DOCDIR" "${docDir}" \
50- --set "NIX_GHC_LIBDIR" "${libDir}"
51- done
52-53- for prg in runghc runhaskell; do
54- rm -f $out/bin/$prg
55- makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
56- --add-flags "-f $out/bin/ghc" \
57- --set "NIX_GHC" "$out/bin/ghc" \
58- --set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
59- --set "NIX_GHC_DOCDIR" "${docDir}" \
60- --set "NIX_GHC_LIBDIR" "${libDir}"
61- done
62-63- for prg in ghc-pkg ghc-pkg-${ghc.version}; do
64- rm -f $out/bin/$prg
65- makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
66- done
67-68- $out/bin/ghc-pkg recache
69- '';
70-}