From d068aa986167abcbf1b25f439b74136b4060f2fd Mon Sep 17 00:00:00 2001 From: Andres Loeh Date: Sun, 16 Dec 2012 14:15:04 +0100 Subject: [PATCH] Patch ghc-paths to interact better with ghcWithPackages. 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. --- .../compilers/ghc/with-packages.nix | 7 +++- .../libraries/haskell/ghc-paths/default.nix | 1 + .../haskell/ghc-paths/ghc-paths-nix.patch | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch diff --git a/pkgs/development/compilers/ghc/with-packages.nix b/pkgs/development/compilers/ghc/with-packages.nix index f4f567f30b39..07071ef8414a 100644 --- a/pkgs/development/compilers/ghc/with-packages.nix +++ b/pkgs/development/compilers/ghc/with-packages.nix @@ -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 diff --git a/pkgs/development/libraries/haskell/ghc-paths/default.nix b/pkgs/development/libraries/haskell/ghc-paths/default.nix index 9d63c04514b4..b930e993dcc4 100644 --- a/pkgs/development/libraries/haskell/ghc-paths/default.nix +++ b/pkgs/development/libraries/haskell/ghc-paths/default.nix @@ -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; diff --git a/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch b/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch new file mode 100644 index 000000000000..0b09f1fcf2e6 --- /dev/null +++ b/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