2015-04-28 13:14:05 +02:00
|
|
|
{ stdenv, lib, ghc, llvmPackages, packages, buildEnv, makeWrapper
|
|
|
|
, ignoreCollisions ? false, withLLVM ? false
|
|
|
|
, postBuild ? ""
|
2015-01-23 00:10:08 +01:00
|
|
|
, haskellPackages
|
2015-04-28 13:14:05 +02:00
|
|
|
}:
|
2015-03-09 20:11:23 +01:00
|
|
|
|
2015-01-07 20:31:32 +01:00
|
|
|
# This wrapper works only with GHC 6.12 or later.
|
2015-04-04 00:54:18 +02:00
|
|
|
assert lib.versionOlder "6.12" ghc.version || ghc.isGhcjs;
|
2015-01-07 20:31:32 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
let
|
2015-03-29 11:02:31 +02:00
|
|
|
isGhcjs = ghc.isGhcjs or false;
|
2015-03-29 04:24:35 +02:00
|
|
|
ghc761OrLater = isGhcjs || lib.versionOlder "7.6.1" ghc.version;
|
2015-01-07 20:31:32 +01:00
|
|
|
packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
|
2015-03-29 11:02:31 +02:00
|
|
|
ghcCommand = if isGhcjs then "ghcjs" else "ghc";
|
2015-05-06 21:56:02 +02:00
|
|
|
ghcCommandCaps= lib.toUpper ghcCommand;
|
2015-03-13 04:20:56 +01:00
|
|
|
libDir = "$out/lib/${ghcCommand}-${ghc.version}";
|
2015-01-07 20:31:32 +01:00
|
|
|
docDir = "$out/share/doc/ghc/html";
|
|
|
|
packageCfgDir = "${libDir}/package.conf.d";
|
2015-03-29 04:24:35 +02:00
|
|
|
paths = lib.filter (x: x ? isHaskellLibrary) (lib.closePropagation packages);
|
|
|
|
hasLibraries = lib.any (x: x.isHaskellLibrary) paths;
|
2015-03-09 20:11:23 +01:00
|
|
|
# CLang is needed on Darwin for -fllvm to work:
|
|
|
|
# https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/code-generators.html
|
2016-04-13 14:53:51 +02:00
|
|
|
llvm = lib.makeBinPath
|
2015-03-09 20:11:23 +01:00
|
|
|
([ llvmPackages.llvm ]
|
2015-03-29 04:24:35 +02:00
|
|
|
++ lib.optional stdenv.isDarwin llvmPackages.clang);
|
2015-01-07 20:31:32 +01:00
|
|
|
in
|
2015-03-09 20:11:23 +01:00
|
|
|
if paths == [] && !withLLVM then ghc else
|
2015-01-10 09:12:37 +01:00
|
|
|
buildEnv {
|
2016-11-16 13:45:59 +01:00
|
|
|
# this makes computing paths from the name attribute impossible;
|
|
|
|
# if such a feature is needed, the real compiler name should be saved
|
|
|
|
# as a dedicated drv attribute, like `compiler-name`
|
|
|
|
name = ghc.name + "-with-packages";
|
2015-01-10 09:12:37 +01:00
|
|
|
paths = paths ++ [ghc];
|
2015-01-07 20:31:32 +01:00
|
|
|
inherit ignoreCollisions;
|
|
|
|
postBuild = ''
|
|
|
|
. ${makeWrapper}/nix-support/setup-hook
|
|
|
|
|
2015-01-09 19:38:10 +01:00
|
|
|
if test -L "$out/bin"; then
|
|
|
|
binTarget="$(readlink -f "$out/bin")"
|
|
|
|
rm "$out/bin"
|
|
|
|
cp -r "$binTarget" "$out/bin"
|
|
|
|
chmod u+w "$out/bin"
|
|
|
|
fi
|
|
|
|
|
2015-05-06 21:56:02 +02:00
|
|
|
for prg in ${ghcCommand} ${ghcCommand}i ${ghcCommand}-${ghc.version} ${ghcCommand}i-${ghc.version}; do
|
|
|
|
if [[ -x "${ghc}/bin/$prg" ]]; then
|
|
|
|
rm -f $out/bin/$prg
|
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
|
|
|
|
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
|
|
|
|
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
|
|
|
|
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
|
|
|
|
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
|
|
|
|
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}" \
|
|
|
|
${lib.optionalString withLLVM ''--prefix "PATH" ":" "${llvm}"''}
|
|
|
|
fi
|
2015-01-07 20:31:32 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
for prg in runghc runhaskell; do
|
2015-05-06 21:56:02 +02:00
|
|
|
if [[ -x "${ghc}/bin/$prg" ]]; then
|
|
|
|
rm -f $out/bin/$prg
|
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
|
|
|
|
--add-flags "-f $out/bin/${ghcCommand}" \
|
|
|
|
--set "NIX_${ghcCommandCaps}" "$out/bin/${ghcCommand}" \
|
|
|
|
--set "NIX_${ghcCommandCaps}PKG" "$out/bin/${ghcCommand}-pkg" \
|
|
|
|
--set "NIX_${ghcCommandCaps}_DOCDIR" "${docDir}" \
|
|
|
|
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
|
|
|
|
fi
|
2015-01-07 20:31:32 +01:00
|
|
|
done
|
|
|
|
|
2015-03-13 04:20:56 +01:00
|
|
|
for prg in ${ghcCommand}-pkg ${ghcCommand}-pkg-${ghc.version}; do
|
2015-05-06 21:56:02 +02:00
|
|
|
if [[ -x "${ghc}/bin/$prg" ]]; then
|
|
|
|
rm -f $out/bin/$prg
|
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "${packageDBFlag}=${packageCfgDir}"
|
|
|
|
fi
|
2015-01-07 20:31:32 +01:00
|
|
|
done
|
|
|
|
|
2015-03-29 04:24:35 +02:00
|
|
|
${lib.optionalString hasLibraries "$out/bin/${ghcCommand}-pkg recache"}
|
2015-03-13 04:20:56 +01:00
|
|
|
$out/bin/${ghcCommand}-pkg check
|
2015-04-28 13:14:05 +02:00
|
|
|
'' + postBuild;
|
2015-01-23 00:10:08 +01:00
|
|
|
passthru = {
|
|
|
|
preferLocalBuild = true;
|
|
|
|
inherit (ghc) version meta;
|
|
|
|
inherit haskellPackages;
|
|
|
|
};
|
2015-01-10 09:12:37 +01:00
|
|
|
}
|