2013-04-17 00:06:10 +02:00
|
|
|
{ stdenv, ghc, makeWrapper, coreutils, forUserEnv ? false }:
|
2009-04-18 14:47:11 +02:00
|
|
|
|
2012-09-13 14:51:27 +02:00
|
|
|
let
|
|
|
|
ghc761OrLater = !stdenv.lib.versionOlder ghc.version "7.6.1";
|
|
|
|
packageDBFlag = if ghc761OrLater then "-package-db" else "-package-conf";
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation ({
|
2009-04-25 16:23:00 +02:00
|
|
|
name = "ghc-${ghc.version}-wrapper";
|
2009-04-18 14:47:11 +02:00
|
|
|
|
2009-04-25 16:23:00 +02:00
|
|
|
buildInputs = [makeWrapper];
|
2009-04-18 14:47:11 +02:00
|
|
|
propagatedBuildInputs = [ghc];
|
|
|
|
|
|
|
|
unpackPhase = "true";
|
2009-04-25 16:23:00 +02:00
|
|
|
installPhase = ''
|
2012-01-18 21:16:00 +01:00
|
|
|
mkdir -p $out/bin
|
2009-04-25 16:23:00 +02:00
|
|
|
cp $GHCGetPackages $out/bin/ghc-get-packages.sh
|
|
|
|
chmod 755 $out/bin/ghc-get-packages.sh
|
2009-05-28 21:06:29 +02:00
|
|
|
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
|
2009-04-25 16:23:00 +02:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\")"
|
|
|
|
done
|
2009-05-28 21:06:29 +02:00
|
|
|
for prg in runghc runhaskell; do
|
2012-09-13 14:51:27 +02:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" \" ${packageDBFlag} --ghc-arg=\")"
|
2009-05-28 21:06:29 +02:00
|
|
|
done
|
2009-04-25 16:23:00 +02:00
|
|
|
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
|
2012-09-13 14:51:27 +02:00
|
|
|
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" -${packageDBFlag}=)"
|
2009-04-25 16:23:00 +02:00
|
|
|
done
|
2010-04-29 19:35:05 +02: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 18:05:44 +02:00
|
|
|
cat >> $out/bin/ghc-packages << EOF
|
|
|
|
#! /bin/bash -e
|
|
|
|
declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths
|
|
|
|
|
2009-11-12 08:11:03 +01:00
|
|
|
for arg in \$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\"); do
|
2009-07-27 18:05:44 +02:00
|
|
|
case "\$arg" in
|
2012-09-13 14:51:27 +02:00
|
|
|
${packageDBFlag}) ;;
|
2009-07-27 18:05:44 +02:00
|
|
|
*)
|
2012-03-23 12:26:28 +01:00
|
|
|
CANONICALIZED="\$(${stdenv.lib.optionalString stdenv.isDarwin "${coreutils}/bin/"}readlink -f "\$arg")"
|
2009-07-27 18:05:44 +02:00
|
|
|
GHC_PACKAGES_HASH["\$CANONICALIZED"]= ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
for path in \''${!GHC_PACKAGES_HASH[@]}; do
|
|
|
|
echo -n "\$path:"
|
|
|
|
done
|
|
|
|
EOF
|
|
|
|
chmod +x $out/bin/ghc-packages
|
2012-01-18 21:16:00 +01:00
|
|
|
mkdir -p $out/nix-support
|
2009-04-25 16:23:00 +02:00
|
|
|
ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
|
2011-08-16 15:03:38 +02:00
|
|
|
'';
|
|
|
|
|
2009-04-25 16:23:00 +02:00
|
|
|
GHCGetPackages = ./ghc-get-packages.sh;
|
2009-04-18 14:47:11 +02:00
|
|
|
|
|
|
|
inherit ghc;
|
2010-04-26 22:39:51 +02:00
|
|
|
inherit (ghc) meta;
|
2009-04-18 22:24:36 +02:00
|
|
|
ghcVersion = ghc.version;
|
2013-04-17 00:06:10 +02:00
|
|
|
} // (stdenv.lib.optionalAttrs ghc761OrLater { preFixup = "sed -i -e 's|-package-conf|${packageDBFlag}|' $out/bin/ghc-get-packages.sh"; })
|
|
|
|
// (stdenv.lib.optionalAttrs forUserEnv {
|
|
|
|
postFixup= ''
|
|
|
|
ln -s $ghc/lib $out/lib;
|
|
|
|
mkdir -p $out/share/doc
|
|
|
|
ln -s $ghc/share/doc/ghc $out/share/doc/ghc-${ghc.version}
|
|
|
|
'';
|
|
|
|
}))
|