@@ -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
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
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
52− reachable = Set.map mkPackageName
54− $ nodeDepends . mkNode <$> stackConfPackages
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
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
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)
91 TargetStackagePackages -> do
86 TargetStackagePackages -> do
92 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
87 (buildPlanFile, buildPlan, packageSetConfig) <- loadStackageBuildPlan stackResolver opts sopts
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)
108 TargetStackageOverride ->
106 TargetStackageOverride ->
109− writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation)
107+ writeOutFile (stackYaml ^. syFilePath) (opts ^. optOutDerivation) $
109+ (stackConf ^. scResolver)
110− $ PP.overrideStackage (stackConf ^. scResolver) (opts ^. optNixpkgsRepository) stackConfPackages
110+ (opts ^. optNixpkgsRepository)
111+ (view nodeDerivation <$> stackConfPackages)
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)
145+reachableDeps :: Traversable t => t Node -> Set.Set PackageName
146+reachableDeps = Set.map mkPackageName
147+ . F.foldr1 Set.union
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 =
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 }
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