2013-10-26 17:33:09 +01:00
|
|
|
{ stdenv, ghc, makeWrapper, coreutils, writeScript }:
|
2009-04-18 13:47:11 +01:00
|
|
|
|
2012-09-13 13:51:27 +01:00
|
|
|
let
|
|
|
|
ghc761OrLater = !stdenv.lib.versionOlder ghc.version "7.6.1";
|
|
|
|
packageDBFlag = if ghc761OrLater then "-package-db" else "-package-conf";
|
2013-10-26 17:33:09 +01:00
|
|
|
|
|
|
|
GHCGetPackages = writeScript "ghc-get-packages.sh" ''
|
|
|
|
#! ${stdenv.shell}
|
|
|
|
# Usage:
|
|
|
|
# $1: version of GHC
|
|
|
|
# $2: invocation path of GHC
|
|
|
|
# $3: prefix
|
|
|
|
version="$1"
|
|
|
|
if test -z "$3"; then
|
|
|
|
prefix="${packageDBFlag} "
|
|
|
|
else
|
|
|
|
prefix="$3"
|
|
|
|
fi
|
|
|
|
PATH="$2:$PATH"
|
|
|
|
IFS=":"
|
|
|
|
for p in $PATH; do
|
|
|
|
PkgDir="$p/../lib/ghc-$version/package.conf.d"
|
|
|
|
for i in "$PkgDir/"*.installedconf; do
|
|
|
|
# output takes place here
|
|
|
|
test -f $i && echo -n " $prefix$i"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
test -f "$2/../lib/ghc-$version/package.conf" && echo -n " $prefix$2/../lib/ghc-$version/package.conf"
|
|
|
|
'';
|
|
|
|
|
|
|
|
GHCPackages = writeScript "ghc-packages.sh" ''
|
|
|
|
#! ${stdenv.shell} -e
|
|
|
|
declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths
|
|
|
|
|
|
|
|
for arg in $(${GHCGetPackages} ${ghc.version} "$(dirname $0)"); do
|
|
|
|
case "$arg" in
|
|
|
|
${packageDBFlag}) ;;
|
|
|
|
*)
|
|
|
|
CANONICALIZED="$(${coreutils}/bin/readlink -f -- "$arg")"
|
|
|
|
GHC_PACKAGES_HASH["$CANONICALIZED"]= ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
for path in ''${!GHC_PACKAGES_HASH[@]}; do
|
|
|
|
echo -n "$path:"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2012-09-13 13:51:27 +01:00
|
|
|
in
|
2013-10-26 17:33:09 +01:00
|
|
|
stdenv.mkDerivation {
|
2009-04-25 15:23:00 +01:00
|
|
|
name = "ghc-${ghc.version}-wrapper";
|
2009-04-18 13:47:11 +01:00
|
|
|
|
2009-04-25 15:23:00 +01:00
|
|
|
buildInputs = [makeWrapper];
|
2009-04-18 13:47:11 +01:00
|
|
|
propagatedBuildInputs = [ghc];
|
|
|
|
|
|
|
|
unpackPhase = "true";
|
2009-04-25 15:23:00 +01:00
|
|
|
installPhase = ''
|
2013-10-26 17:33:09 +01:00
|
|
|
runHook preInstall
|
|
|
|
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $out/bin
|
2009-05-28 20:06:29 +01:00
|
|
|
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
|
2013-10-26 17:33:09 +01:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\")"
|
2009-04-25 15:23:00 +01:00
|
|
|
done
|
2009-05-28 20:06:29 +01:00
|
|
|
for prg in runghc runhaskell; do
|
2013-10-26 17:33:09 +01:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\" \" ${packageDBFlag} --ghc-arg=\")"
|
2009-05-28 20:06:29 +01:00
|
|
|
done
|
2009-04-25 15:23:00 +01:00
|
|
|
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
|
2013-10-26 17:33:09 +01:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\" -${packageDBFlag}=)"
|
2009-04-25 15:23:00 +01:00
|
|
|
done
|
2010-04-29 18:35:05 +01:00
|
|
|
for prg in hp2ps hpc hasktags hsc2hs; do
|
|
|
|
test -x $ghc/bin/$prg && ln -s $ghc/bin/$prg $out/bin/$prg
|
|
|
|
done
|
2009-07-27 17:05:44 +01:00
|
|
|
|
2012-01-18 20:16:00 +00:00
|
|
|
mkdir -p $out/nix-support
|
2009-04-25 15:23:00 +01:00
|
|
|
ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
|
2011-08-16 14:03:38 +01:00
|
|
|
|
2013-10-26 17:33:09 +01:00
|
|
|
mkdir -p $out/share/doc
|
|
|
|
ln -s $ghc/lib $out/lib
|
|
|
|
ln -s $ghc/share/doc/ghc $out/share/doc/ghc-${ghc.version}
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2009-04-18 13:47:11 +01:00
|
|
|
|
2013-10-26 17:33:09 +01:00
|
|
|
inherit ghc GHCGetPackages GHCPackages;
|
|
|
|
inherit (ghc) meta version;
|
|
|
|
}
|