1 diff --git a/GHC/Paths.hs b/GHC/Paths.hs
2 index c87565d..88b3db4 100644
7 +{-# LANGUAGE ScopedTypeVariables #-}
10 ghc, ghc_pkg, libdir, docdir
13 +import Control.Exception as E
15 +import System.Environment
16 +import System.IO.Unsafe
18 +-- Yes, there's lookupEnv now, but we want to be compatible
20 +checkEnv :: String -> IO (Maybe String)
21 +checkEnv var = E.catch (fmap Just (getEnv var))
22 + (\ (e :: IOException) -> return Nothing)
24 +nixLibdir, nixDocdir, nixGhc, nixGhcPkg :: Maybe FilePath
25 +nixLibdir = unsafePerformIO (checkEnv "NIX_GHCJS_LIBDIR")
26 +nixDocdir = unsafePerformIO (checkEnv "NIX_GHCJS_DOCDIR")
27 +nixGhc = unsafePerformIO (checkEnv "NIX_GHCJS")
28 +nixGhcPkg = unsafePerformIO (checkEnv "NIX_GHCJSPKG")
29 +{-# NOINLINE nixLibdir #-}
30 +{-# NOINLINE nixDocdir #-}
31 +{-# NOINLINE nixGhc #-}
32 +{-# NOINLINE nixGhcPkg #-}
34 libdir, docdir, ghc, ghc_pkg :: FilePath
36 -libdir = GHC_PATHS_LIBDIR
37 -docdir = GHC_PATHS_DOCDIR
38 +libdir = fromMaybe GHC_PATHS_LIBDIR nixLibdir
39 +docdir = fromMaybe GHC_PATHS_DOCDIR nixDocdir
42 -ghc_pkg = GHC_PATHS_GHC_PKG
43 +ghc = fromMaybe GHC_PATHS_GHC nixGhc
44 +ghc_pkg = fromMaybe GHC_PATHS_GHC_PKG nixGhcPkg
45 diff --git a/Setup.hs b/Setup.hs
46 index f2d1733..ca4792e 100644
49 @@ -39,13 +39,13 @@ main = defaultMainWithHooks simpleUserHooks {
51 libdir_ <- rawSystemProgramStdoutConf (fromFlag (configVerbosity flags))
53 - ghcProgram (withPrograms lbi) ["--print-libdir"]
54 + ghcjsProgram (withPrograms lbi) ["--print-libdir"]
55 let libdir = reverse $ dropWhile isSpace $ reverse libdir_
57 - ghc_pkg = case lookupProgram ghcPkgProgram (withPrograms lbi) of
58 + ghc_pkg = case lookupProgram ghcjsPkgProgram (withPrograms lbi) of
59 Just p -> programPath p
60 Nothing -> error "ghc-pkg was not found"
61 - ghc = case lookupProgram ghcProgram (withPrograms lbi) of
62 + ghc = case lookupProgram ghcjsProgram (withPrograms lbi) of
63 Just p -> programPath p
64 Nothing -> error "ghc was not found"