git.iko.soy/typeable/stackage2nix
on master help sign in
Add: Nix file path
0374c6cDmitry Bushev
.gitignore+1
@@ -1 +1,2 @@
1.stack-work
1.stack-work
2+/nix
src/Distribution/Nixpkgs/Haskell/Stack.hs+3−3
@@ -35,13 +35,13 @@ data PackageConfig = PackageConfig
35
35
36makeLenses ''PackageConfig
36makeLenses ''PackageConfig
37
37
38−mkPackageConfig :: Platform -> CompilerId -> FlagAssignment -> PackageConfig
38+mkPackageConfig :: Platform -> CompilerId -> PackageConfig
39−mkPackageConfig platform compilerId flagAssignment = PackageConfig
39+mkPackageConfig platform compilerId = PackageConfig
40 { _pcHaskellResolver = const True
40 { _pcHaskellResolver = const True
41 , _pcNixpkgsResolver = \i -> Just (binding # (i, path # [i]))
41 , _pcNixpkgsResolver = \i -> Just (binding # (i, path # [i]))
42 , _pcTargetPlatform = platform
42 , _pcTargetPlatform = platform
43 , _pcTargetCompiler = unknownCompilerInfo compilerId NoAbiTag
43 , _pcTargetCompiler = unknownCompilerInfo compilerId NoAbiTag
44− , _pcFlagAssignment = flagAssignment
44+ , _pcFlagAssignment = []
45 }
45 }
46
46
47-- Thin wrapper around private stack2nix 'PackageSourceSpec.fromDB' method.
47-- Thin wrapper around private stack2nix 'PackageSourceSpec.fromDB' method.
src/Language/Nix/FilePath.hsnew file+47
@@ -0,0 +1,47 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE TemplateHaskell #-}
3+
4+module Language.Nix.FilePath where
5+
6+import Control.DeepSeq
7+import Control.Lens
8+import Control.Monad
9+import Data.Maybe
10+import Data.String
11+import Distribution.Compat.ReadP as ReadP
12+import Distribution.Text
13+import GHC.Generics (Generic)
14+import Prelude hiding (FilePath)
15+import qualified System.FilePath.Posix as Posix
16+import Test.QuickCheck as QC
17+import Text.PrettyPrint as PP
18+
19+
20+newtype FilePath = FilePath { unFilePath :: String }
21+ deriving (Show, Eq, Ord, Generic)
22+
23+makePrisms ''FilePath
24+
25+instance NFData FilePath where
26+ rnf = rnf . unFilePath
27+
28+instance Arbitrary FilePath where
29+ arbitrary = FilePath <$> arbitrary
30+ shrink = fmap FilePath . shrink . unFilePath
31+
32+instance Text FilePath where
33+ disp = text . renderFilePath
34+ parse = parseFilePath
35+
36+instance IsString FilePath where
37+ fromString s = fromMaybe (error $ "invalid Nix file path:" ++ s) (simpleParse s)
38+
39+parseFilePath :: ReadP r FilePath
40+parseFilePath = do
41+ path <- ReadP.munch (const True)
42+ if Posix.isValid path
43+ then pure (FilePath path)
44+ else pfail
45+
46+renderFilePath :: FilePath -> String
47+renderFilePath = Posix.combine "." . Posix.normalise . unFilePath
src/Runner.hs+6−17
@@ -1,32 +1,21 @@
1−{-# LANGUAGE RecordWildCards #-}
2−
3module Runner where
1module Runner where
4
2
5−import Cli
6import Control.Lens
3import Control.Lens
7import Distribution.Nixpkgs.Haskell.Stack
4import Distribution.Nixpkgs.Haskell.Stack
8import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
5import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
9−import Distribution.PackageDescription ( FlagName(..), FlagAssignment )
10−import Distribution.Simple.Utils ( lowercase )
11import Language.Nix.PrettyPrinting as PP
6import Language.Nix.PrettyPrinting as PP
12import Options.Applicative
7import Options.Applicative
8+import Runner.Cli
13import Stack.Config
9import Stack.Config
14−import Stack.Types
15−
16
10
17−readFlagList :: [CabalFlag] -> FlagAssignment
18−readFlagList = fmap (tagWithValue . unCabalFlag)
19− where tagWithValue ('-':fname) = (FlagName (lowercase fname), False)
20− tagWithValue fname = (FlagName (lowercase fname), True)
21
11
22run :: IO ()
12run :: IO ()
23run = do
13run = do
24− Options{..} <- execParser pinfo
14+ opts <- execParser pinfo
25− stackYaml <- either fail pure =<< readStackConfig optStackYaml
15+ stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
26 let
16 let
27− flags = readFlagList optFlags
28− pkgConfig = mkPackageConfig optPlatform optCompilerId flags
17+ pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
29− packages <- traverse (packageDerivation pkgConfig optHackageDb)
18+ packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
30 $ stackYaml ^. scPackages
19 $ stackYaml ^. scPackages
31 let out = PP.overrideHaskellPackages (PP.text "ghc802") packages
20 let out = PP.overrideHaskellPackages (PP.text "ghc802") packages
32− print out
21+ print (opts ^. optStackagePackages, opts ^. optStackageConfig)
src/Cli.hs → src/Runner/Cli.hsrenamed+41−12
@@ -1,5 +1,8 @@
1−module Cli where
1+{-# LANGUAGE TemplateHaskell #-}
2
2
3+module Runner.Cli where
4+
5+import Control.Lens
3import Data.Monoid ( (<>) )
6import Data.Monoid ( (<>) )
4import Data.Text as T
7import Data.Text as T
5import qualified Distribution.Compat.ReadP as P
8import qualified Distribution.Compat.ReadP as P
@@ -7,25 +10,37 @@ import Distribution.Compiler as Compiler
7import Distribution.Nixpkgs.Haskell.Stack
10import Distribution.Nixpkgs.Haskell.Stack
8import Distribution.System as System
11import Distribution.System as System
9import qualified Distribution.Text as Text
12import qualified Distribution.Text as Text
10−import Options.Applicative
13+import Options.Applicative as Opts
11import Stack.Config
14import Stack.Config
12import Stack.Types
15import Stack.Types
13
16
14
17
18+newtype StackagePackages = StackagePackages { fromStackagePackages :: FilePath }
19+ deriving (Show)
20+
21+makePrisms ''StackagePackages
22+
23+newtype StackageConfig = StackageConfig { fromStackageConfig :: FilePath }
24+ deriving (Show)
25+
26+makePrisms ''StackageConfig
27+
15data Options = Options
28data Options = Options
16− { optStackResolver :: Maybe StackResolver
17− , optHackageDb :: Maybe HackageDb
29+ { _optHackageDb :: Maybe HackageDb
18− , optFlags :: [CabalFlag]
30+ , _optStackagePackages :: StackagePackages
31+ , _optStackageConfig :: StackageConfig
19− , optCompilerId :: CompilerId
32+ , _optCompilerId :: CompilerId
20− , optPlatform :: Platform
33+ , _optPlatform :: Platform
21− , optStackYaml :: FilePath
34+ , _optStackYaml :: FilePath
22 } deriving (Show)
35 } deriving (Show)
23
36
37+makeLenses ''Options
38+
24options :: Parser Options
39options :: Parser Options
25options = Options
40options = Options
26− <$> optional stackResolver
27− <*> optional hackageDb
41+ <$> optional hackageDb
28− <*> many cabalFlag
42+ <*> stackagePackages
43+ <*> stackageConfig
29 <*> compilerId
44 <*> compilerId
30 <*> platform
45 <*> platform
31 <*> stackYamlArg
46 <*> stackYamlArg
@@ -44,8 +59,22 @@ stackResolver = StackResolver <$>
44 <> metavar "RESOLVER"
59 <> metavar "RESOLVER"
45 <> help "override stack resolver" )
60 <> help "override stack resolver" )
46
61
62+stackagePackages :: Parser StackagePackages
63+stackagePackages = StackagePackages <$>
64+ option str
65+ ( long "nix-stackage-packages"
66+ <> metavar "STACKAGE_PACKAGES"
67+ <> help "path to packages file generated by 'stackage2nix'" )
68+
69+stackageConfig :: Parser StackageConfig
70+stackageConfig = StackageConfig <$>
71+ option str
72+ ( long "nix-stackage-config"
73+ <> metavar "STACKAGE_CONFIG"
74+ <> help "path to packages config file generated by 'stackage2nix'" )
75+
47stackYamlArg :: Parser FilePath
76stackYamlArg :: Parser FilePath
48−stackYamlArg = argument str
77+stackYamlArg = Opts.argument str
49 ( metavar "STACK_YAML"
78 ( metavar "STACK_YAML"
50 <> value "stack.yaml" )
79 <> value "stack.yaml" )
51
80
stack2nix.cabal+6−2
@@ -13,20 +13,24 @@ cabal-version: >=1.10
13
13
14library
14library
15 hs-source-dirs: src
15 hs-source-dirs: src
16− exposed-modules: Cli
17− , Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting
16+ exposed-modules: Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting
18 , Distribution.Nixpkgs.Haskell.Stack
17 , Distribution.Nixpkgs.Haskell.Stack
19 , Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting
18 , Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting
19+ , Language.Nix.FilePath
20 , Runner
20 , Runner
21+ , Runner.Cli
21 , Stack.Config
22 , Stack.Config
22 , Stack.Config.Yaml
23 , Stack.Config.Yaml
23 , Stack.Types
24 , Stack.Types
24 build-depends: base > 4.7 && < 5
25 build-depends: base > 4.7 && < 5
25 , Cabal > 1.24 && < 1.25
26 , Cabal > 1.24 && < 1.25
27+ , QuickCheck > 2.9 && < 2.10
26 , aeson > 1.0 && < 1.1
28 , aeson > 1.0 && < 1.1
27 , bytestring > 0.10 && < 0.11
29 , bytestring > 0.10 && < 0.11
28 , cabal2nix > 2.0 && < 2.1
30 , cabal2nix > 2.0 && < 2.1
31+ , deepseq > 1.4 && < 1.5
29 , distribution-nixpkgs > 1 && < 1.1
32 , distribution-nixpkgs > 1 && < 1.1
33+ , filepath
30 , language-nix > 2.1 && < 2.2
34 , language-nix > 2.1 && < 2.2
31 , lens > 4.15 && < 4.16
35 , lens > 4.15 && < 4.16
32 , optparse-applicative > 0.13 && < 0.14
36 , optparse-applicative > 0.13 && < 0.14