about summary refs log tree commit diff
path: root/pkgs/development/compilers/ghc
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/ghc')
-rwxr-xr-xpkgs/development/compilers/ghc/ghc-get-packages.sh21
-rw-r--r--pkgs/development/compilers/ghc/wrapper.nix21
2 files changed, 38 insertions, 4 deletions
diff --git a/pkgs/development/compilers/ghc/ghc-get-packages.sh b/pkgs/development/compilers/ghc/ghc-get-packages.sh
new file mode 100755
index 000000000000..4593ead17d31
--- /dev/null
+++ b/pkgs/development/compilers/ghc/ghc-get-packages.sh
@@ -0,0 +1,21 @@
+#! /bin/sh
+# Usage:
+#  $1: version of GHC
+#  $2: invocation path of GHC
+#  $3: prefix
+version="$1"
+if test -z "$3"; then
+  prefix="-package-conf "
+else
+  prefix="$3"
+fi
+PATH="$2:$PATH"
+IFS=":"
+PKGS=""
+for p in $PATH; do
+  PkgDir="$p/../lib/ghc-pkgs/ghc-$version"
+  for i in $PkgDir/*.installedconf; do
+    test -f $i && PKGS="$PKGS $prefix$i"
+  done
+done
+echo $PKGS
diff --git a/pkgs/development/compilers/ghc/wrapper.nix b/pkgs/development/compilers/ghc/wrapper.nix
index 932cf6343018..5cacfdf8f894 100644
--- a/pkgs/development/compilers/ghc/wrapper.nix
+++ b/pkgs/development/compilers/ghc/wrapper.nix
@@ -1,14 +1,27 @@
-{stdenv, ghc}:
+{stdenv, ghc, makeWrapper}:
 
 stdenv.mkDerivation {
-  name = "ghc-wrapper-${ghc.version}";
+  name = "ghc-${ghc.version}-wrapper";
 
+  buildInputs = [makeWrapper];
   propagatedBuildInputs = [ghc];
 
   unpackPhase = "true";
-  installPhase = "true";
+  installPhase = ''
+    ensureDir $out/bin
+    cp $GHCGetPackages $out/bin/ghc-get-packages.sh
+    chmod 755 $out/bin/ghc-get-packages.sh
+    for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version} runghc runhaskell; do
+      makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\")"
+    done
+    for prg in ghc-pkg ghc-pkg-${ghc.version}; do
+      makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" --package-conf=)"
+    done
+    ensureDir $out/nix-support
+    ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
+  ''; 
   
-  setupHook = ./setup-hook.sh;
+  GHCGetPackages = ./ghc-get-packages.sh;
 
   inherit ghc;
   ghcVersion = ghc.version;