@@ -1,7 +1,6 @@
1module Runner ( run ) where
1module Runner ( run ) where
3import Control.Lens
3import Control.Lens
5import Data.Foldable as F
4import Data.Foldable as F
6import Data.List as L
5import Data.List as L
7import Distribution.Nixpkgs.Haskell.FromStack
6import Distribution.Nixpkgs.Haskell.FromStack
@@ -34,62 +33,66 @@ run = do
34 -- Generate build derivation from stack.yaml file
33 -- Generate build derivation from stack.yaml file
35 OriginStackYaml stackYaml -> do
34 OriginStackYaml stackYaml -> do
36 stackConf <- either fail pure =<< readStackConfig stackYaml
35 stackConf <- either fail pure =<< readStackConfig stackYaml
37− let buildPlanFile = LH.buildPlanFilePath (opts ^. optLtsHaskellRepo) (stackConf ^. scResolver)
38− buildPlan <- LH.loadBuildPlan buildPlanFile
39− packageSetConfig <- LH.buildPackageSetConfig
40− (opts ^. optHackageDb)
41− (opts ^. optAllCabalHashesRepo)
42− (opts ^. optNixpkgsRepository)
45− overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
46− stackPackagesConfig = mkStackPackagesConfig opts
47− stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb))
48− $ stackConf ^. scPackages
50− reachable = Set.map mkPackageName
52− $ nodeDepends . mkNode <$> stackConfPackages
53− s2nLoader mHash pkgId =
54− if pkgName pkgId `Set.member` reachable
55− then packageLoader packageSetConfig Nothing pkgId
56− else packageLoader packageSetConfig mHash pkgId
57− s2nPackageSetConfig = packageSetConfig { packageLoader = s2nLoader }
58− s2nPackageConfig = PackageConfig
60− , enableHaddock = True }
61− stackagePackages <- traverse (uncurry (buildNode s2nPackageSetConfig s2nPackageConfig))
62− $ Map.toAscList (bpPackages buildPlan)
64 generateStackage = opts ^. optWithStackage || opts ^. optWithStackageClosure
37 generateStackage = opts ^. optWithStackage || opts ^. optWithStackageClosure
38+ stackPackagesConfig = mkStackPackagesConfig opts
39+ stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb)) $ stackConf ^. scPackages
41+ case generateStackage of
42+ -- Generate Stackage packages from stack.yaml resolver
44+ let buildPlanFile = LH.buildPlanFilePath (opts ^. optLtsHaskellRepo) (stackConf ^. scResolver)
45+ buildPlan <- LH.loadBuildPlan buildPlanFile
46+ packageSetConfig <- LH.buildPackageSetConfig
47+ (opts ^. optHackageDb)
48+ (opts ^. optAllCabalHashesRepo)
49+ (opts ^. optNixpkgsRepository)
52+ overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
53+ reachable = Set.map mkPackageName
55+ $ nodeDepends . mkNode <$> stackConfPackages
56+ s2nLoader mHash pkgId =
57+ if pkgName pkgId `Set.member` reachable
58+ then packageLoader packageSetConfig Nothing pkgId
59+ else packageLoader packageSetConfig mHash pkgId
60+ s2nPackageSetConfig = packageSetConfig { packageLoader = s2nLoader }
61+ s2nPackageConfig = PackageConfig
63+ , enableHaddock = True }
64+ stackagePackages <- traverse (uncurry (buildNode s2nPackageSetConfig s2nPackageConfig))
65+ $ Map.toAscList (bpPackages buildPlan)
65− -- Nixpkgs generic-builder puts hscolour on path for all libraries
67+ -- Nixpkgs generic-builder puts hscolour on path for all libraries
66− withHscolour pkgs =
68+ withHscolour pkgs =
67− let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
69+ let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
68− in maybe pkgs (`Set.insert` pkgs) hscolour
70+ in maybe pkgs (`Set.insert` pkgs) hscolour
69− -- Find all reachable dependencies in stackage set to stick into
71+ -- Find all reachable dependencies in stackage set to stick into
70− -- stackage packages file. This is performed on the full stackage
72+ -- stackage packages file. This is performed on the full stackage
71− -- set rather than pruning stackage packages beforehand because
73+ -- set rather than pruning stackage packages beforehand because
72− -- stackage does not concern itself with build tools while cabal2nix
74+ -- stackage does not concern itself with build tools while cabal2nix
73− -- does: pruning only after generating full set of packages allows
75+ -- does: pruning only after generating full set of packages allows
74− -- us to make sure all those extra dependencies are explicitly
76+ -- us to make sure all those extra dependencies are explicitly
75− -- listed as well.
77+ -- listed as well.
76− nodes = case opts ^. optWithStackageClosure of
78+ nodes = case opts ^. optWithStackageClosure of
77− True -> Set.toAscList
79+ True -> Set.toAscList
78− $ withHscolour
80+ $ withHscolour
79− $ flip reachableDependencies stackagePackages
81+ $ flip reachableDependencies stackagePackages
80− -- Originally reachable nodes are root nodes
82+ -- Originally reachable nodes are root nodes
81− $ L.filter (\n -> mkPackageName (nodeName n) `Set.member` reachable) stackagePackages
83+ $ L.filter (\n -> mkPackageName (nodeName n) `Set.member` reachable) stackagePackages
82− False -> stackagePackages
84+ False -> stackagePackages
83− when generateStackage $ do
84− writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
85+ writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
85− $ pPrintOutPackages (view nodeDerivation <$> nodes)
86+ $ pPrintOutPackages (view nodeDerivation <$> nodes)
86− writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
87+ writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
87− $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
88+ $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
88− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
89+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
90− then PP.overrideHaskellPackages overrideConfig stackConfPackages
90+ $ PP.overrideHaskellPackages overrideConfig stackConfPackages
91− -- TODO: --lts-haskell and --all-cabal-caches unnecessary
91+
92+ -- Generate Stackage override only
94+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
92− else PP.overrideStackage (stackConf ^. scResolver) overrideConfig stackConfPackages
95+ $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
94 -- Generate Stackage packages from resolver
97 -- Generate Stackage packages from resolver
95 OriginResolver stackResolver -> do
98 OriginResolver stackResolver -> do