{-# LANGUAGE TemplateHaskell #-}
module ReWire.GHC.PackagePath (bakedPackagePath) where
import Control.Exception (SomeException, try)
import Data.Char (isSpace)
import Data.List (dropWhileEnd)
import Language.Haskell.TH.Syntax (lift, runIO)
import System.Process (readProcess)
bakedPackagePath :: Maybe FilePath
bakedPackagePath :: Maybe FilePath
bakedPackagePath = $( runIO ( either (const Nothing)
( (\ p -> if null p then Nothing else Just p)
. dropWhileEnd isSpace . dropWhile isSpace )
<$> (try (readProcess "stack" ["path", "--ghc-package-path"] "")
:: IO (Either SomeException String)) )
>>= lift )