git.iko.soy/typeable/stackage2nix
on master help sign in
Generate stackage override
aac2111Dmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+30−2
@@ -15,6 +15,7 @@ import Distribution.Text
15import Distribution.Version (Version)
15import Distribution.Version (Version)
16import qualified Language.Nix.FilePath as Nix
16import qualified Language.Nix.FilePath as Nix
17import Language.Nix.PrettyPrinting as PP
17import Language.Nix.PrettyPrinting as PP
18+import Stack.Config (StackResolver, unStackResolver)
18
19
19
20
20data OverrideConfig = OverrideConfig
21data OverrideConfig = OverrideConfig
@@ -87,6 +88,28 @@ overrideHaskellPackages oc packages =
87 , "}"
88 , "}"
88 ]
89 ]
89
90
91+overrideStackage :: StackResolver -> OverrideConfig -> NonEmpty Derivation -> Doc
92+overrideStackage stackResolver oc packages =
93+ let
94+ nixpkgs = if oc ^. ocNixpkgs . to fromString == systemNixpkgs
95+ then systemNixpkgs
96+ else (disp . (fromString :: FilePath -> Nix.FilePath)) (oc ^. ocNixpkgs)
97+ in vcat
98+ [ funargs
99+ [ "nixpkgs ? import " <> nixpkgs <> " {}"
100+ ]
101+ , ""
102+ , "let"
103+ , nest 2 $ vcat
104+ [ "stackPackages ="
105+ , nest 2 $ overridePackages packages <> semi
106+ ]
107+ , "in nixpkgs.haskell.packages.stackage." <> toNixStackResolver stackResolver <> ".override {"
108+ , nest 2
109+ $ attr "packageSetConfig" "self: super: stackPackages { inherit (nixpkgs) pkgs stdenv; inherit (self) callPackage; } super"
110+ , "}"
111+ ]
112+
90pPrintHaskellPackages :: OverrideConfig -> Doc
113pPrintHaskellPackages :: OverrideConfig -> Doc
91pPrintHaskellPackages oc =
114pPrintHaskellPackages oc =
92 let
115 let
@@ -114,5 +137,10 @@ pPrintHaskellPackages oc =
114 ]
137 ]
115
138
116toNixGhcVersion :: Version -> Doc
139toNixGhcVersion :: Version -> Doc
117−toNixGhcVersion =
140+toNixGhcVersion = (<>) "ghc" . toNixVersion . show . disp
141+
142+toNixStackResolver :: StackResolver -> Doc
143+toNixStackResolver = toNixVersion . unStackResolver
144+
145+toNixVersion :: String -> Doc
118− (<>) "ghc" . text . L.filter (/= '.') . show . disp
146+toNixVersion = text . L.filter (/= '.')
src/Runner.hs+5−3
@@ -85,9 +85,11 @@ run = do
85 $ pPrintOutPackages (view nodeDerivation <$> nodes)
85 $ pPrintOutPackages (view nodeDerivation <$> nodes)
86 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
86 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
87 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
87 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
88− -- TODO: generate stackage override
89− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
88+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
89+ if generateStackage
90− $ PP.overrideHaskellPackages overrideConfig stackConfPackages
90+ then PP.overrideHaskellPackages overrideConfig stackConfPackages
91+ -- TODO: --lts-haskell and --all-cabal-caches unnecessary
92+ else PP.overrideStackage (stackConf ^. scResolver) overrideConfig stackConfPackages
91
93
92 -- Generate Stackage packages from resolver
94 -- Generate Stackage packages from resolver
93 OriginResolver stackResolver -> do
95 OriginResolver stackResolver -> do
src/Runner/Cli.hs+2−2
@@ -135,12 +135,12 @@ doHaddockPackages = flag True False
135
135
136withStackage :: Parser Bool
136withStackage :: Parser Bool
137withStackage = switch
137withStackage = switch
138− ( long "--with-stackage"
138+ ( long "with-stackage"
139 <> help "generate full Stackage" )
139 <> help "generate full Stackage" )
140
140
141withStackageClosure :: Parser Bool
141withStackageClosure :: Parser Bool
142withStackageClosure = switch
142withStackageClosure = switch
143− ( long "--with-stackage-closure"
143+ ( long "with-stackage-closure"
144 <> help "generate Stackage subset containing only build dependencies" )
144 <> help "generate Stackage subset containing only build dependencies" )
145
145
146resolver :: Parser StackResolver
146resolver :: Parser StackResolver