@@ -14,7 +14,7 @@ module Stack.Nix
1414import Control.Applicative
1515import Control.Arrow ((***) )
1616import Control.Exception (Exception ,throw )
17- import Control.Monad
17+ import Control.Monad hiding ( mapM )
1818import Control.Monad.Catch (try ,MonadCatch )
1919import Control.Monad.IO.Class (MonadIO ,liftIO )
2020import Control.Monad.Logger (MonadLogger ,logDebug )
@@ -33,8 +33,9 @@ import Network.HTTP.Client.Conduit (HasHttpManager)
3333import Path
3434import Path.IO
3535import qualified Paths_stack as Meta
36- import Prelude -- Fix redundant import warnings
36+ import Prelude hiding ( mapM ) -- Fix redundant import warnings
3737import Stack.Constants (stackProgName ,platformVariantEnvVar )
38+ import Stack.Config (makeConcreteResolver )
3839import Stack.Docker (reExecArgName )
3940import Stack.Exec (exec )
4041import System.Process.Read (getEnvOverride )
@@ -43,20 +44,21 @@ import Stack.Types.Internal
4344import System.Environment (lookupEnv ,getArgs ,getExecutablePath )
4445import System.Exit (exitSuccess , exitWith )
4546
46-
4747-- | If Nix is enabled, re-runs the currently running OS command in a Nix container.
4848-- Otherwise, runs the inner action.
4949reexecWithOptionalShell
5050 :: M env m
5151 => Maybe (Path Abs Dir )
52+ -> Maybe AbstractResolver
53+ -> Maybe CompilerVersion
5254 -> IO ()
5355 -> m ()
54- reexecWithOptionalShell mprojectRoot inner =
56+ reexecWithOptionalShell mprojectRoot maresolver mcompiler inner =
5557 do config <- asks getConfig
5658 inShell <- getInShell
5759 isReExec <- asks getReExec
5860 if nixEnable (configNix config) && not inShell && not isReExec
59- then runShellAndExit mprojectRoot getCmdArgs
61+ then runShellAndExit mprojectRoot maresolver mcompiler getCmdArgs
6062 else liftIO inner
6163 where
6264 getCmdArgs = do
@@ -70,30 +72,34 @@ reexecWithOptionalShell mprojectRoot inner =
7072runShellAndExit
7173 :: M env m
7274 => Maybe (Path Abs Dir )
75+ -> Maybe AbstractResolver
76+ -> Maybe CompilerVersion
7377 -> m (String , [String ])
7478 -> m ()
75- runShellAndExit mprojectRoot getCmdArgs = do
79+ runShellAndExit mprojectRoot maresolver mcompiler getCmdArgs = do
7680 config <- asks getConfig
81+ mresolver <- mapM makeConcreteResolver maresolver
7782 envOverride <- getEnvOverride (configPlatform config)
7883 (cmnd,args) <- fmap (escape *** map escape) getCmdArgs
7984 mshellFile <-
8085 traverse (resolveFile (fromMaybeProjectRoot mprojectRoot)) $
8186 nixInitFile (configNix config)
8287 let pkgsInConfig = nixPackages (configNix config)
88+ pkgs = pkgsInConfig ++ [nixCompiler (configNix config) mresolver mcompiler]
8389 pureShell = nixPureShell (configNix config)
8490 nixopts = case mshellFile of
8591 Just fp -> [toFilePath fp]
8692 Nothing -> [" -E" , T. unpack $ T. intercalate " " $ concat
8793 [[" with (import <nixpkgs> {});"
8894 ," runCommand \" myEnv\" {"
89- ," buildInputs=lib.optional stdenv.isLinux glibcLocales ++ [" ],pkgsInConfig ,[" ];"
95+ ," buildInputs=lib.optional stdenv.isLinux glibcLocales ++ [" ],pkgs ,[" ];"
9096 ,T. pack platformVariantEnvVar <> " =''nix'';"
9197 ,T. pack inShellEnvVar <> " =1;"
9298 ," STACK_IN_NIX_EXTRA_ARGS=''" ]
9399 , (map (\ p -> T. concat
94100 [" --extra-lib-dirs=${" ,p," }/lib"
95101 ," --extra-include-dirs=${" ,p," }/include " ])
96- pkgsInConfig ), [" '' ;"
102+ pkgs ), [" '' ;"
97103 ," } \"\" " ]]]
98104 -- glibcLocales is necessary on Linux to avoid warnings about GHC being incapable to set the locale.
99105 fullArgs = concat [if pureShell then [" --pure" ] else [] ,
@@ -105,7 +111,7 @@ runShellAndExit mprojectRoot getCmdArgs = do
105111 $ logDebug $
106112 " Using a nix-shell environment " <> (case mshellFile of
107113 Just path -> " from file: " <> (T. pack (toFilePath path))
108- Nothing -> " with nix packages: " <> (T. intercalate " , " pkgsInConfig ))
114+ Nothing -> " with nix packages: " <> (T. intercalate " , " pkgs ))
109115 e <- try (exec envOverride " nix-shell" fullArgs)
110116 case e of
111117 Left (ProcessExitedUnsuccessfully _ ec) -> liftIO (exitWith ec)
0 commit comments