summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/patches/ghc-paths-nix-ghcjs.patch
blob: 48cf6a035afb39bcf76aced04ecd73675d76cdde (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
diff --git a/GHC/Paths.hs b/GHC/Paths.hs
index c87565d..88b3db4 100644
--- a/GHC/Paths.hs
+++ b/GHC/Paths.hs
@@ -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 (checkEnv "NIX_GHCJS_LIBDIR")
+nixDocdir = unsafePerformIO (checkEnv "NIX_GHCJS_DOCDIR")
+nixGhc    = unsafePerformIO (checkEnv "NIX_GHCJS")
+nixGhcPkg = unsafePerformIO (checkEnv "NIX_GHCJSPKG")
+{-# 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
diff --git a/Setup.hs b/Setup.hs
index f2d1733..ca4792e 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -39,13 +39,13 @@ main = defaultMainWithHooks simpleUserHooks {
 #else
       libdir_ <- rawSystemProgramStdoutConf (fromFlag (configVerbosity flags))
 #endif
-                     ghcProgram (withPrograms lbi) ["--print-libdir"]
+                     ghcjsProgram (withPrograms lbi) ["--print-libdir"]
       let libdir = reverse $ dropWhile isSpace $ reverse libdir_
 
-          ghc_pkg = case lookupProgram ghcPkgProgram (withPrograms lbi) of
+          ghc_pkg = case lookupProgram ghcjsPkgProgram (withPrograms lbi) of
                           Just p  -> programPath p
                           Nothing -> error "ghc-pkg was not found"
-          ghc     = case lookupProgram ghcProgram (withPrograms lbi) of
+          ghc     = case lookupProgram ghcjsProgram (withPrograms lbi) of
                           Just p  -> programPath p
                           Nothing -> error "ghc was not found"