From 66f3af0bdd87c8f3029aefcd3dd8f069cdbff5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andres=20L=C3=B6h?= Date: Sat, 25 Apr 2009 14:23:00 +0000 Subject: [PATCH] ghc-wrapper now detects installed pkgs automatically. svn path=/nixpkgs/trunk/; revision=15301 --- .../compilers/ghc/ghc-get-packages.sh | 21 +++++++++++++++++++ pkgs/development/compilers/ghc/setup-hook.sh | 17 --------------- pkgs/development/compilers/ghc/wrapper.nix | 21 +++++++++++++++---- .../libraries/haskell/cabal/cabal.nix | 10 ++++++++- pkgs/top-level/haskell-packages.nix | 4 ++-- 5 files changed, 49 insertions(+), 24 deletions(-) create mode 100755 pkgs/development/compilers/ghc/ghc-get-packages.sh delete mode 100644 pkgs/development/compilers/ghc/setup-hook.sh 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/setup-hook.sh b/pkgs/development/compilers/ghc/setup-hook.sh deleted file mode 100644 index 11ad50a0c796..000000000000 --- a/pkgs/development/compilers/ghc/setup-hook.sh +++ /dev/null @@ -1,17 +0,0 @@ -# Create isolated package config -packages_db=$TMPDIR/.package.conf -cp @ghc@/lib/ghc-*/package.conf $packages_db -chmod u+w $packages_db - -export GHC_PACKAGE_PATH=$packages_db - -# Env hook to add packages to the package config -addLibToPackageConf () { - local fn - shopt -s nullglob - for fn in $1/lib/ghc-pkgs/ghc-@ghcVersion@/*.conf; do - @ghc@/bin/ghc-pkg register --force $fn - done -} - -envHooks=(${envHooks[@]} addLibToPackageConf) 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; diff --git a/pkgs/development/libraries/haskell/cabal/cabal.nix b/pkgs/development/libraries/haskell/cabal/cabal.nix index c0dea9976839..c4ea86a4ac72 100644 --- a/pkgs/development/libraries/haskell/cabal/cabal.nix +++ b/pkgs/development/libraries/haskell/cabal/cabal.nix @@ -68,9 +68,17 @@ attrs : ./Setup copy + ensureDir $out/bin # necessary to get it added to PATH + local confDir=$out/lib/ghc-pkgs/ghc-${attrs.ghc.ghc.version} + local installedPkgConf=$confDir/${self.fname}.installedconf + local pkgConf=$confDir/${self.fname}.conf ensureDir $confDir - ./Setup register --gen-pkg-config=$confDir/${self.fname}.conf + ./Setup register --gen-pkg-config=$pkgConf + if test -f $pkgConf; then + echo '[]' > $installedPkgConf + GHC_PACKAGE_PATH=$installedPkgConf ghc-pkg --global register $pkgConf --force + fi ensureDir $out/nix-support ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index ffbf72e21fd7..a10da675ae59 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -1,6 +1,6 @@ {pkgs, ghc}: -let ghcReal = ghc; in +let ghcReal = pkgs.lowPrio ghc; in rec { @@ -11,7 +11,7 @@ rec { # wrapper provides essential functionality: the ability to find # Haskell packages in the buildInputs automatically. ghc = import ../development/compilers/ghc/wrapper.nix { - inherit (pkgs) stdenv; + inherit (pkgs) stdenv makeWrapper; ghc = ghcReal; };