git.iko.soy/typeable/stackage2nix
on master help sign in
Only output necessary Stackage dependencies (#25)
d44634aMateusz Kowalczyk
src/Runner.hs+18−5
@@ -50,20 +50,33 @@ run = do
50 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ stackYaml ^. syFilePath)
50 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ stackYaml ^. syFilePath)
51 hPrint h out
51 hPrint h out
52 let
52 let
53− reachable = fmap mkPackageName
53+ reachable = Set.map mkPackageName
54− $ F.toList . F.foldr1 Set.union
54+ $ F.foldr1 Set.union
55 $ nodeDepends . mkNode <$> packages
55 $ nodeDepends . mkNode <$> packages
56 s2nLoader mHash pkgId =
56 s2nLoader mHash pkgId =
57− if pkgName pkgId `elem` reachable
57+ if pkgName pkgId `Set.member` reachable
58 then packageLoader packageSetConfig Nothing pkgId
58 then packageLoader packageSetConfig Nothing pkgId
59 else packageLoader packageSetConfig mHash pkgId
59 else packageLoader packageSetConfig mHash pkgId
60 s2nPackageSetConfig = packageSetConfig { packageLoader = s2nLoader }
60 s2nPackageSetConfig = packageSetConfig { packageLoader = s2nLoader }
61 s2nPackageConfig = PackageConfig
61 s2nPackageConfig = PackageConfig
62 { enableCheck = opts ^. optDoCheckStackage
62 { enableCheck = opts ^. optDoCheckStackage
63 , enableHaddock = opts ^. optDoHaddockStackage }
63 , enableHaddock = opts ^. optDoHaddockStackage }
64− -- generate stackage packages
65− nodes <- traverse (uncurry (buildNodeM s2nPackageSetConfig s2nPackageConfig))
64+ allNodes <- traverse (uncurry (buildNodeM s2nPackageSetConfig s2nPackageConfig))
66 $ Map.toList (bpPackages buildPlan)
65 $ 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+
67 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
80 withFile (opts ^. optOutStackagePackages) WriteMode $ \h -> do
68 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ buildPlanFile)
81 hPutStrLn h ("# Generated by stackage2nix " ++ Text.display version ++ " from " ++ buildPlanFile)
69 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
82 hPutStrLn h $ render $ pPrintOutPackages (view nodeDerivation <$> nodes)
src/Runner/Cli.hs+7
@@ -20,6 +20,7 @@ data Options = Options
20 , _optLtsHaskellRepo :: !FilePath
20 , _optLtsHaskellRepo :: !FilePath
21 , _optOutStackagePackages :: !FilePath
21 , _optOutStackagePackages :: !FilePath
22 , _optOutStackageConfig :: !FilePath
22 , _optOutStackageConfig :: !FilePath
23+ , _optOutPackagesClosure :: !Bool
23 , _optOutDerivation :: !FilePath
24 , _optOutDerivation :: !FilePath
24 , _optDoCheckPackages :: !Bool
25 , _optDoCheckPackages :: !Bool
25 , _optDoHaddockPackages :: !Bool
26 , _optDoHaddockPackages :: !Bool
@@ -53,6 +54,7 @@ options = Options
53 <*> ltsHaskellRepo
54 <*> ltsHaskellRepo
54 <*> outStackagePackages
55 <*> outStackagePackages
55 <*> outStackageConfig
56 <*> outStackageConfig
57+ <*> outPackagesClosure
56 <*> outDerivation
58 <*> outDerivation
57 <*> doCheckPackages
59 <*> doCheckPackages
58 <*> doHaddockPackages
60 <*> doHaddockPackages
@@ -108,6 +110,11 @@ outStackageConfig = option str
108 <> value "configuration-packages.nix"
110 <> value "configuration-packages.nix"
109 <> showDefaultWith id)
111 <> showDefaultWith id)
110
112
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+
111outDerivation :: Parser FilePath
118outDerivation :: Parser FilePath
112outDerivation = option str
119outDerivation = option str
113 ( long "out-derivation"
120 ( long "out-derivation"