git.iko.soy/typeable/stackage2nix
on master help sign in
Only output necessary Stackage dependencies (#25)

Dependency graph is pruned after cabal2nix step as this allows us to take care of dependencies not explicitly tracked by stackage build plans. Closes #19.

commitd44634a8e8cede2c62020ee4e860641beca00eef authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk> dateMon 28 Aug 2017, 18:38 (9 years ago) parentba38a68
2 files changed+25−5
src/Runner.hs+18−5 src/Runner/Cli.hs+7
src/Runner.hs+18−5
@@ -50,20 +50,33 @@ run = do
5050 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ stackYaml ^. syFilePath)
5151 hPrint h out
5252 let
53− reachable = fmap mkPackageName
54− $ F.toList . F.foldr1 Set.union
53+ reachable = Set.map mkPackageName
54+ $ F.foldr1 Set.union
5555 $ nodeDepends . mkNode <$> packages
5656 s2nLoader mHash pkgId =
57− if pkgName pkgId `elem` reachable
57+ if pkgName pkgId `Set.member` reachable
5858 then packageLoader packageSetConfig Nothing pkgId
5959 else packageLoader packageSetConfig mHash pkgId
6060 s2nPackageSetConfig = packageSetConfig { packageLoader = s2nLoader }
6161 s2nPackageConfig = PackageConfig
6262 { enableCheck = opts ^. optDoCheckStackage
6363 , enableHaddock = opts ^. optDoHaddockStackage }
64− -- generate stackage packages
65− nodes <- traverse (uncurry (buildNodeM s2nPackageSetConfig s2nPackageConfig))
64+ allNodes <- traverse (uncurry (buildNodeM s2nPackageSetConfig s2nPackageConfig))
6665 $ Map.toList (bpPackages buildPlan)
66+
67+ -- Find all reachable dependencies in stackage set to stick into
68+ -- stackage packages file. This is performed on the full stackage
69+ -- set rather than pruning stackage packages beforehand because
70+ -- stackage does not concern itself with build tools while cabal2nix
71+ -- does: pruning only after generating full set of packages allows
72+ -- us to make sure all those extra dependencies are explicitly
73+ -- listed as well.
74+ let nodes = case opts ^. optOutPackagesClosure of
75+ True -> flip reachableDependencies allNodes
76+ -- Originally reachable nodes are root nodes
77+ $ filter (\n -> mkPackageName (nodeName n) `Set.member` reachable) allNodes
78+ False -> allNodes
79+
6780 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
6881 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ buildPlanFile)
6982 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
src/Runner/Cli.hs+7
@@ -20,6 +20,7 @@ data Options = Options
2020 , _optLtsHaskellRepo :: !FilePath
2121 , _optOutStackagePackages :: !FilePath
2222 , _optOutStackageConfig :: !FilePath
23+ , _optOutPackagesClosure :: !Bool
2324 , _optOutDerivation :: !FilePath
2425 , _optDoCheckPackages :: !Bool
2526 , _optDoHaddockPackages :: !Bool
@@ -53,6 +54,7 @@ options = Options
5354 <*> ltsHaskellRepo
5455 <*> outStackagePackages
5556 <*> outStackageConfig
57+ <*> outPackagesClosure
5658 <*> outDerivation
5759 <*> doCheckPackages
5860 <*> doHaddockPackages
@@ -108,6 +110,11 @@ outStackageConfig = option str
108110 <> value "configuration-packages.nix"
109111 <> showDefaultWith id)
110112
113+outPackagesClosure :: Parser Bool
114+outPackagesClosure = flag True False
115+ ( long "no-packages-closure"
116+ <> help "produce full set of stackage packages, not just dependencies" )
117+
111118outDerivation :: Parser FilePath
112119outDerivation = option str
113120 ( long "out-derivation"