git.iko.soy/typeable/stackage2nix
on master help sign in
Add: generate complete build derivation
7275fb1Dmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+55−12
@@ -1,14 +1,29 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RankNTypes #-}
3+{-# LANGUAGE TemplateHaskell #-}
2
4
3module Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting where
5module Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting where
4
6
5−import Control.Lens
7+import Control.Lens
8+import Data.Maybe
9+import Data.String
10+import Distribution.Nixpkgs.Haskell.Derivation
11+import Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting as PP
6−import Distribution.Package
12+import Distribution.Package
7−import Distribution.Text
13+import Distribution.Text
8−import Distribution.Nixpkgs.Haskell.Derivation
14+import qualified Language.Nix.FilePath as Nix
9−import Distribution.Nixpkgs.Haskell.Packages.PrettyPrinting as PP
10−import Language.Nix.PrettyPrinting as PP
15+import Language.Nix.PrettyPrinting as PP
11
16
17+data OverrideConfig = OverrideConfig
18+ { _ocGhc :: String
19+ , _ocStackagePackages :: Maybe FilePath
20+ , _ocStackageConfig :: Maybe FilePath
21+ }
22+
23+makeLenses ''OverrideConfig
24+
25+hasField :: Lens' OverrideConfig (Maybe a) -> OverrideConfig -> Bool
26+hasField p = views p isJust
12
27
13overridePackages :: [Derivation] -> Doc
28overridePackages :: [Derivation] -> Doc
14overridePackages deps = PP.packageSetConfig . PP.cat $ callPackage <$> deps
29overridePackages deps = PP.packageSetConfig . PP.cat $ callPackage <$> deps
@@ -18,24 +33,52 @@ overridePackages deps = PP.packageSetConfig . PP.cat $ callPackage <$> deps
18 (drvNameString drv <> " = callPackage") 2
33 (drvNameString drv <> " = callPackage") 2
19 (PP.parens (PP.pPrint drv) <+> "{};")
34 (PP.parens (PP.pPrint drv) <+> "{};")
20
35
21−overrideHaskellPackages :: Doc -> [Derivation] -> Doc
36+importStackagePackages :: FilePath -> Doc
37+importStackagePackages path = hsep
38+ [ funarg "self", "import", disp (fromString path :: Nix.FilePath), "{"
39+ , "inherit pkgs stdenv;"
40+ , "inherit (self) callPackage;"
41+ , "}"
42+ ]
43+
44+importStackageConfig :: FilePath -> Doc
45+importStackageConfig path = hsep
46+ [ "import", disp (fromString path :: Nix.FilePath), "{"
47+ , "inherit pkgs;"
48+ , "}"
49+ ]
50+
51+callStackageConfig :: FilePath -> Doc
52+callStackageConfig path = hsep
53+ [ "callPackage", disp (fromString path :: Nix.FilePath), "{}"]
54+
55+overrideHaskellPackages :: OverrideConfig -> [Derivation] -> Doc
22−overrideHaskellPackages ghc packages = vcat
56+overrideHaskellPackages oc packages = vcat
23 [ funargs ["nixpkgs ? import <nixpkgs> {}"]
57 [ funargs ["nixpkgs ? import <nixpkgs> {}"]
24 , ""
58 , ""
25 , "with nixpkgs;"
59 , "with nixpkgs;"
26 , "let"
60 , "let"
61+ , nest 2 "inherit (stdenv.lib) extends;"
62+ , nest 2 . vcat $ catMaybes
63+ [ attr "stackagePackages" . importStackagePackages <$> oc ^. ocStackagePackages
64+ , attr "stackageConfig" . callStackageConfig <$> oc ^. ocStackageConfig ]
27 , nest 2 $ vcat
65 , nest 2 $ vcat
28− [ "packageSetConfig ="
66+ [ "stackPackages ="
29 , nest 2 $ overridePackages packages <> semi
67 , nest 2 $ overridePackages packages <> semi
30 , ""
68 , ""
31− , "pkgOverrides = self: packageSetConfig {"
69+ , "pkgOverrides = self: stackPackages {"
32 , nest 2 "inherit pkgs stdenv;"
70 , nest 2 "inherit pkgs stdenv;"
33 , nest 2 "inherit (self) callPackage;"
71 , nest 2 "inherit (self) callPackage;"
34 , "};"
72 , "};"
35 , ""
73 , ""
36 ]
74 ]
37− , "in pkgs.haskell.packages." <> ghc <> ".override {"
75+ , "in callPackage <nixpkgs/pkgs/development/haskell-modules> {"
38 , nest 2 $ vcat
76 , nest 2 $ vcat
77+ [ attr "ghc" ("pkgs.haskell.compiler." <> ghc)
78+ , onlyIf (hasField ocStackageConfig oc && hasField ocStackagePackages oc)
79+ $ attr "compilerConfig" "self: extends stackageConfig (stackagePackages self)"
39− [ "overrides = self: pkgOverrides self;"]
80+ , attr "overrides" "self: pkgOverrides self"]
40 , "}"
81 , "}"
41 ]
82 ]
83+ where
84+ ghc = oc ^. ocGhc . to text
src/Language/Nix/FilePath.hs+1−1
@@ -26,7 +26,7 @@ instance NFData FilePath where
26 rnf = rnf . unFilePath
26 rnf = rnf . unFilePath
27
27
28instance Arbitrary FilePath where
28instance Arbitrary FilePath where
29− arbitrary = FilePath <$> arbitrary
29+ arbitrary = FilePath <$> QC.suchThat arbitrary Posix.isValid
30 shrink = fmap FilePath . shrink . unFilePath
30 shrink = fmap FilePath . shrink . unFilePath
31
31
32instance Text FilePath where
32instance Text FilePath where
src/Runner.hs+7−3
@@ -3,7 +3,6 @@ module Runner where
3import Control.Lens
3import Control.Lens
4import Distribution.Nixpkgs.Haskell.Stack
4import Distribution.Nixpkgs.Haskell.Stack
5import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
5import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
6−import Language.Nix.PrettyPrinting as PP
7import Options.Applicative
6import Options.Applicative
8import Runner.Cli
7import Runner.Cli
9import Stack.Config
8import Stack.Config
@@ -15,7 +14,12 @@ run = do
15 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
14 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
16 let
15 let
17 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
16 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
17+ overrideConfig = OverrideConfig
18+ { _ocGhc = "ghc802"
19+ , _ocStackagePackages = unStackagePackages <$> opts ^. optStackagePackages
20+ , _ocStackageConfig = unStackageConfig <$> opts ^. optStackageConfig }
18 packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
21 packages <- traverse (packageDerivation pkgConfig (opts ^. optHackageDb))
19 $ stackYaml ^. scPackages
22 $ stackYaml ^. scPackages
23+ let
20− let out = PP.overrideHaskellPackages (PP.text "ghc802") packages
24+ out = PP.overrideHaskellPackages overrideConfig packages
21− print (opts ^. optStackagePackages, opts ^. optStackageConfig)
25+ print out
src/Runner/Cli.hs+6−6
@@ -15,20 +15,20 @@ import Stack.Config
15import Stack.Types
15import Stack.Types
16
16
17
17
18−newtype StackagePackages = StackagePackages { fromStackagePackages :: FilePath }
18+newtype StackagePackages = StackagePackages { unStackagePackages :: FilePath }
19 deriving (Show)
19 deriving (Show)
20
20
21makePrisms ''StackagePackages
21makePrisms ''StackagePackages
22
22
23−newtype StackageConfig = StackageConfig { fromStackageConfig :: FilePath }
23+newtype StackageConfig = StackageConfig { unStackageConfig :: FilePath }
24 deriving (Show)
24 deriving (Show)
25
25
26makePrisms ''StackageConfig
26makePrisms ''StackageConfig
27
27
28data Options = Options
28data Options = Options
29 { _optHackageDb :: Maybe HackageDb
29 { _optHackageDb :: Maybe HackageDb
30− , _optStackagePackages :: StackagePackages
30+ , _optStackagePackages :: Maybe StackagePackages
31− , _optStackageConfig :: StackageConfig
31+ , _optStackageConfig :: Maybe StackageConfig
32 , _optCompilerId :: CompilerId
32 , _optCompilerId :: CompilerId
33 , _optPlatform :: Platform
33 , _optPlatform :: Platform
34 , _optStackYaml :: FilePath
34 , _optStackYaml :: FilePath
@@ -39,8 +39,8 @@ makeLenses ''Options
39options :: Parser Options
39options :: Parser Options
40options = Options
40options = Options
41 <$> optional hackageDb
41 <$> optional hackageDb
42− <*> stackagePackages
42+ <*> optional stackagePackages
43− <*> stackageConfig
43+ <*> optional stackageConfig
44 <*> compilerId
44 <*> compilerId
45 <*> platform
45 <*> platform
46 <*> stackYamlArg
46 <*> stackYamlArg
stack2nix.cabal+4−1
@@ -53,14 +53,17 @@ test-suite spec
53 hs-source-dirs: test
53 hs-source-dirs: test
54 main-is: Spec.hs
54 main-is: Spec.hs
55 build-depends: base
55 build-depends: base
56+ , Cabal
56 , bytestring > 0.10 && < 0.11
57 , bytestring > 0.10 && < 0.11
57 , hspec
58 , hspec
59+ , pretty
58 , shakespeare
60 , shakespeare
59 , stack2nix
61 , stack2nix
60 , text
62 , text
61 , yaml
63 , yaml
62 default-extensions: OverloadedStrings
64 default-extensions: OverloadedStrings
65+ other-modules: Language.Nix.FilePathSpec
63− other-modules: PrettyPrintingSpec
66+ , PrettyPrintingSpec
64 , Stack.Config.YamlSpec
67 , Stack.Config.YamlSpec
65 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
68 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
66 default-language: Haskell2010
69 default-language: Haskell2010
test/Language/Nix/FilePathSpec.hsnew file+21
@@ -0,0 +1,21 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module Language.Nix.FilePathSpec where
4+
5+import Data.String
6+import Distribution.Text
7+import qualified Language.Nix.FilePath as Nix
8+import Test.Hspec
9+import Text.PrettyPrint as PP
10+
11+displayPath :: String -> Doc -> SpecWith ()
12+displayPath path result = specify path
13+ $ disp (fromString path :: Nix.FilePath) `shouldBe` result
14+
15+spec :: Spec
16+spec = describe "valid FilePath" $ do
17+ displayPath "foo" "./foo"
18+ displayPath "./foo" "./foo"
19+ displayPath "../foo" "./../foo"
20+ displayPath "/foo" "/foo"
21+ displayPath "." "./."