git.iko.soy/typeable/stackage2nix
on master help sign in
Add: Nix file path
commit0374c6cd85470582ee5139a571260bf164627858 authorDmitry Bushev <bushevdv@gmail.com> dateSun 28 May 2017, 21:56 (9 years ago) parentba0e443
6 files changed+104−34
.gitignore+1 src/Distribution/Nixpkgs/Haskell/Stack.hs+3−3 src/Language/Nix/FilePath.hs+47 src/Runner.hs+6−17 src/Cli.hs → src/Runner/Cli.hs+41−12 stack2nix.cabal+6−2
.gitignore+1
@@ -1 +1,2 @@
11.stack-work
2+/nix
src/Distribution/Nixpkgs/Haskell/Stack.hs+3−3
@@ -35,13 +35,13 @@ data PackageConfig = PackageConfig
3535
3636makeLenses ''PackageConfig
3737
38−mkPackageConfig :: Platform -> CompilerId -> FlagAssignment -> PackageConfig
39−mkPackageConfig platform compilerId flagAssignment = PackageConfig
38+mkPackageConfig :: Platform -> CompilerId -> PackageConfig
39+mkPackageConfig platform compilerId = PackageConfig
4040 { _pcHaskellResolver = const True
4141 , _pcNixpkgsResolver = \i -> Just (binding # (i, path # [i]))
4242 , _pcTargetPlatform = platform
4343 , _pcTargetCompiler = unknownCompilerInfo compilerId NoAbiTag
44− , _pcFlagAssignment = flagAssignment
44+ , _pcFlagAssignment = []
4545 }
4646
4747-- 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−
31module Runner where
42
5−import Cli
63import Control.Lens
74import Distribution.Nixpkgs.Haskell.Stack
85import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
9−import Distribution.PackageDescription ( FlagName(..), FlagAssignment )
10−import Distribution.Simple.Utils ( lowercase )
116import Language.Nix.PrettyPrinting as PP
127import Options.Applicative
8+import Runner.Cli
139import Stack.Config
14−import Stack.Types
15−
1610
17−readFlagList :: [CabalFlag] -> FlagAssignment
18−readFlagList = fmap (tagWithValue . unCabalFlag)
19− where tagWithValue ('-':fname) = (FlagName (lowercase fname), False)
20− tagWithValue fname = (FlagName (lowercase fname), True)
2111
2212run :: IO ()
2313run = do
24− Options{..} <- execParser pinfo
25− stackYaml <- either fail pure =<< readStackConfig optStackYaml
14+ opts <- execParser pinfo
15+ stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
2616 let
27− flags = readFlagList optFlags
28− pkgConfig = mkPackageConfig optPlatform optCompilerId flags
29− packages <- traverse (packageDerivation pkgConfig optHackageDb)
17+ pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
18+ packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
3019 $ stackYaml ^. scPackages
3120 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 #-}
22
3+module Runner.Cli where
4+
5+import Control.Lens
36import Data.Monoid ( (<>) )
47import Data.Text as T
58import qualified Distribution.Compat.ReadP as P
@@ -7,25 +10,37 @@ import Distribution.Compiler as Compiler
710import Distribution.Nixpkgs.Haskell.Stack
811import Distribution.System as System
912import qualified Distribution.Text as Text
10−import Options.Applicative
13+import Options.Applicative as Opts
1114import Stack.Config
1215import Stack.Types
1316
1417
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+
1528data Options = Options
16− { optStackResolver :: Maybe StackResolver
17− , optHackageDb :: Maybe HackageDb
18− , optFlags :: [CabalFlag]
19− , optCompilerId :: CompilerId
20− , optPlatform :: Platform
21− , optStackYaml :: FilePath
29+ { _optHackageDb :: Maybe HackageDb
30+ , _optStackagePackages :: StackagePackages
31+ , _optStackageConfig :: StackageConfig
32+ , _optCompilerId :: CompilerId
33+ , _optPlatform :: Platform
34+ , _optStackYaml :: FilePath
2235 } deriving (Show)
2336
37+makeLenses ''Options
38+
2439options :: Parser Options
2540options = Options
26− <$> optional stackResolver
27− <*> optional hackageDb
28− <*> many cabalFlag
41+ <$> optional hackageDb
42+ <*> stackagePackages
43+ <*> stackageConfig
2944 <*> compilerId
3045 <*> platform
3146 <*> stackYamlArg
@@ -44,8 +59,22 @@ stackResolver = StackResolver <$>
4459 <> metavar "RESOLVER"
4560 <> help "override stack resolver" )
4661
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+
4776stackYamlArg :: Parser FilePath
48−stackYamlArg = argument str
77+stackYamlArg = Opts.argument str
4978 ( metavar "STACK_YAML"
5079 <> value "stack.yaml" )
5180
stack2nix.cabal+6−2
@@ -13,20 +13,24 @@ cabal-version: >=1.10
1313
1414library
1515 hs-source-dirs: src
16− exposed-modules: Cli
17− , Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting
16+ exposed-modules: Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting
1817 , Distribution.Nixpkgs.Haskell.Stack
1918 , Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting
19+ , Language.Nix.FilePath
2020 , Runner
21+ , Runner.Cli
2122 , Stack.Config
2223 , Stack.Config.Yaml
2324 , Stack.Types
2425 build-depends: base > 4.7 && < 5
2526 , Cabal > 1.24 && < 1.25
27+ , QuickCheck > 2.9 && < 2.10
2628 , aeson > 1.0 && < 1.1
2729 , bytestring > 0.10 && < 0.11
2830 , cabal2nix > 2.0 && < 2.1
31+ , deepseq > 1.4 && < 1.5
2932 , distribution-nixpkgs > 1 && < 1.1
33+ , filepath
3034 , language-nix > 2.1 && < 2.2
3135 , lens > 4.15 && < 4.16
3236 , optparse-applicative > 0.13 && < 0.14