From 0f5976b599d915eca2f3ddda089237f80d3cf338 Mon Sep 17 00:00:00 2001
From: Andres Loeh <mail@andres-loeh.de>
Date: Sun, 16 Dec 2012 17:25:15 +0100
Subject: [PATCH] ghc-paths: Fix patch to hopefully work with older GHCs.

---
 .../haskell/ghc-paths/ghc-paths-nix.patch     | 23 ++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch b/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch
index 0b09f1fcf2e6..b3c75a26a035 100644
--- a/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch
+++ b/pkgs/development/libraries/haskell/ghc-paths/ghc-paths-nix.patch
@@ -1,19 +1,30 @@
 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-paths-0.1.0.9-new/GHC/Paths.hs	2012-12-16 17:22:12.765576568 +0100
+@@ -1,13 +1,35 @@
+ {-# LANGUAGE CPP #-}
++{-# LANGUAGE ScopedTypeVariables #-}
+ 
+ module GHC.Paths (
          ghc, ghc_pkg, libdir, docdir
    ) where
  
++import Control.Exception as E
 +import Data.Maybe
 +import System.Environment
 +import System.IO.Unsafe
 +
++-- Yes, there's lookupEnv now, but we want to be compatible
++-- with older GHCs.
++checkEnv :: String -> IO (Maybe String)
++checkEnv var = E.catch (fmap Just (getEnv var))
++                       (\ (e :: IOException) -> return Nothing)
++
 +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")
++nixLibdir = unsafePerformIO (checkEnv "NIX_GHC_LIBDIR")
++nixDocdir = unsafePerformIO (checkEnv "NIX_GHC_DOCDIR")
++nixGhc    = unsafePerformIO (checkEnv "NIX_GHC")
++nixGhcPkg = unsafePerformIO (checkEnv "NIX_GHCPKG")
 +{-# NOINLINE nixLibdir #-}
 +{-# NOINLINE nixDocdir #-}
 +{-# NOINLINE nixGhc    #-}