@@ -79,6 +79,13 @@ writeDoc file doc =
79
79
hPutDoc handle doc
80
80
hClose handle
81
81
82
+ -- PackageKey is used when selecting which version is the most recent
83
+ -- when to deduplicate the plan.
84
+ -- By including PackageType as well as version we can select the
85
+ -- NonPreExisting version of the package if the versions match.
86
+ data PackageType = PreExisting | NotPreExisting deriving (Eq , Ord )
87
+ data PackageKey = PackageKey Version PackageType deriving (Eq , Ord )
88
+
82
89
plan2nix :: Args -> Plan -> IO NExpr
83
90
plan2nix args Plan { packages, extras, components, compilerVersion, compilerPackages } = do
84
91
-- TODO: this is an aweful hack and expects plan-to-nix to be
@@ -260,13 +267,19 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
260
267
filterInstallPlan :: (Value -> Maybe b ) -> HashMap Text b
261
268
filterInstallPlan f = fmap snd .
262
269
-- If the same package occurs more than once, choose the latest
263
- Map. fromListWith (\ a b -> if parseVersion ( fst a) > parseVersion ( fst b) then a else b)
264
- $ mapMaybe (\ pkg -> (,) (pkg ^. key " pkg-name" . _String) . (pkg ^. key " pkg-version " . _String ,) <$> f pkg)
270
+ Map. fromListWith (\ a b -> if fst a > fst b then a else b)
271
+ $ mapMaybe (\ pkg -> (,) (pkg ^. key " pkg-name" . _String) . (getPackageKey pkg,) <$> f pkg)
265
272
$ Vector. toList (plan ^. key " install-plan" . _Array)
266
273
267
274
parseVersion :: Text -> Version
268
275
parseVersion s = fromMaybe (error $ " Unable to parse version " <> show s) . simpleParsec $ Text. unpack s
269
276
277
+ getPackageKey :: Value -> PackageKey
278
+ getPackageKey pkg = PackageKey (parseVersion (pkg ^. key " pkg-version" . _String)) (
279
+ if pkg ^. key " type" . _String == " pre-existing"
280
+ then PreExisting
281
+ else NotPreExisting )
282
+
270
283
-- Set of components that are included in the plan.
271
284
components :: HashSet Text
272
285
components =
0 commit comments