git.iko.soy/typeable/stackage2nix
on 596bf03 help sign in
78 lines 2.0 kB history raw
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE TemplateHaskell #-}
5module Stack.Config where
7import Control.Lens
8import Data.Coerce
9import Data.Maybe
10import Data.Text as T
11import Stack.Config.Yaml as Yaml
13newtype StackResolver = StackResolver { fromStackResolver :: Text }
14 deriving (Eq, Ord, Show)
16makePrisms ''StackResolver
18unStackResolver :: StackResolver -> String
19unStackResolver = T.unpack . fromStackResolver
21data RepoGit = RepoGit
22 { _rgUri :: Text
23 , _rgCommit :: Text
24 } deriving (Eq, Ord, Show)
26makeLenses ''RepoGit
28data StackLocation
29 = StackPath Text
30 | StackRepoGit RepoGit
31 deriving (Eq, Ord, Show)
33makePrisms ''StackLocation
35data StackPackage = StackPackage
36 { _spLocation :: StackLocation
37 , _spExtraDep :: Bool
38 } deriving (Eq, Ord, Show)
40makeLenses ''StackPackage
42newtype StackExtraDep = StackExtraDep { fromStackExtraDep :: Text }
43 deriving (Eq, Ord, Show)
45makePrisms ''StackExtraDep
47unExtraDep :: StackExtraDep -> String
48unExtraDep = T.unpack . fromStackExtraDep
50data StackConfig = StackConfig
51 { _scResolver :: StackResolver
52 , _scPackages :: [StackPackage]
53 , _scExtraDeps :: [StackExtraDep]
54 } deriving (Eq, Ord, Show)
56makeLenses ''StackConfig
58fromYamlConfig :: Yaml.Config -> StackConfig
59fromYamlConfig c = StackConfig{..}
60 where
61 _scResolver = coerce $ c ^. cResolver
62 _scPackages = fromYamlPackage <$> c ^. cPackages
63 _scExtraDeps = StackExtraDep <$> c ^. cExtraDeps
65fromYamlPackage :: Yaml.Package -> StackPackage
66fromYamlPackage = \case
67 Yaml.Simple path ->
68 StackPackage (StackPath path) False
69 Yaml.LocationSimple (Yaml.Location path extraDep) ->
70 StackPackage (StackPath path) (fromMaybe False extraDep)
71 Yaml.LocationGit (Location git extraDep) ->
72 StackPackage (StackRepoGit $ fromYamlGit git) (fromMaybe False extraDep)
74fromYamlGit :: Yaml.Git -> RepoGit
75fromYamlGit yg = RepoGit{..}
76 where
77 _rgUri = yg ^. gGit
78 _rgCommit = yg ^. gCommit