git.iko.soy/typeable/stackage2nix
on master help sign in
Generate stack-yaml-packages.nix file
683b3ffDmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack/PrettyPrinting.hs+7−8
@@ -75,7 +75,6 @@ overrideHaskellPackages oc packages = vcat
75 , nest 2 "inherit pkgs stdenv;"
75 , nest 2 "inherit pkgs stdenv;"
76 , nest 2 "inherit (self) callPackage;"
76 , nest 2 "inherit (self) callPackage;"
77 , "};"
77 , "};"
78− , attr "stackYamlPackages" (stackYamlPackages $ pkgName . packageId <$> packages)
79 ]
78 ]
80 , "in callPackage (nixpkgs.path + \"/pkgs/development/haskell-modules\") {"
79 , "in callPackage (nixpkgs.path + \"/pkgs/development/haskell-modules\") {"
81 , nest 2 $ vcat
80 , nest 2 $ vcat
@@ -86,9 +85,10 @@ overrideHaskellPackages oc packages = vcat
86 , attr "configurationCommon" "args: self: super: {}"
85 , attr "configurationCommon" "args: self: super: {}"
87 , "inherit haskellLib;"
86 , "inherit haskellLib;"
88 ]
87 ]
89− , "} // { inherit stackYamlPackages; }"
88+ , "}"
89+ ]
90− ] where
90+ where
91− nixGhc = toNixGhcVersion (oc ^. ocGhc)
91+ nixGhc = toNixGhcVersion (oc ^. ocGhc)
92
92
93overrideStackage :: StackResolver -> FilePath -> NonEmpty Derivation -> Doc
93overrideStackage :: StackResolver -> FilePath -> NonEmpty Derivation -> Doc
94overrideStackage stackResolver nixpkgsPath packages = vcat
94overrideStackage stackResolver nixpkgsPath packages = vcat
@@ -100,12 +100,11 @@ overrideStackage stackResolver nixpkgsPath packages = vcat
100 , nest 2 $ vcat
100 , nest 2 $ vcat
101 [ "stackPackages ="
101 [ "stackPackages ="
102 , nest 2 $ overridePackages packages <> semi
102 , nest 2 $ overridePackages packages <> semi
103− , attr "stackYamlPackages" (stackYamlPackages $ pkgName . packageId <$> packages)
104 ]
103 ]
105 , "in nixpkgs.haskell.packages.stackage." <> toNixStackResolver stackResolver <> ".override {"
104 , "in nixpkgs.haskell.packages.stackage." <> toNixStackResolver stackResolver <> ".override {"
106 , nest 2
105 , nest 2
107 $ attr "packageSetConfig" "self: super: stackPackages { inherit (nixpkgs) pkgs stdenv; inherit (self) callPackage; } super"
106 $ attr "packageSetConfig" "self: super: stackPackages { inherit (nixpkgs) pkgs stdenv; inherit (self) callPackage; } super"
108− , "} // { inherit stackYamlPackages; }"
107+ , "}"
109 ]
108 ]
110
109
111pPrintHaskellPackages :: OverrideConfig -> Doc
110pPrintHaskellPackages :: OverrideConfig -> Doc
@@ -148,14 +147,14 @@ pPrintHaskellPackages oc = vcat
148 , "in extensible-self"
147 , "in extensible-self"
149 ]
148 ]
150
149
151−stackYamlPackages :: NonEmpty PackageName -> Doc
150+stackYamlPackages :: NonEmpty Derivation -> Doc
152stackYamlPackages packages = hcat
151stackYamlPackages packages = hcat
153 [ "self: { "
152 [ "self: { "
154 , "inherit (self) "
153 , "inherit (self) "
155 , text . intercalate " " $ NE.toList packageNames
154 , text . intercalate " " $ NE.toList packageNames
156 , "; }" ]
155 , "; }" ]
157 where
156 where
158− packageNames = unPackageName <$> packages
157+ packageNames = unPackageName . pkgName . packageId <$> packages
159
158
160toNixGhcVersion :: Version -> Doc
159toNixGhcVersion :: Version -> Doc
161toNixGhcVersion = (<>) "ghc" . toNixVersion . show . disp
160toNixGhcVersion = (<>) "ghc" . toNixVersion . show . disp
src/Runner.hs+20−12
@@ -25,8 +25,9 @@ import Stackage.Types
25import System.IO (withFile, IOMode(..), hPutStrLn)
25import System.IO (withFile, IOMode(..), hPutStrLn)
26import Text.PrettyPrint.HughesPJClass (Doc, render)
26import Text.PrettyPrint.HughesPJClass (Doc, render)
27
27
28−import qualified Data.Set as Set
28+import qualified Data.List.NonEmpty as NE
29import qualified Data.Map as Map
29import qualified Data.Map as Map
30+import qualified Data.Set as Set
30import qualified LtsHaskell as LH
31import qualified LtsHaskell as LH
31
32
32run :: IO ()
33run :: IO ()
@@ -51,6 +52,11 @@ run = do
51 stackPackagesConfig = mkStackPackagesConfig opts
52 stackPackagesConfig = mkStackPackagesConfig opts
52 stackConfPackages <- traverse (fmap mkNode . packageDerivation stackPackagesConfig hackageDb)
53 stackConfPackages <- traverse (fmap mkNode . packageDerivation stackPackagesConfig hackageDb)
53 $ stackConf ^. scPackages
54 $ stackConf ^. scPackages
55+ stackConfExtraDeps <- traverse (fmap mkNode . packageDerivation stackPackagesConfig hackageDb)
56+ $ stackConf ^. scExtraDeps
57+ let
58+ stackConfAllPackages = maybe stackConfPackages ((<>) stackConfPackages)
59+ $ NE.nonEmpty stackConfExtraDeps
54
60
55 case buildTarget of
61 case buildTarget of
56 TargetStackageClosure -> do
62 TargetStackageClosure -> do
@@ -58,11 +64,11 @@ run = do
58 let
64 let
59 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
65 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
60 stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
66 stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
61− then extraDepsLatestConfig stackConfPackages packageSetConfig
67+ then extraDepsLatestConfig stackConfAllPackages packageSetConfig
62 else packageSetConfig
68 else packageSetConfig
63 stackagePackages <- buildStackagePackages stackageSetConfig buildPlan
69 stackagePackages <- buildStackagePackages stackageSetConfig buildPlan
64 let
70 let
65− reachable = reachableDeps stackConfPackages
71+ reachable = reachableDeps stackConfAllPackages
66 -- Nixpkgs generic-builder puts hscolour on path for all libraries
72 -- Nixpkgs generic-builder puts hscolour on path for all libraries
67 withHscolour pkgs =
73 withHscolour pkgs =
68 let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
74 let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
@@ -84,14 +90,14 @@ run = do
84 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
90 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
85 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
91 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
86 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
92 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
87− $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
93+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfAllPackages)
88
94
89 TargetStackagePackages -> do
95 TargetStackagePackages -> do
90 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan hackageDb stackResolver opts sopts
96 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan hackageDb stackResolver opts sopts
91 let
97 let
92 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
98 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
93 stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
99 stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
94− then extraDepsLatestConfig stackConfPackages packageSetConfig
100+ then extraDepsLatestConfig stackConfAllPackages packageSetConfig
95 else packageSetConfig
101 else packageSetConfig
96 -- stackageLoader mHash pkgId =
102 -- stackageLoader mHash pkgId =
97 -- if pkgName pkgId `Set.member` reachable
103 -- if pkgName pkgId `Set.member` reachable
@@ -104,14 +110,16 @@ run = do
104 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
110 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
105 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
111 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
106 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
112 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
107− $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
113+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfAllPackages)
108
114
109− TargetStackageOverride ->
115+ TargetStackageOverride -> do
110− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
116+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
111− PP.overrideStackage
117+ $ PP.overrideStackage
112− (stackConf ^. scResolver)
118+ (stackConf ^. scResolver)
113− (opts ^. optNixpkgsRepository)
119+ (opts ^. optNixpkgsRepository)
120+ (view nodeDerivation <$> stackConfAllPackages)
121+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutStackYamlPackages)
114− (view nodeDerivation <$> stackConfPackages)
122+ $ PP.stackYamlPackages (view nodeDerivation <$> stackConfPackages)
115
123
116 -- Generate Stackage packages from resolver
124 -- Generate Stackage packages from resolver
117 OriginResolver stackResolver -> do
125 OriginResolver stackResolver -> do
src/Runner/Cli.hs+23−13
@@ -46,19 +46,20 @@ data StackageOptions = StackageOptions
46makeLenses ''StackageOptions
46makeLenses ''StackageOptions
47
47
48data Options = Options
48data Options = Options
49− { _optAllCabalHashesRepo :: Maybe FilePath
49+ { _optAllCabalHashesRepo :: Maybe FilePath
50− , _optLtsHaskellRepo :: Maybe FilePath
50+ , _optLtsHaskellRepo :: Maybe FilePath
51− , _optOutStackagePackages :: FilePath
51+ , _optOutStackagePackages :: FilePath
52− , _optOutStackageConfig :: FilePath
52+ , _optOutStackageConfig :: FilePath
53− , _optOutDerivation :: FilePath
53+ , _optOutDerivation :: FilePath
54+ , _optOutStackYamlPackages :: FilePath
54− , _optDoCheckPackages :: Bool
55+ , _optDoCheckPackages :: Bool
55− , _optDoHaddockPackages :: Bool
56+ , _optDoHaddockPackages :: Bool
56− , _optTweaks :: Tweaks
57+ , _optTweaks :: Tweaks
57− , _optHackageDb :: Maybe FilePath
58+ , _optHackageDb :: Maybe FilePath
58− , _optNixpkgsRepository :: FilePath
59+ , _optNixpkgsRepository :: FilePath
59− , _optCompilerId :: CompilerId
60+ , _optCompilerId :: CompilerId
60− , _optPlatform :: Platform
61+ , _optPlatform :: Platform
61− , _optConfigOrigin :: ConfigOrigin
62+ , _optConfigOrigin :: ConfigOrigin
62 } deriving (Show)
63 } deriving (Show)
63
64
64makeLenses ''Options
65makeLenses ''Options
@@ -79,6 +80,7 @@ options = Options
79 <*> outStackagePackages
80 <*> outStackagePackages
80 <*> outStackageConfig
81 <*> outStackageConfig
81 <*> outDerivation
82 <*> outDerivation
83+ <*> outStackYamlPackages
82 <*> doCheckPackages
84 <*> doCheckPackages
83 <*> doHaddockPackages
85 <*> doHaddockPackages
84 <*> tweaks
86 <*> tweaks
@@ -140,6 +142,14 @@ outDerivation = option str
140 <> value "default.nix"
142 <> value "default.nix"
141 <> showDefaultWith id )
143 <> showDefaultWith id )
142
144
145+outStackYamlPackages :: Parser FilePath
146+outStackYamlPackages = option str
147+ ( long "out-stack-yaml-packages"
148+ <> metavar "NIX_FILE"
149+ <> help "path to output stackage.yaml packages list"
150+ <> value "stack-yaml-packages.nix"
151+ <> showDefaultWith id )
152+
143doCheckPackages :: Parser Bool
153doCheckPackages :: Parser Bool
144doCheckPackages = flag True False
154doCheckPackages = flag True False
145 ( long "no-check"
155 ( long "no-check"
src/Stack/Config.hs+20−7
@@ -6,7 +6,7 @@ import Control.Lens
6import Data.Bifunctor
6import Data.Bifunctor
7import Data.ByteString as BS
7import Data.ByteString as BS
8import Data.Coerce
8import Data.Coerce
9−import Data.Foldable as F
9+import Data.List as L
10import Data.List.NonEmpty as NE
10import Data.List.NonEmpty as NE
11import Data.Maybe
11import Data.Maybe
12import Data.Semigroup
12import Data.Semigroup
@@ -72,22 +72,35 @@ makeLenses ''StackPackage
72data StackConfig = StackConfig
72data StackConfig = StackConfig
73 { _scResolver :: StackResolver
73 { _scResolver :: StackResolver
74 , _scPackages :: NonEmpty StackPackage
74 , _scPackages :: NonEmpty StackPackage
75+ , _scExtraDeps :: [StackPackage]
75 } deriving (Eq, Ord, Show)
76 } deriving (Eq, Ord, Show)
76
77
77makeLenses ''StackConfig
78makeLenses ''StackConfig
78
79
80+scAllPackages :: Getter StackConfig (NonEmpty StackPackage)
81+scAllPackages = to allPs
82+ where
83+ allPs sc = maybe ps ((<>) ps) (NE.nonEmpty ed)
84+ where
85+ ps = sc ^. scPackages
86+ ed = sc ^. scExtraDeps
87+
79fromYamlConfig :: Yaml.Config -> StackConfig
88fromYamlConfig :: Yaml.Config -> StackConfig
80fromYamlConfig c = StackConfig{..}
89fromYamlConfig c = StackConfig{..}
81 where
90 where
82 _scResolver = coerce $ c ^. cResolver
91 _scResolver = coerce $ c ^. cResolver
83− -- 'NE.nub' replicates Stack behavior of having a Set of packages rather than list
92+ -- 'nub' replicates Stack behavior of having a Set of packages rather than list
84− _scPackages = NE.nub $ F.foldl' (<>) nePackages yamlExtraDeps
93+ _scPackages = NE.nub nePackages
94+ _scExtraDeps = L.nub $ extraDeps ++ yamlExtraDeps
85 nePackages = fromMaybe (pure defaultPackage)
95 nePackages = fromMaybe (pure defaultPackage)
86− $ fmap sconcat
87− $ NE.nonEmpty yamlPackages
96+ $ NE.nonEmpty packages
97+ -- yaml packages section can contain extra-deps
98+ (extraDeps, packages) = L.partition (view spExtraDep) yamlPackages
99+ yamlPackages = L.concatMap NE.toList
88− yamlPackages = fromYamlPackage packagesSimplePath False
100+ $ fromYamlPackage packagesSimplePath False
89 <$> fromMaybe mempty (c ^. cPackages)
101 <$> fromMaybe mempty (c ^. cPackages)
102+ yamlExtraDeps = L.concatMap NE.toList
90− yamlExtraDeps = fromYamlPackage extraDepsSimplePath True
103+ $ fromYamlPackage extraDepsSimplePath True
91 <$> fromMaybe mempty (c ^. cExtraDeps)
104 <$> fromMaybe mempty (c ^. cExtraDeps)
92 defaultPackage = StackPackage (PlFilePath ".") False Nothing
105 defaultPackage = StackPackage (PlFilePath ".") False Nothing
93
106
test/Stack/ConfigSpec.hs+22−18
@@ -51,6 +51,7 @@ minimalConf = StackConfig
51 { _scResolver = StackResolver "lts-10.0"
51 { _scResolver = StackResolver "lts-10.0"
52 , _scPackages = NE.fromList
52 , _scPackages = NE.fromList
53 [ StackPackage (PlFilePath ".") False Nothing]
53 [ StackPackage (PlFilePath ".") False Nothing]
54+ , _scExtraDeps = []
54 }
55 }
55
56
56packageDefaultBs :: ByteString
57packageDefaultBs :: ByteString
@@ -73,10 +74,11 @@ packages:
73
74
74packageSimpleListConf :: StackConfig
75packageSimpleListConf :: StackConfig
75packageSimpleListConf = StackConfig
76packageSimpleListConf = StackConfig
76− { _scResolver = StackResolver "lts-10.0"
77+ { _scResolver = StackResolver "lts-10.0"
77− , _scPackages = NE.fromList
78+ , _scPackages = NE.fromList
78 [ StackPackage (PlFilePath "client") False Nothing
79 [ StackPackage (PlFilePath "client") False Nothing
79 , StackPackage (PlFilePath "server") False Nothing ]
80 , StackPackage (PlFilePath "server") False Nothing ]
81+ , _scExtraDeps = []
80 }
82 }
81
83
82packageLocationsBs :: ByteString
84packageLocationsBs :: ByteString
@@ -102,11 +104,12 @@ packages:
102
104
103packageLocationsConf :: StackConfig
105packageLocationsConf :: StackConfig
104packageLocationsConf = StackConfig
106packageLocationsConf = StackConfig
105− { _scResolver = StackResolver "lts-10.0"
107+ { _scResolver = StackResolver "lts-10.0"
106− , _scPackages = NE.fromList
108+ , _scPackages = NE.fromList
107 [ StackPackage (PlFilePath "humble/package") False (Just "client")
109 [ StackPackage (PlFilePath "humble/package") False (Just "client")
108− , StackPackage (PlFilePath "humble/package") False (Just "server")
110+ , StackPackage (PlFilePath "humble/package") False (Just "server") ]
111+ , _scExtraDeps =
109− , StackPackage (PlUri $ stUri "https://example.com/foo/bar/baz-0.0.2.tar.gz") True (Just "extra")
112+ [ StackPackage (PlUri $ stUri "https://example.com/foo/bar/baz-0.0.2.tar.gz") True (Just "extra")
110 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir1")
113 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir1")
111 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir2")
114 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir2")
112 ]
115 ]
@@ -122,10 +125,10 @@ extra-deps:
122
125
123packageExtraDepsConf :: StackConfig
126packageExtraDepsConf :: StackConfig
124packageExtraDepsConf = StackConfig
127packageExtraDepsConf = StackConfig
125− { _scResolver = StackResolver "lts-10.0"
128+ { _scResolver = StackResolver "lts-10.0"
126− , _scPackages = NE.fromList
127− [ StackPackage (PlFilePath ".") False Nothing
129+ , _scPackages = NE.fromList [ StackPackage (PlFilePath ".") False Nothing ]
130+ , _scExtraDeps =
128− , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
131+ [ StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
129 , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
132 , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
130 }
133 }
131
134
@@ -142,11 +145,12 @@ extra-deps:
142
145
143packageMixedConf :: StackConfig
146packageMixedConf :: StackConfig
144packageMixedConf = StackConfig
147packageMixedConf = StackConfig
145− { _scResolver = StackResolver "lts-10.0"
148+ { _scResolver = StackResolver "lts-10.0"
146− , _scPackages = NE.fromList
149+ , _scPackages = NE.fromList
147 [ StackPackage (PlFilePath "client") False Nothing
150 [ StackPackage (PlFilePath "client") False Nothing
148− , StackPackage (PlFilePath "server") False Nothing
151+ , StackPackage (PlFilePath "server") False Nothing ]
152+ , _scExtraDeps =
149− , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
153+ [ StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
150 , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
154 , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
151 }
155 }
152
156
@@ -172,10 +176,10 @@ extra-deps:
172
176
173packageExtraDepsNewConf :: StackConfig
177packageExtraDepsNewConf :: StackConfig
174packageExtraDepsNewConf = StackConfig
178packageExtraDepsNewConf = StackConfig
175− { _scResolver = StackResolver "lts-10.0"
179+ { _scResolver = StackResolver "lts-10.0"
176− , _scPackages = NE.fromList
177− [ StackPackage (PlFilePath ".") False Nothing
180+ , _scPackages = NE.fromList [ StackPackage (PlFilePath ".") False Nothing ]
181+ , _scExtraDeps =
178− , StackPackage (PlFilePath "vendor/lib") True Nothing
182+ [ StackPackage (PlFilePath "vendor/lib") True Nothing
179 , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
183 , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
180 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "auto-update")
184 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "auto-update")
181 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "wai")
185 , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "wai")