@@ -31,8 +31,11 @@ import CmdLineParser
3131import DynFlags
3232import Panic
3333import GHC
34−import GHC.Paths
34+import qualified GHC.Paths
3535
36+-- Set the GHC libdir to the nix libdir if it's present.
37+getLibdir :: IO FilePath
38+getLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"
3639
3740main :: IO ()
3841main = do
@@ -78,7 +81,7 @@ showEvent lock e = withLock lock $ print e
7881
7982-- | Create a GHC session that will be subsequently reused.
8083newSession :: [String] -> IO HscEnv
81−newSession flags = runGhc (Just libdir) $ do
84+newSession flags = getLibdir >>= \libdir -> runGhc (Just libdir) $ do
8285 damlDFlags <- getSessionDynFlags
8386 (dflags', leftover, warns) <- parseDynamicFlagsCmdLine damlDFlags $ map noLoc flags
8487