git.iko.soy/typeable/stackage2nix
on master help sign in
Add: generate stackage packages with stackage2nix
be94366Dmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−7
@@ -14,10 +14,11 @@ import Distribution.Text
14import qualified Language.Nix.FilePath as Nix
14import qualified Language.Nix.FilePath as Nix
15import Language.Nix.PrettyPrinting as PP
15import Language.Nix.PrettyPrinting as PP
16
16
17+
17data OverrideConfig = OverrideConfig
18data OverrideConfig = OverrideConfig
18 { _ocGhc :: !String
19 { _ocGhc :: !String
19− , _ocStackagePackages :: !(Maybe FilePath)
20+ , _ocStackagePackages :: !FilePath
20− , _ocStackageConfig :: !(Maybe FilePath) }
21+ , _ocStackageConfig :: !FilePath }
21
22
22makeLenses ''OverrideConfig
23makeLenses ''OverrideConfig
23
24
@@ -58,9 +59,9 @@ overrideHaskellPackages oc packages = vcat
58 , "with nixpkgs;"
59 , "with nixpkgs;"
59 , "let"
60 , "let"
60 , nest 2 "inherit (stdenv.lib) extends;"
61 , nest 2 "inherit (stdenv.lib) extends;"
61− , nest 2 . vcat $ catMaybes
62+ , nest 2 $ vcat
62− [ attr "stackagePackages" . importStackagePackages <$> oc ^. ocStackagePackages
63+ [ attr "stackagePackages" . importStackagePackages $ oc ^. ocStackagePackages
63− , attr "stackageConfig" . callStackageConfig <$> oc ^. ocStackageConfig ]
64+ , attr "stackageConfig" . callStackageConfig $ oc ^. ocStackageConfig ]
64 , nest 2 $ vcat
65 , nest 2 $ vcat
65 [ "stackPackages ="
66 [ "stackPackages ="
66 , nest 2 $ overridePackages packages <> semi
67 , nest 2 $ overridePackages packages <> semi
@@ -74,8 +75,7 @@ overrideHaskellPackages oc packages = vcat
74 , "in callPackage <nixpkgs/pkgs/development/haskell-modules> {"
75 , "in callPackage <nixpkgs/pkgs/development/haskell-modules> {"
75 , nest 2 $ vcat
76 , nest 2 $ vcat
76 [ attr "ghc" ("pkgs.haskell.compiler." <> ghc)
77 [ attr "ghc" ("pkgs.haskell.compiler." <> ghc)
77− , onlyIf (hasField ocStackageConfig oc && hasField ocStackagePackages oc)
78− $ attr "compilerConfig" "self: extends stackageConfig (stackagePackages self)"
78+ , attr "compilerConfig" "self: extends stackageConfig (stackagePackages self)"
79 , attr "overrides" "self: pkgOverrides self"]
79 , attr "overrides" "self: pkgOverrides self"]
80 , "}"
80 , "}"
81 ]
81 ]
src/Runner.hs+19−3
@@ -7,11 +7,26 @@ import Options.Applicative
7import Runner.Cli
7import Runner.Cli
8import Stack.Config
8import Stack.Config
9
9
10+import qualified Stackage2nix as S2n
11+
10
12
11run :: IO ()
13run :: IO ()
12run = do
14run = do
13 opts <- execParser pinfo
15 opts <- execParser pinfo
14 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
16 stackYaml <- either fail pure =<< readStackConfig (opts ^. optStackYaml)
17+
18+ -- generate stackage packages
19+ let
20+ s2nOptions = S2n.Options
21+ { S2n.optBuildPlanFile = opts ^. optStackageBuildPlan
22+ , S2n.optAllCabalHashes = opts ^. optAllCabalHashes
23+ , S2n.optNixpkgsRepository = opts ^. optNixpkgsRepository
24+ , S2n.optNixpkgsMap = Nothing
25+ , S2n.optOutPackages = opts ^. optStackageOutPackages
26+ , S2n.optOutConfig = opts ^. optStackageOutConfig }
27+ _ <- S2n.run s2nOptions
28+
29+ -- generate haskell packages override
15 let
30 let
16 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
31 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
17 overrideConfig = mkOverrideConfig opts
32 overrideConfig = mkOverrideConfig opts
@@ -19,11 +34,12 @@ run = do
19 $ stackYaml ^. scPackages
34 $ stackYaml ^. scPackages
20 let
35 let
21 out = PP.overrideHaskellPackages overrideConfig packages
36 out = PP.overrideHaskellPackages overrideConfig packages
37+
22 writeFile (opts ^. optOutFile) (show out)
38 writeFile (opts ^. optOutFile) (show out)
23 putStrLn $ "\nDerivation was written to " ++ opts ^. optOutFile
39 putStrLn $ "\nDerivation was written to " ++ opts ^. optOutFile
24
40
25mkOverrideConfig :: Options -> OverrideConfig
41mkOverrideConfig :: Options -> OverrideConfig
26mkOverrideConfig opts = OverrideConfig
42mkOverrideConfig opts = OverrideConfig
27− { _ocGhc = "ghc802"
43+ { _ocGhc = "ghc802"
28− , _ocStackagePackages = unStackagePackages <$> opts ^. optStackagePackages
44+ , _ocStackagePackages = opts ^. optStackageOutPackages
29− , _ocStackageConfig = unStackageConfig <$> opts ^. optStackageConfig }
45+ , _ocStackageConfig = opts ^. optStackageOutConfig }
src/Runner/Cli.hs+48−32
@@ -15,24 +15,17 @@ import Stack.Config
15import Stack.Types
15import Stack.Types
16
16
17
17
18−newtype StackagePackages = StackagePackages { unStackagePackages :: FilePath }
19− deriving (Show)
20−
21−makePrisms ''StackagePackages
22−
23−newtype StackageConfig = StackageConfig { unStackageConfig :: FilePath }
24− deriving (Show)
25−
26−makePrisms ''StackageConfig
27−
28data Options = Options
18data Options = Options
29− { _optOutFile :: !FilePath
19+ { _optOutFile :: !FilePath
30− , _optHackageDb :: !(Maybe HackageDb)
20+ , _optHackageDb :: !(Maybe HackageDb)
31− , _optStackagePackages :: !(Maybe StackagePackages)
21+ , _optNixpkgsRepository :: !FilePath
32− , _optStackageConfig :: !(Maybe StackageConfig)
22+ , _optStackageBuildPlan :: !FilePath
23+ , _optAllCabalHashes :: !FilePath
24+ , _optStackageOutPackages :: !FilePath
25+ , _optStackageOutConfig :: !FilePath
33− , _optCompilerId :: !CompilerId
26+ , _optCompilerId :: !CompilerId
34− , _optPlatform :: !Platform
27+ , _optPlatform :: !Platform
35− , _optStackYaml :: !FilePath
28+ , _optStackYaml :: !FilePath
36 } deriving (Show)
29 } deriving (Show)
37
30
38makeLenses ''Options
31makeLenses ''Options
@@ -41,8 +34,11 @@ options :: Parser Options
41options = Options
34options = Options
42 <$> outFile
35 <$> outFile
43 <*> optional hackageDb
36 <*> optional hackageDb
44− <*> optional stackagePackages
37+ <*> nixpkgsRepository
45− <*> optional stackageConfig
38+ <*> stackageBuildPlan
39+ <*> allCabalHashes
40+ <*> stackageOutPackages
41+ <*> stackageOutConfig
46 <*> compilerId
42 <*> compilerId
47 <*> platform
43 <*> platform
48 <*> stackYamlArg
44 <*> stackYamlArg
@@ -61,6 +57,26 @@ outFile = option str
61 <> help "path where to write output derivation"
57 <> help "path where to write output derivation"
62 <> value "default.nix" )
58 <> value "default.nix" )
63
59
60+nixpkgsRepository :: Parser FilePath
61+nixpkgsRepository = option str
62+ ( long "nixpkgs"
63+ <> metavar "NIXPKGS"
64+ <> help "path to Nixpkgs repository"
65+ <> value "<nixpkgs>"
66+ <> showDefaultWith id )
67+
68+stackageBuildPlan :: Parser FilePath
69+stackageBuildPlan = option str
70+ ( long "stackage-build-plan"
71+ <> metavar "STACKAGE_BUILD_PLAN"
72+ <> help "stackage build plan (YAML)" )
73+
74+allCabalHashes :: Parser FilePath
75+allCabalHashes = option str
76+ ( long "all-cabal-hashes"
77+ <> metavar "ALL_CABAL_HASHES"
78+ <> help "path to all-cabal-hashes repository" )
79+
64stackResolver :: Parser StackResolver
80stackResolver :: Parser StackResolver
65stackResolver = StackResolver <$>
81stackResolver = StackResolver <$>
66 option text
82 option text
@@ -68,19 +84,19 @@ stackResolver = StackResolver <$>
68 <> metavar "RESOLVER"
84 <> metavar "RESOLVER"
69 <> help "override stack resolver" )
85 <> help "override stack resolver" )
70
86
71−stackagePackages :: Parser StackagePackages
87+stackageOutPackages :: Parser FilePath
72−stackagePackages = StackagePackages <$>
73− option str
88+stackageOutPackages = option str
74− ( long "nix-stackage-packages"
89+ ( long "nix-stackage-packages"
75− <> metavar "STACKAGE_PACKAGES"
90+ <> metavar "STACKAGE_PACKAGES"
76− <> help "path to packages file generated by 'stackage2nix'" )
91+ <> help "name of the output file for the package set"
77−
92+ <> value "configuration-packages.nix" )
78−stackageConfig :: Parser StackageConfig
93+
79−stackageConfig = StackageConfig <$>
94+stackageOutConfig :: Parser FilePath
80− option str
95+stackageOutConfig = option str
81− ( long "nix-stackage-config"
96+ ( long "nix-stackage-config"
82− <> metavar "STACKAGE_CONFIG"
97+ <> metavar "STACKAGE_CONFIG"
83− <> help "path to packages config file generated by 'stackage2nix'" )
98+ <> help "name of the output file for the package set configuration"
99+ <> value "packages.nix" )
84
100
85stackYamlArg :: Parser FilePath
101stackYamlArg :: Parser FilePath
86stackYamlArg = Opts.argument str
102stackYamlArg = Opts.argument str
stack.yaml+4−3
@@ -1,9 +1,10 @@
1resolver: lts-8.15
1resolver: lts-8.15
2packages:
2packages:
3- '.'
3- '.'
4−- location:
4+- location: ../cabal2nix
5+#- location:
5− git: https://github.com/4e6/cabal2nix.git
6+ #git: https://github.com/4e6/cabal2nix.git
6− commit: 7df95c029fb2e33dc9176796e5055bd6c5175ed3
7+ #commit: 5da88077431fca9ec4d63ce3ad22cd1fe935ad93
7 extra-dep: true
8 extra-dep: true
8extra-deps:
9extra-deps:
9- distribution-nixpkgs-1.1
10- distribution-nixpkgs-1.1
test.sh+8−2
@@ -1,5 +1,11 @@
1−#!/usr/bin/env sh
1+#!/usr/bin/env bash
2
2
3+VERSION=${VERSION:-8.15}
4+
5+stack2nix \
6+ --stackage-build-plan "$HOME/projects/fpco/lts-haskell/lts-$VERSION.yaml" \
7+ --all-cabal-hashes "$HOME/projects/commercialhaskell/all-cabal-hashes" \
3−stack2nix --nix-stackage-config=nix/configuration-packages.nix --nix-stackage-packages=./nix/packages.nix
8+ --nix-stackage-config=nix/configuration-packages.nix \
9+ --nix-stackage-packages=./nix/packages.nix
4
10
5nix-build -A stack2nix --dry-run
11nix-build -A stack2nix --dry-run