git.iko.soy/typeable/stackage2nix
on master help sign in
Upd enable tweak with exra-deps with cli flag
24ae7abDmitry Bushev
CHANGELOG.md+9−1
@@ -11,8 +11,16 @@
11
11
12# 0.5.0
12# 0.5.0
13- Add `--with-stackage` and `--with-stackage-closure` flag generates stackage
13- 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
14- Upd override of stackage packages generated by default
21- 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
16- Remove `--do-check-stackage` flag (enabled by default)
24- Remove `--do-check-stackage` flag (enabled by default)
17- Remove `--do-haddock-stackage` flag (enabled by default)
25- Remove `--do-haddock-stackage` flag (enabled by default)
18- Remove `--no-packages-closure` flag (use `--with-stackage-closure`)
26- Remove `--no-packages-closure` flag (use `--with-stackage-closure`)
src/Runner.hs+39−21
@@ -11,7 +11,7 @@ import Distribution.Nixpkgs.Haskell.Stack
11import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
11import Distribution.Nixpkgs.Haskell.Stack.PrettyPrinting as PP
12import Distribution.Version (Version)
12import Distribution.Version (Version)
13import Distribution.Compiler (AbiTag(..), unknownCompilerInfo)
13import Distribution.Compiler (AbiTag(..), unknownCompilerInfo)
14−import Distribution.Package (mkPackageName, pkgName)
14+import Distribution.Package (PackageName, mkPackageName, pkgName)
15import Distribution.Text as Text (display)
15import Distribution.Text as Text (display)
16import Language.Nix as Nix
16import Language.Nix as Nix
17import Options.Applicative
17import Options.Applicative
@@ -32,7 +32,7 @@ run = do
32 opts <- execParser pinfo
32 opts <- execParser pinfo
33 let
33 let
34 -- With optparse-applicative it seems there's no way to make
34 -- 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
36 -- other cases
36 -- other cases
37 missingErr = error . ("Missing required parameter: " <>)
37 missingErr = error . ("Missing required parameter: " <>)
38 sopts = StackageOptions
38 sopts = StackageOptions
@@ -46,25 +46,20 @@ run = do
46 let
46 let
47 stackResolver = stackConf ^. scResolver
47 stackResolver = stackConf ^. scResolver
48 stackPackagesConfig = mkStackPackagesConfig opts
48 stackPackagesConfig = mkStackPackagesConfig opts
49− stackConfPackages <- traverse (packageDerivation stackPackagesConfig (opts ^. optHackageDb))
49+ stackConfPackages <- traverse (fmap mkNode . packageDerivation stackPackagesConfig (opts ^. optHackageDb))
50 $ stackConf ^. scPackages
50 $ stackConf ^. scPackages
51− let
52− reachable = Set.map mkPackageName
53− $ F.foldr1 Set.union
54− $ nodeDepends . mkNode <$> stackConfPackages
55
51
56 case buildTarget of
52 case buildTarget of
57 TargetStackageClosure -> do
53 TargetStackageClosure -> do
58 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
54 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
59 let
55 let
60 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
56 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
61− stackageLoader mHash pkgId =
57+ stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
62− if pkgName pkgId `Set.member` reachable
58+ then extraDepsLatestConfig stackConfPackages packageSetConfig
63− then packageLoader packageSetConfig Nothing pkgId
64− else packageLoader packageSetConfig mHash pkgId
59+ else packageSetConfig
65− stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
66 stackagePackages <- buildStackagePackages stackageSetConfig buildPlan
60 stackagePackages <- buildStackagePackages stackageSetConfig buildPlan
67 let
61 let
62+ reachable = reachableDeps stackConfPackages
68 -- Nixpkgs generic-builder puts hscolour on path for all libraries
63 -- Nixpkgs generic-builder puts hscolour on path for all libraries
69 withHscolour pkgs =
64 withHscolour pkgs =
70 let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
65 let hscolour = F.find ((== "hscolour") . nodeName) stackagePackages
@@ -86,28 +81,34 @@ run = do
86 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
81 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
87 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
82 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
88 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
83 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
89− $ PP.overrideHaskellPackages overrideConfig stackConfPackages
84+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
90
85
91 TargetStackagePackages -> do
86 TargetStackagePackages -> do
92 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
87 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
93 let
88 let
94 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
89 overrideConfig = mkOverrideConfig opts (siGhcVersion $ bpSystemInfo buildPlan)
90+ stackageSetConfig = if opts ^. optTweaks . tExtraDepsRevisionLatest
91+ then extraDepsLatestConfig stackConfPackages packageSetConfig
92+ else packageSetConfig
95− stackageLoader mHash pkgId =
93+ -- stackageLoader mHash pkgId =
96− if pkgName pkgId `Set.member` reachable
94+ -- if pkgName pkgId `Set.member` reachable
97− then packageLoader packageSetConfig Nothing pkgId
95+ -- then packageLoader packageSetConfig Nothing pkgId
98− else packageLoader packageSetConfig mHash pkgId
96+ -- else packageLoader packageSetConfig mHash pkgId
99− stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
97+ -- stackageSetConfig = packageSetConfig { packageLoader = stackageLoader }
100 nodes <- buildStackagePackages stackageSetConfig buildPlan
98 nodes <- buildStackagePackages stackageSetConfig buildPlan
101 writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
99 writeOutFile buildPlanFile (opts ^. optOutStackagePackages)
102 $ pPrintOutPackages (view nodeDerivation <$> nodes)
100 $ pPrintOutPackages (view nodeDerivation <$> nodes)
103 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
101 writeOutFile buildPlanFile (opts ^. optOutStackageConfig)
104 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
102 $ pPrintOutConfig (bpSystemInfo buildPlan) nodes
105 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
103 writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
106− $ PP.overrideHaskellPackages overrideConfig stackConfPackages
104+ $ PP.overrideHaskellPackages overrideConfig (view nodeDerivation <$> stackConfPackages)
107
105
108 TargetStackageOverride ->
106 TargetStackageOverride ->
109− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
107+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
108+ PP.overrideStackage
109+ (stackConf ^. scResolver)
110− $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
110+ (opts ^. optNixpkgsRepository)
111+ (view nodeDerivation <$> stackConfPackages)
111
112
112 -- Generate Stackage packages from resolver
113 -- Generate Stackage packages from resolver
113 OriginResolver stackResolver -> do
114 OriginResolver stackResolver -> do
@@ -141,6 +142,23 @@ buildStackagePackages packageSetConfig buildPlan = do
141 traverse (uncurry (buildNode packageSetConfig stackagePackageConfig))
142 traverse (uncurry (buildNode packageSetConfig stackagePackageConfig))
142 $ Map.toAscList (bpPackages buildPlan)
143 $ Map.toAscList (bpPackages buildPlan)
143
144
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+
144writeOutFile :: Show source => source -> FilePath -> Doc -> IO ()
162writeOutFile :: Show source => source -> FilePath -> Doc -> IO ()
145writeOutFile source filePath contents =
163writeOutFile source filePath contents =
146 withFile filePath WriteMode $ \h -> do
164 withFile filePath WriteMode $ \h -> do
src/Runner/Cli.hs+16−4
@@ -12,9 +12,14 @@ import Options.Applicative as Opts
12import Paths_stackage2nix ( version )
12import Paths_stackage2nix ( version )
13import Stack.Config
13import Stack.Config
14import Stack.Types
14import Stack.Types
15−import System.Environment
16import System.FilePath
15import System.FilePath
17
16
17+data Tweaks = Tweaks
18+ { _tExtraDepsRevisionLatest :: Bool
19+ } deriving (Show)
20+
21+makeLenses ''Tweaks
22+
18-- | What will be generated
23-- | What will be generated
19data Target
24data Target
20 = TargetStackagePackages
25 = TargetStackagePackages
@@ -49,6 +54,7 @@ data Options = Options
49 , _optOutDerivation :: FilePath
54 , _optOutDerivation :: FilePath
50 , _optDoCheckPackages :: Bool
55 , _optDoCheckPackages :: Bool
51 , _optDoHaddockPackages :: Bool
56 , _optDoHaddockPackages :: Bool
57+ , _optTweaks :: Tweaks
52 , _optHackageDb :: Maybe HackageDb
58 , _optHackageDb :: Maybe HackageDb
53 , _optNixpkgsRepository :: FilePath
59 , _optNixpkgsRepository :: FilePath
54 , _optCompilerId :: CompilerId
60 , _optCompilerId :: CompilerId
@@ -58,9 +64,6 @@ data Options = Options
58
64
59makeLenses ''Options
65makeLenses ''Options
60
66
61−envStackYaml :: IO (Maybe StackYaml)
62−envStackYaml = fmap mkStackYaml <$> lookupEnv "STACK_YAML"
63−
64mkStackYaml :: FilePath -> StackYaml
67mkStackYaml :: FilePath -> StackYaml
65mkStackYaml p = case splitFileName p of
68mkStackYaml p = case splitFileName p of
66 (dir, "") -> StackYaml dir "stack.yaml"
69 (dir, "") -> StackYaml dir "stack.yaml"
@@ -77,6 +80,7 @@ options = Options
77 <*> outDerivation
80 <*> outDerivation
78 <*> doCheckPackages
81 <*> doCheckPackages
79 <*> doHaddockPackages
82 <*> doHaddockPackages
83+ <*> tweaks
80 <*> optional hackageDb
84 <*> optional hackageDb
81 <*> nixpkgsRepository
85 <*> nixpkgsRepository
82 <*> compilerId
86 <*> compilerId
@@ -155,6 +159,14 @@ withStackageClosure = flag' ()
155 ( long "with-stackage-closure"
159 ( long "with-stackage-closure"
156 <> help "generate Stackage subset containing only build dependencies" )
160 <> help "generate Stackage subset containing only build dependencies" )
157
161
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+
158resolver :: Parser StackResolver
170resolver :: Parser StackResolver
159resolver = StackResolver <$> option text
171resolver = StackResolver <$> option text
160 ( long "resolver"
172 ( long "resolver"