git.iko.soy/typeable/stackage2nix
on master help sign in
Generate Stack packages and Stackage separately
commit40216b81567ba6c5c2101fef21e408477bee3f62 authorDmitry Bushev <bushevdv@gmail.com> dateTue 2 Jan 2018, 16:47 (9 years ago) parentaac2111
2 files changed+68−70
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+10−15 src/Runner.hs+58−55
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+10−15
@@ -30,6 +30,11 @@ makeLenses ''OverrideConfig
3030systemNixpkgs :: Doc
3131systemNixpkgs = "<nixpkgs>"
3232
33+renderNixpkgs :: FilePath -> Doc
34+renderNixpkgs nixpkgsPath
35+ | fromString nixpkgsPath == systemNixpkgs = systemNixpkgs
36+ | otherwise = disp $ (fromString nixpkgsPath :: Nix.FilePath)
37+
3338hasField :: Lens' a (Maybe b) -> a -> Bool
3439hasField p = views p isJust
3540
@@ -50,14 +55,9 @@ importStackageConfig path = hsep
5055 ["import ", disp (fromString path :: Nix.FilePath), "{ inherit pkgs haskellLib; }"]
5156
5257overrideHaskellPackages :: OverrideConfig -> NonEmpty Derivation -> Doc
53−overrideHaskellPackages oc packages =
54− let
55− nixpkgs = if oc ^. ocNixpkgs . to fromString == systemNixpkgs
56− then systemNixpkgs
57− else (disp . (fromString :: FilePath -> Nix.FilePath)) (oc ^. ocNixpkgs)
58− in vcat
58+overrideHaskellPackages oc packages = vcat
5959 [ funargs
60− [ "nixpkgs ? import " <> nixpkgs <> " {}"
60+ [ "nixpkgs ? import " <> renderNixpkgs (oc ^. ocNixpkgs) <> " {}"
6161 ]
6262 , ""
6363 , "with nixpkgs;"
@@ -88,15 +88,10 @@ overrideHaskellPackages oc packages =
8888 , "}"
8989 ]
9090
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
91+overrideStackage :: StackResolver -> FilePath -> NonEmpty Derivation -> Doc
92+overrideStackage stackResolver nixpkgsPath packages = vcat
9893 [ funargs
99− [ "nixpkgs ? import " <> nixpkgs <> " {}"
94+ [ "nixpkgs ? import " <> renderNixpkgs nixpkgsPath <> " {}"
10095 ]
10196 , ""
10297 , "let"
src/Runner.hs+58−55
@@ -1,7 +1,6 @@
11module Runner ( run ) where
22
33import Control.Lens
4−import Control.Monad
54import Data.Foldable as F
65import Data.List as L
76import Distribution.Nixpkgs.Haskell.FromStack
@@ -34,62 +33,66 @@ run = do
3433 -- Generate build derivation from stack.yaml file
3534 OriginStackYaml stackYaml -> do
3635 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)
43− buildPlan
44− let
45− overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
46− stackPackagesConfig = mkStackPackagesConfig opts
47− stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb))
48− $ stackConf ^. scPackages
49− let
50− reachable = Set.map mkPackageName
51− $ F.foldr1 Set.union
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
59− { enableCheck = True
60− , enableHaddock = True }
61− stackagePackages <- traverse (uncurry (buildNode s2nPackageSetConfig s2nPackageConfig))
62− $ Map.toAscList (bpPackages buildPlan)
6336 let
6437 generateStackage = opts ^. optWithStackage || opts ^. optWithStackageClosure
65− -- Nixpkgs generic-builder puts hscolour on path for all libraries
66− withHscolour pkgs =
67− let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
68− in maybe pkgs (`Set.insert` pkgs) hscolour
69− -- Find all reachable dependencies in stackage set to stick into
70− -- stackage packages file. This is performed on the full stackage
71− -- set rather than pruning stackage packages beforehand because
72− -- stackage does not concern itself with build tools while cabal2nix
73− -- does: pruning only after generating full set of packages allows
74− -- us to make sure all those extra dependencies are explicitly
75− -- listed as well.
76− nodes = case opts ^. optWithStackageClosure of
77− True -> Set.toAscList
78− $ withHscolour
79− $ flip reachableDependencies stackagePackages
80− -- Originally reachable nodes are root nodes
81− $ L.filter (\n -> mkPackageName (nodeName n) `Set.member` reachable) stackagePackages
82− False -> stackagePackages
83− when generateStackage $ do
84− writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
85− $ pPrintOutPackages (view nodeDerivation <$> nodes)
86− writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
87− $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
88− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
89− if generateStackage
90− then PP.overrideHaskellPackages overrideConfig stackConfPackages
91− -- TODO: --lts-haskell and --all-cabal-caches unnecessary
92− else PP.overrideStackage (stackConf ^. scResolver) overrideConfig stackConfPackages
38+ stackPackagesConfig = mkStackPackagesConfig opts
39+ stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb)) $ stackConf ^. scPackages
40+
41+ case generateStackage of
42+ -- Generate Stackage packages from stack.yaml resolver
43+ True -> do
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)
50+ buildPlan
51+ let
52+ overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
53+ reachable = Set.map mkPackageName
54+ $ F.foldr1 Set.union
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
62+ { enableCheck = True
63+ , enableHaddock = True }
64+ stackagePackages <- traverse (uncurry (buildNode s2nPackageSetConfig s2nPackageConfig))
65+ $ Map.toAscList (bpPackages buildPlan)
66+ let
67+ -- Nixpkgs generic-builder puts hscolour on path for all libraries
68+ withHscolour pkgs =
69+ let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
70+ in maybe pkgs (`Set.insert` pkgs) hscolour
71+ -- Find all reachable dependencies in stackage set to stick into
72+ -- stackage packages file. This is performed on the full stackage
73+ -- set rather than pruning stackage packages beforehand because
74+ -- stackage does not concern itself with build tools while cabal2nix
75+ -- does: pruning only after generating full set of packages allows
76+ -- us to make sure all those extra dependencies are explicitly
77+ -- listed as well.
78+ nodes = case opts ^. optWithStackageClosure of
79+ True -> Set.toAscList
80+ $ withHscolour
81+ $ flip reachableDependencies stackagePackages
82+ -- Originally reachable nodes are root nodes
83+ $ L.filter (\n -> mkPackageName (nodeName n) `Set.member` reachable) stackagePackages
84+ False -> stackagePackages
85+ writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
86+ $ pPrintOutPackages (view nodeDerivation <$> nodes)
87+ writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
88+ $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
89+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
90+ $ PP.overrideHaskellPackages overrideConfig stackConfPackages
91+
92+ -- Generate Stackage override only
93+ False ->
94+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
95+ $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
9396
9497 -- Generate Stackage packages from resolver
9598 OriginResolver stackResolver -> do