git.iko.soy/typeable/stackage2nix
on master help sign in
Generate Stack packages and Stackage separately
40216b8Dmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+10−15
@@ -30,6 +30,11 @@ makeLenses ''OverrideConfig
30systemNixpkgs :: Doc
30systemNixpkgs :: Doc
31systemNixpkgs = "<nixpkgs>"
31systemNixpkgs = "<nixpkgs>"
32
32
33+renderNixpkgs :: FilePath -> Doc
34+renderNixpkgs nixpkgsPath
35+ | fromString nixpkgsPath == systemNixpkgs = systemNixpkgs
36+ | otherwise = disp $ (fromString nixpkgsPath :: Nix.FilePath)
37+
33hasField :: Lens' a (Maybe b) -> a -> Bool
38hasField :: Lens' a (Maybe b) -> a -> Bool
34hasField p = views p isJust
39hasField p = views p isJust
35
40
@@ -50,14 +55,9 @@ importStackageConfig path = hsep
50 ["import ", disp (fromString path :: Nix.FilePath), "{ inherit pkgs haskellLib; }"]
55 ["import ", disp (fromString path :: Nix.FilePath), "{ inherit pkgs haskellLib; }"]
51
56
52overrideHaskellPackages :: OverrideConfig -> NonEmpty Derivation -> Doc
57overrideHaskellPackages :: OverrideConfig -> NonEmpty Derivation -> Doc
53−overrideHaskellPackages oc packages =
58+overrideHaskellPackages oc packages = vcat
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
59 [ funargs
59 [ funargs
60− [ "nixpkgs ? import " <> nixpkgs <> " {}"
60+ [ "nixpkgs ? import " <> renderNixpkgs (oc ^. ocNixpkgs) <> " {}"
61 ]
61 ]
62 , ""
62 , ""
63 , "with nixpkgs;"
63 , "with nixpkgs;"
@@ -88,15 +88,10 @@ overrideHaskellPackages oc packages =
88 , "}"
88 , "}"
89 ]
89 ]
90
90
91−overrideStackage :: StackResolver -> OverrideConfig -> NonEmpty Derivation -> Doc
91+overrideStackage :: StackResolver -> FilePath -> NonEmpty Derivation -> Doc
92−overrideStackage stackResolver oc packages =
92+overrideStackage stackResolver nixpkgsPath packages = vcat
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
93 [ funargs
99− [ "nixpkgs ? import " <> nixpkgs <> " {}"
94+ [ "nixpkgs ? import " <> renderNixpkgs nixpkgsPath <> " {}"
100 ]
95 ]
101 , ""
96 , ""
102 , "let"
97 , "let"
src/Runner.hs+58−55
@@ -1,7 +1,6 @@
1module Runner ( run ) where
1module Runner ( run ) where
2
2
3import Control.Lens
3import Control.Lens
4−import Control.Monad
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)
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)
63 let
36 let
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
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
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)
89− if generateStackage
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
93+ False ->
94+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
92− else PP.overrideStackage (stackConf ^. scResolver) overrideConfig stackConfPackages
95+ $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
93
96
94 -- Generate Stackage packages from resolver
97 -- Generate Stackage packages from resolver
95 OriginResolver stackResolver -> do
98 OriginResolver stackResolver -> do