Skip to content

Commit

Permalink
Patch ghc-paths to interact better with ghcWithPackages.
Browse files Browse the repository at this point in the history
When the ghc-paths library is compiled, the paths of the
compiler it is compiled with are being hardcoded in the
library (and can then be queried from other applications
using the library).

But on Nix, packages are compiled with ghc-wrapper, and
subsequently possibly used with a special version of ghc
generated for a particular environment of packages. So
one version of ghc-paths may potentially end up being
used by lots of different instances of ghc. The hardcoding
approach fails.

As a work-around, we now patch ghc-paths so that it allows
setting the paths that can be queried via environment
variables. Specific GHC environments can then set these
environment variables in the wrapper shell script that
invokes GHC.

This should at least partially solve issue #213.
  • Loading branch information
kosmikus committed Dec 16, 2012
1 parent e89aea5 commit d068aa9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkgs/development/compilers/ghc/with-packages.nix
Expand Up @@ -79,7 +79,12 @@ stdenv.mkDerivation rec {
echo -n "Generating wrappers "
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
makeWrapper ${ghc}/bin/$prg $out/bin/$prg --add-flags "-B$linkedTopDir"
# 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"
echo -n .
done
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/libraries/haskell/ghc-paths/default.nix
Expand Up @@ -4,6 +4,7 @@ cabal.mkDerivation (self: {
pname = "ghc-paths";
version = "0.1.0.9";
sha256 = "0ibrr1dxa35xx20cpp8jzgfak1rdmy344dfwq4vlq013c6w8z9mg";
patches = [ ./ghc-paths-nix.patch ];
meta = {
description = "Knowledge of GHC's installation directories";
license = self.stdenv.lib.licenses.bsd3;
Expand Down
32 changes: 32 additions & 0 deletions pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch
@@ -0,0 +1,32 @@
diff -Naur ghc-paths-0.1.0.9/GHC/Paths.hs ghc-paths-0.1.0.9-new/GHC/Paths.hs
--- ghc-paths-0.1.0.9/GHC/Paths.hs 2012-12-16 13:53:45.720148396 +0100
+++ ghc-paths-0.1.0.9-new/GHC/Paths.hs 2012-12-16 13:51:50.073070123 +0100
@@ -4,10 +4,24 @@
ghc, ghc_pkg, libdir, docdir
) where

+import Data.Maybe
+import System.Environment
+import System.IO.Unsafe
+
+nixLibdir, nixDocdir, nixGhc, nixGhcPkg :: Maybe FilePath
+nixLibdir = unsafePerformIO (lookupEnv "NIX_GHC_LIBDIR")
+nixDocdir = unsafePerformIO (lookupEnv "NIX_GHC_DOCDIR")
+nixGhc = unsafePerformIO (lookupEnv "NIX_GHC")
+nixGhcPkg = unsafePerformIO (lookupEnv "NIX_GHCPKG")
+{-# NOINLINE nixLibdir #-}
+{-# NOINLINE nixDocdir #-}
+{-# NOINLINE nixGhc #-}
+{-# NOINLINE nixGhcPkg #-}
+
libdir, docdir, ghc, ghc_pkg :: FilePath

-libdir = GHC_PATHS_LIBDIR
-docdir = GHC_PATHS_DOCDIR
+libdir = fromMaybe GHC_PATHS_LIBDIR nixLibdir
+docdir = fromMaybe GHC_PATHS_DOCDIR nixDocdir

-ghc = GHC_PATHS_GHC
-ghc_pkg = GHC_PATHS_GHC_PKG
+ghc = fromMaybe GHC_PATHS_GHC nixGhc
+ghc_pkg = fromMaybe GHC_PATHS_GHC_PKG nixGhcPkg

1 comment on commit d068aa9

@aristidb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical problem: "GHC/Paths.hs:12:30: Not in scope: `lookupEnv'"

Please sign in to comment.