2011-12-04 20:07:39 +04:00
|
|
|
{stdenv, ghc, packages ? [], makeWrapper}:
|
2011-12-03 20:19:43 +04:00
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2012-03-21 15:46:15 +04:00
|
|
|
name = "haskell-env-${ghc.name}";
|
2011-12-03 20:19:43 +04:00
|
|
|
|
|
|
|
allPackages = stdenv.lib.closePropagation packages;
|
|
|
|
buildInputs = allPackages ++ [makeWrapper];
|
|
|
|
propagatedBuildInputs = packages;
|
|
|
|
|
|
|
|
unpackPhase = "true";
|
|
|
|
|
|
|
|
installPhase = ''
|
2012-06-08 12:25:30 +04:00
|
|
|
numversion=$(${ghc}/bin/ghc --numeric-version)
|
|
|
|
majorversion=''${numversion%%.*}
|
|
|
|
minorversion=''${numversion#*.}
|
|
|
|
minorversion=''${minorversion%%.*}
|
|
|
|
|
|
|
|
if [[ $majorversion -gt 6 ]] && [[ $minorversion -gt 4 ]]; then
|
|
|
|
globalConf="--global-package-db"
|
|
|
|
else
|
|
|
|
globalConf="--global-conf"
|
|
|
|
fi
|
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
originalTopDir="${ghc}/lib/ghc-${ghc.version}"
|
2011-12-03 20:19:43 +04:00
|
|
|
originalPkgDir="$originalTopDir/package.conf.d"
|
|
|
|
linkedTopDir="$out/lib"
|
|
|
|
linkedPkgDir="$linkedTopDir/package.conf.d"
|
|
|
|
|
2012-01-19 00:16:00 +04:00
|
|
|
mkdir -p $out/bin
|
|
|
|
mkdir -p $linkedTopDir
|
|
|
|
mkdir -p $linkedPkgDir
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
echo "Linking GHC core libraries:"
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-11 21:19:36 +04:00
|
|
|
echo -n "Linking $originalTopDir "
|
2012-03-21 15:46:12 +04:00
|
|
|
for f in "$originalTopDir/"*; do
|
2011-12-11 21:19:36 +04:00
|
|
|
if test -f $f; then
|
|
|
|
ln -s $f $linkedTopDir
|
|
|
|
echo -n .
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
echo -n "Linking $originalPkgDir "
|
2012-03-21 15:46:12 +04:00
|
|
|
for f in "$originalPkgDir/"*.conf; do
|
2011-12-04 20:07:39 +04:00
|
|
|
ln -s $f $linkedPkgDir
|
|
|
|
echo -n .
|
2011-12-03 20:19:43 +04:00
|
|
|
done
|
2011-12-04 20:07:39 +04:00
|
|
|
echo
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
echo "Linking selected packages and dependencies:"
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
for currentPath in ${stdenv.lib.concatStringsSep " " allPackages}; do
|
|
|
|
currentPkgDir="$currentPath/lib/ghc-pkgs/ghc-${ghc.version}"
|
2011-12-04 21:45:12 +04:00
|
|
|
# Check if current path is a Cabal package for the current GHC
|
|
|
|
if test -d $currentPkgDir; then
|
|
|
|
echo -n "Linking $currentPath "
|
2012-03-21 15:46:12 +04:00
|
|
|
for f in "$currentPath/bin/"*; do
|
2011-12-04 21:45:12 +04:00
|
|
|
ln -s $f $out/bin
|
|
|
|
echo -n .
|
|
|
|
done
|
2012-09-25 17:05:49 +04:00
|
|
|
for f in "$currentPath/etc/bash_completion.d/"*; do
|
2013-03-15 22:58:08 +04:00
|
|
|
mkdir -p $out/etc/bash_completion.d
|
2012-09-25 17:05:49 +04:00
|
|
|
ln -s $f $out/etc/bash_completion.d/
|
|
|
|
echo -n .
|
|
|
|
done
|
2013-03-15 22:58:08 +04:00
|
|
|
for s in 1 2 3 4 5 6 7 8 9; do
|
|
|
|
for f in "$currentPath/share/man/man$s/"*; do
|
|
|
|
mkdir -p $out/share/man/man$s
|
2013-02-12 02:25:19 +04:00
|
|
|
ln -sv $f $out/share/man/man$s/
|
|
|
|
echo -n .
|
2013-03-15 22:58:08 +04:00
|
|
|
done
|
|
|
|
done
|
|
|
|
for f in "$currentPath/share/emacs/site-lisp/"*; do
|
|
|
|
mkdir -p $out/share/emacs/site-lisp
|
|
|
|
ln -s $f $out/share/emacs/site-lisp/
|
|
|
|
echo -n .
|
|
|
|
done
|
2013-08-08 17:43:45 +04:00
|
|
|
for f in "$currentPath/share/ghci/"*; do
|
|
|
|
mkdir -p $out/share/ghci
|
|
|
|
ln -s $f $out/share/ghci/
|
|
|
|
echo -n .
|
|
|
|
done
|
2012-03-21 15:46:12 +04:00
|
|
|
for f in "$currentPkgDir/"*.conf; do
|
2011-12-04 21:45:12 +04:00
|
|
|
ln -s $f $linkedPkgDir
|
|
|
|
echo -n .
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
2011-12-03 20:19:43 +04:00
|
|
|
done
|
|
|
|
|
2011-12-04 21:45:12 +04:00
|
|
|
echo -n "Generating package cache "
|
2012-06-08 12:25:30 +04:00
|
|
|
${ghc}/bin/ghc-pkg $globalConf $linkedPkgDir recache
|
2011-12-04 21:45:12 +04:00
|
|
|
echo .
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
echo -n "Generating wrappers "
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
|
2012-12-16 17:15:04 +04:00
|
|
|
# The NIX env-vars are picked up by our patched version of ghc-paths.
|
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
|
|
|
|
--add-flags "-B$linkedTopDir" \
|
|
|
|
--set "NIX_GHC" "$out/bin/ghc" \
|
|
|
|
--set "NIX_GHCPKG" "$out/bin/ghc-pkg" \
|
|
|
|
--set "NIX_GHC_LIBDIR" "$linkedTopDir"
|
2011-12-04 20:07:39 +04:00
|
|
|
echo -n .
|
|
|
|
done
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
for prg in runghc runhaskell; do
|
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "-f $out/bin/ghc"
|
|
|
|
echo -n .
|
2011-12-03 20:19:43 +04:00
|
|
|
done
|
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
|
2012-06-08 12:25:30 +04:00
|
|
|
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "$globalConf $linkedPkgDir"
|
2011-12-04 20:07:39 +04:00
|
|
|
echo -n .
|
|
|
|
done
|
2011-12-03 20:19:43 +04:00
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
for prg in hp2ps hpc hasktags hsc2hs haddock haddock-${ghc.version}; do
|
2011-12-04 21:45:12 +04:00
|
|
|
if test -x ${ghc}/bin/$prg -a ! -x $out/bin/$prg; then
|
|
|
|
ln -s ${ghc}/bin/$prg $out/bin/$prg && echo -n .
|
|
|
|
fi
|
2011-12-04 20:07:39 +04:00
|
|
|
done
|
|
|
|
echo
|
2011-12-03 20:19:43 +04:00
|
|
|
'';
|
|
|
|
|
2011-12-04 20:07:39 +04:00
|
|
|
meta = ghc.meta;
|
2011-12-03 20:19:43 +04:00
|
|
|
}
|