git.iko.soy/typeable/stackage2nix
on master help sign in
Upd enable tweak with exra-deps with cli flag

Adds --extra-deps-revision-latest cli flag

commit24ae7ab64be0766c9803ad9d4341a62ee97abf86 authorDmitry Bushev <bushevdv@gmail.com> dateFri 5 Jan 2018, 19:39 (9 years ago) parent6d71d97
3 files changed+64−26
CHANGELOG.md+9−1 src/Runner.hs+39−21 src/Runner/Cli.hs+16−4
CHANGELOG.md+9−1
@@ -11,8 +11,16 @@
1111
1212# 0.5.0
1313- Add `--with-stackage` and `--with-stackage-closure` flag generates stackage
14+- Add `--extra-deps-revision-latest` flag. Changes generation strategy for the
15+ direct dependencies of the stack.yaml extra-deps. Default strategy is to
16+ generate exact revision defined in the Stackage config. With this flag
17+ enabled, direct dependencies of the stack.yaml extra-deps will be generated
18+ with latest revision available on Hackage. This may help when Cabal fails to
19+ resolve dependencies of extra-deps, and dependences are fixed in the latest
20+ revision
1421- Upd override of stackage packages generated by default
15−- Upd generated Stackage packages with `doCheck` and `runHaddock` enabled by default
22+- Upd generated Stackage packages with `doCheck` and `runHaddock` enabled by
23+ default
1624- Remove `--do-check-stackage` flag (enabled by default)
1725- Remove `--do-haddock-stackage` flag (enabled by default)
1826- Remove `--no-packages-closure` flag (use `--with-stackage-closure`)
src/Runner.hs+39−21
@@ -11,7 +11,7 @@ import Distribution.Nixpkgs.Haskell.Stack
1111import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
1212import Distribution.Version (Version)
1313import Distribution.Compiler (AbiTag(..), unknownCompilerInfo)
14−import Distribution.Package (mkPackageName, pkgName)
14+import Distribution.Package (PackageName, mkPackageName, pkgName)
1515import Distribution.Text as Text (display)
1616import Language.Nix as Nix
1717import Options.Applicative
@@ -32,7 +32,7 @@ run = do
3232 opts <- execParser pinfo
3333 let
3434 -- With optparse-applicative it seems there's no way to make
35− -- 'StackageOptions' optional for stackage override and required in
35+ -- 'StackageOptions' optional for Stackage override and required in
3636 -- other cases
3737 missingErr = error . ("Missing required parameter: " <>)
3838 sopts = StackageOptions
@@ -46,25 +46,20 @@ run = do
4646 let
4747 stackResolver = stackConf ^. scResolver
4848 stackPackagesConfig = mkStackPackagesConfig opts
49− stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb))
49+ stackConfPackages <- traverse (fmap mkNode . packageDerivation stackPackagesConfig (opts ^. optHackageDb))
5050 $ stackConf ^. scPackages
51− let
52− reachable = Set.map mkPackageName
53− $ F.foldr1 Set.union
54− $ nodeDepends . mkNode <$> stackConfPackages
5551
5652 case buildTarget of
5753 TargetStackageClosure -> do
5854 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
5955 let
6056 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
61− stackageLoader mHash pkgId =
62− if pkgName pkgId `Set.member` reachable
63− then packageLoader packageSetConfig Nothing pkgId
64− else packageLoader packageSetConfig mHash pkgId
65− stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
57+ stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
58+ then extraDepsLatestConfig stackConfPackages packageSetConfig
59+ else packageSetConfig
6660 stackagePackages <- buildStackagePackages stackageSetConfig buildPlan
6761 let
62+ reachable = reachableDeps stackConfPackages
6863 -- Nixpkgs generic-builder puts hscolour on path for all libraries
6964 withHscolour pkgs =
7065 let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
@@ -86,28 +81,34 @@ run = do
8681 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
8782 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
8883 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
89− $ PP.overrideHaskellPackages overrideConfig stackConfPackages
84+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
9085
9186 TargetStackagePackages -> do
9287 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
9388 let
9489 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
95− stackageLoader mHash pkgId =
96− if pkgName pkgId `Set.member` reachable
97− then packageLoader packageSetConfig Nothing pkgId
98− else packageLoader packageSetConfig mHash pkgId
99− stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
90+ stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
91+ then extraDepsLatestConfig stackConfPackages packageSetConfig
92+ else packageSetConfig
93+ -- stackageLoader mHash pkgId =
94+ -- if pkgName pkgId `Set.member` reachable
95+ -- then packageLoader packageSetConfig Nothing pkgId
96+ -- else packageLoader packageSetConfig mHash pkgId
97+ -- stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
10098 nodes <- buildStackagePackages stackageSetConfig buildPlan
10199 writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
102100 $ pPrintOutPackages (view nodeDerivation <$> nodes)
103101 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
104102 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
105103 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
106− $ PP.overrideHaskellPackages overrideConfig stackConfPackages
104+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
107105
108106 TargetStackageOverride ->
109− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
110− $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
107+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
108+ PP.overrideStackage
109+ (stackConf ^. scResolver)
110+ (opts ^. optNixpkgsRepository)
111+ (view nodeDerivation <$> stackConfPackages)
111112
112113 -- Generate Stackage packages from resolver
113114 OriginResolver stackResolver -> do
@@ -141,6 +142,23 @@ buildStackagePackages packageSetConfig buildPlan = do
141142 traverse (uncurry (buildNode packageSetConfig stackagePackageConfig))
142143 $ Map.toAscList (bpPackages buildPlan)
143144
145+reachableDeps :: Traversable t => t Node -> Set.Set PackageName
146+reachableDeps = Set.map mkPackageName
147+ . F.foldr1 Set.union
148+ . fmap nodeDepends
149+
150+-- Return 'PackageSetConfig' with package loader that loads latest Hackage
151+-- revison for direct (reachable) dependencies of input packages
152+extraDepsLatestConfig :: Traversable t => t Node -> PackageSetConfig -> PackageSetConfig
153+extraDepsLatestConfig packages packageSetConfig =
154+ let
155+ reachable = reachableDeps packages
156+ stackageLoader mHash pkgId =
157+ if pkgName pkgId `Set.member` reachable
158+ then packageLoader packageSetConfig Nothing pkgId
159+ else packageLoader packageSetConfig mHash pkgId
160+ in packageSetConfig { packageLoader = stackageLoader }
161+
144162writeOutFile :: Show source => source -> FilePath -> Doc -> IO ()
145163writeOutFile source filePath contents =
146164 withFile filePath WriteMode $ \h -> do
src/Runner/Cli.hs+16−4
@@ -12,9 +12,14 @@ import Options.Applicative as Opts
1212import Paths_stackage2nix ( version )
1313import Stack.Config
1414import Stack.Types
15−import System.Environment
1615import System.FilePath
1716
17+data Tweaks = Tweaks
18+ { _tExtraDepsRevisionLatest :: Bool
19+ } deriving (Show)
20+
21+makeLenses ''Tweaks
22+
1823-- | What will be generated
1924data Target
2025 = TargetStackagePackages
@@ -49,6 +54,7 @@ data Options = Options
4954 , _optOutDerivation :: FilePath
5055 , _optDoCheckPackages :: Bool
5156 , _optDoHaddockPackages :: Bool
57+ , _optTweaks :: Tweaks
5258 , _optHackageDb :: Maybe HackageDb
5359 , _optNixpkgsRepository :: FilePath
5460 , _optCompilerId :: CompilerId
@@ -58,9 +64,6 @@ data Options = Options
5864
5965makeLenses ''Options
6066
61−envStackYaml :: IO (Maybe StackYaml)
62−envStackYaml = fmap mkStackYaml <$> lookupEnv "STACK_YAML"
63−
6467mkStackYaml :: FilePath -> StackYaml
6568mkStackYaml p = case splitFileName p of
6669 (dir, "") -> StackYaml dir "stack.yaml"
@@ -77,6 +80,7 @@ options = Options
7780 <*> outDerivation
7881 <*> doCheckPackages
7982 <*> doHaddockPackages
83+ <*> tweaks
8084 <*> optional hackageDb
8185 <*> nixpkgsRepository
8286 <*> compilerId
@@ -155,6 +159,14 @@ withStackageClosure = flag' ()
155159 ( long "with-stackage-closure"
156160 <> help "generate Stackage subset containing only build dependencies" )
157161
162+extraDepsRevisionLatest :: Parser Bool
163+extraDepsRevisionLatest = switch
164+ ( long "extra-deps-revision-latest"
165+ <> help "Changes algorithm for the dependencies generation of the stack.yaml extra-deps. Default one is to generate exact revision defined in the Stackage config. With this flag enabled, direct dependencies of the stack.yaml extra-deps will be generated with the latest revision available on Hackage. This may help when Cabal fails to resolve dependencies of extra-deps, and dependences are fixed in the latest revision" )
166+
167+tweaks :: Parser Tweaks
168+tweaks = Tweaks <$> extraDepsRevisionLatest
169+
158170resolver :: Parser StackResolver
159171resolver = StackResolver <$> option text
160172 ( long "resolver"