git.iko.soy/typeable/stackage2nix
on master help sign in
Add: generate stackage packages with stackage2nix
commitbe94366a75e6bdf93fc797fdf2d907f5ff7f6f72 authorDmitry Bushev <bushevdv@gmail.com> dateMon 12 Jun 2017, 00:38 (9 years ago) parent8d273a4
5 files changed+86−47
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−7 src/Runner.hs+19−3 src/Runner/Cli.hs+48−32 stack.yaml+4−3 test.sh+8−2
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−7
@@ -14,10 +14,11 @@ import Distribution.Text
1414import qualified Language.Nix.FilePath as Nix
1515import Language.Nix.PrettyPrinting as PP
1616
17+
1718data OverrideConfig = OverrideConfig
1819 { _ocGhc :: !String
19− , _ocStackagePackages :: !(Maybe FilePath)
20− , _ocStackageConfig :: !(Maybe FilePath) }
20+ , _ocStackagePackages :: !FilePath
21+ , _ocStackageConfig :: !FilePath }
2122
2223makeLenses ''OverrideConfig
2324
@@ -58,9 +59,9 @@ overrideHaskellPackages oc packages = vcat
5859 , "with nixpkgs;"
5960 , "let"
6061 , nest 2 "inherit (stdenv.lib) extends;"
61− , nest 2 . vcat $ catMaybes
62− [ attr "stackagePackages" . importStackagePackages <$> oc ^. ocStackagePackages
63− , attr "stackageConfig" . callStackageConfig <$> oc ^. ocStackageConfig ]
62+ , nest 2 $ vcat
63+ [ attr "stackagePackages" . importStackagePackages $ oc ^. ocStackagePackages
64+ , attr "stackageConfig" . callStackageConfig $ oc ^. ocStackageConfig ]
6465 , nest 2 $ vcat
6566 [ "stackPackages ="
6667 , nest 2 $ overridePackages packages <> semi
@@ -74,8 +75,7 @@ overrideHaskellPackages oc packages = vcat
7475 , "in callPackage <nixpkgs/pkgs/development/haskell-modules> {"
7576 , nest 2 $ vcat
7677 [ 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)"
7979 , attr "overrides" "self: pkgOverrides self"]
8080 , "}"
8181 ]
src/Runner.hs+19−3
@@ -7,11 +7,26 @@ import Options.Applicative
77import Runner.Cli
88import Stack.Config
99
10+import qualified Stackage2nix as S2n
11+
1012
1113run :: IO ()
1214run = do
1315 opts <- execParser pinfo
1416 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
1530 let
1631 pkgConfig = mkPackageConfig (opts ^. optPlatform) (opts ^. optCompilerId)
1732 overrideConfig = mkOverrideConfig opts
@@ -19,11 +34,12 @@ run = do
1934 $ stackYaml ^. scPackages
2035 let
2136 out = PP.overrideHaskellPackages overrideConfig packages
37+
2238 writeFile (opts ^. optOutFile) (show out)
2339 putStrLn $ "\nDerivation was written to " ++ opts ^. optOutFile
2440
2541mkOverrideConfig :: Options -> OverrideConfig
2642mkOverrideConfig opts = OverrideConfig
27− { _ocGhc = "ghc802"
28− , _ocStackagePackages = unStackagePackages <$> opts ^. optStackagePackages
29− , _ocStackageConfig = unStackageConfig <$> opts ^. optStackageConfig }
43+ { _ocGhc = "ghc802"
44+ , _ocStackagePackages = opts ^. optStackageOutPackages
45+ , _ocStackageConfig = opts ^. optStackageOutConfig }
src/Runner/Cli.hs+48−32
@@ -15,24 +15,17 @@ import Stack.Config
1515import Stack.Types
1616
1717
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−
2818data Options = Options
29− { _optOutFile :: !FilePath
30− , _optHackageDb :: !(Maybe HackageDb)
31− , _optStackagePackages :: !(Maybe StackagePackages)
32− , _optStackageConfig :: !(Maybe StackageConfig)
33− , _optCompilerId :: !CompilerId
34− , _optPlatform :: !Platform
35− , _optStackYaml :: !FilePath
19+ { _optOutFile :: !FilePath
20+ , _optHackageDb :: !(Maybe HackageDb)
21+ , _optNixpkgsRepository :: !FilePath
22+ , _optStackageBuildPlan :: !FilePath
23+ , _optAllCabalHashes :: !FilePath
24+ , _optStackageOutPackages :: !FilePath
25+ , _optStackageOutConfig :: !FilePath
26+ , _optCompilerId :: !CompilerId
27+ , _optPlatform :: !Platform
28+ , _optStackYaml :: !FilePath
3629 } deriving (Show)
3730
3831makeLenses ''Options
@@ -41,8 +34,11 @@ options :: Parser Options
4134options = Options
4235 <$> outFile
4336 <*> optional hackageDb
44− <*> optional stackagePackages
45− <*> optional stackageConfig
37+ <*> nixpkgsRepository
38+ <*> stackageBuildPlan
39+ <*> allCabalHashes
40+ <*> stackageOutPackages
41+ <*> stackageOutConfig
4642 <*> compilerId
4743 <*> platform
4844 <*> stackYamlArg
@@ -61,6 +57,26 @@ outFile = option str
6157 <> help "path where to write output derivation"
6258 <> value "default.nix" )
6359
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+
6480stackResolver :: Parser StackResolver
6581stackResolver = StackResolver <$>
6682 option text
@@ -68,19 +84,19 @@ stackResolver = StackResolver <$>
6884 <> metavar "RESOLVER"
6985 <> help "override stack resolver" )
7086
71−stackagePackages :: Parser StackagePackages
72−stackagePackages = StackagePackages <$>
73− option str
74− ( long "nix-stackage-packages"
75− <> metavar "STACKAGE_PACKAGES"
76− <> help "path to packages file generated by 'stackage2nix'" )
77−
78−stackageConfig :: Parser StackageConfig
79−stackageConfig = StackageConfig <$>
80− option str
81− ( long "nix-stackage-config"
82− <> metavar "STACKAGE_CONFIG"
83− <> help "path to packages config file generated by 'stackage2nix'" )
87+stackageOutPackages :: Parser FilePath
88+stackageOutPackages = option str
89+ ( long "nix-stackage-packages"
90+ <> metavar "STACKAGE_PACKAGES"
91+ <> help "name of the output file for the package set"
92+ <> value "configuration-packages.nix" )
93+
94+stackageOutConfig :: Parser FilePath
95+stackageOutConfig = option str
96+ ( long "nix-stackage-config"
97+ <> metavar "STACKAGE_CONFIG"
98+ <> help "name of the output file for the package set configuration"
99+ <> value "packages.nix" )
84100
85101stackYamlArg :: Parser FilePath
86102stackYamlArg = Opts.argument str
stack.yaml+4−3
@@ -1,9 +1,10 @@
11resolver: lts-8.15
22packages:
33- '.'
4−- location:
5− git: https://github.com/4e6/cabal2nix.git
6− commit: 7df95c029fb2e33dc9176796e5055bd6c5175ed3
4+- location: ../cabal2nix
5+#- location:
6+ #git: https://github.com/4e6/cabal2nix.git
7+ #commit: 5da88077431fca9ec4d63ce3ad22cd1fe935ad93
78 extra-dep: true
89extra-deps:
910- distribution-nixpkgs-1.1
test.sh+8−2
@@ -1,5 +1,11 @@
1−#!/usr/bin/env sh
1+#!/usr/bin/env bash
22
3−stack2nix --nix-stackage-config=nix/configuration-packages.nix --nix-stackage-packages=./nix/packages.nix
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" \
8+ --nix-stackage-config=nix/configuration-packages.nix \
9+ --nix-stackage-packages=./nix/packages.nix
410
511nix-build -A stack2nix --dry-run