Skip to content

Commit 99f7fa8

Browse files
Yves ParèsYPares
authored andcommitted
Added config parsing for nix-shell execution environment
1 parent 2efbc9a commit 99f7fa8

9 files changed

Lines changed: 1165 additions & 1 deletion

File tree

src/Stack/Config.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Safe (headMay)
6868
import Stack.BuildPlan
6969
import Stack.Constants
7070
import Stack.Config.Docker
71+
import Stack.Config.ExecEnv
7172
import qualified Stack.Image as Image
7273
import Stack.Init
7374
import Stack.Types
@@ -143,6 +144,7 @@ configFromConfigMonoid configStackRoot configUserConfigPath mproject configMonoi
143144
configCompilerCheck = fromMaybe MatchMinor configMonoidCompilerCheck
144145

145146
configDocker <- dockerOptsFromMonoid mproject configStackRoot configMonoidDockerOpts
147+
configExecEnv <- execEnvOptsFromMonoid mproject configStackRoot configMonoidExecEnvOpts
146148

147149
rawEnv <- liftIO getEnvironment
148150
origEnv <- mkEnvOverride configPlatform

src/Stack/Config/ExecEnv.hs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards, TemplateHaskell #-}
2+
3+
-- | Docker configuration
4+
module Stack.Config.ExecEnv where
5+
6+
import Control.Exception.Lifted
7+
import Control.Monad
8+
import Control.Monad.Catch (throwM, MonadThrow)
9+
import Data.List (find)
10+
import Data.Maybe
11+
import qualified Data.Text as T
12+
import Data.Typeable (Typeable)
13+
import Path
14+
import Stack.Types
15+
16+
-- | Interprets DockerOptsMonoid options.
17+
execEnvOptsFromMonoid
18+
:: MonadThrow m
19+
=> Maybe Project -> Path Abs Dir -> ExecEnvOptsMonoid -> m ExecEnvOpts
20+
execEnvOptsFromMonoid mproject stackRoot ExecEnvOptsMonoid{..} = do
21+
let execEnvType =
22+
if fromMaybe execEnvMonoidDefaultEnable execEnvMonoidEnable
23+
then Just NixShellExecEnv
24+
else Nothing
25+
execEnvPackages = execEnvMonoidPackages
26+
{- dockerContainerName = emptyToNothing dockerMonoidContainerName
27+
dockerRunArgs = dockerMonoidRunArgs
28+
dockerMount = dockerMonoidMount
29+
dockerEnv = dockerMonoidEnv
30+
dockerDatabasePath <-
31+
case dockerMonoidDatabasePath of
32+
Nothing -> return $ stackRoot </> $(mkRelFile "docker.db")
33+
Just fp ->
34+
case parseAbsFile fp of
35+
Left e -> throwM (InvalidDatabasePathException e)
36+
Right p -> return p
37+
dockerStackExe <-
38+
case dockerMonoidStackExe of
39+
Just e -> liftM Just (parseDockerStackExe e)
40+
Nothing -> return Nothing -}
41+
return ExecEnvOpts{..}
42+
43+
{- where emptyToNothing Nothing = Nothing
44+
emptyToNothing (Just s) | null s = Nothing
45+
| otherwise = Just s
46+
47+
-- | Exceptions thrown by Stack.Docker.Config.
48+
data StackNixConfigException
49+
= ResolverNotSupportedException String
50+
-- ^ Only LTS resolvers are supported for default image tag.
51+
| InvalidDatabasePathException SomeException
52+
-- ^ Invalid global database path.
53+
deriving (Typeable)
54+
55+
-- | Exception instance for StackDockerConfigException.
56+
instance Exception StackDockerConfigException
57+
58+
-- | Show instance for StackDockerConfigException.
59+
instance Show StackDockerConfigException where
60+
show (ResolverNotSupportedException resolver) =
61+
concat
62+
[ "Resolver not supported for Docker images:\n "
63+
, resolver
64+
, "\nUse an LTS resolver, or set the '"
65+
, T.unpack dockerImageArgName
66+
, "' explicitly, in your configuration file."]
67+
show (InvalidDatabasePathException ex) =
68+
concat ["Invalid database path: ", show ex]
69+
-}

0 commit comments

Comments
 (0)