|
1 |
| -{-# LANGUAGE LambdaCase, OverloadedStrings, NamedFieldPuns, RecordWildCards #-} |
| 1 | +{-# LANGUAGE LambdaCase, OverloadedStrings, NamedFieldPuns, RecordWildCards, TupleSections #-} |
2 | 2 |
|
3 | 3 | module Plan2Nix
|
4 | 4 | ( doPlan2Nix
|
@@ -33,6 +33,8 @@ import Data.Text.Prettyprint.Doc.Render.Text (hPutDoc)
|
33 | 33 | import Distribution.Types.PackageId (PackageIdentifier(..))
|
34 | 34 | import Distribution.Nixpkgs.Fetch (DerivationSource(..), Source(..), Hash(..), fetch)
|
35 | 35 | import Distribution.Simple.Utils (shortRelativePath)
|
| 36 | +import Distribution.Types.Version (Version) |
| 37 | +import Distribution.Parsec (simpleParsec) |
36 | 38 |
|
37 | 39 | import Control.Monad.Trans.Maybe
|
38 | 40 | import Control.Monad.IO.Class (liftIO)
|
@@ -241,11 +243,15 @@ value2plan plan = Plan { packages, components, extras, compilerVersion, compiler
|
241 | 243 | else Just $ pkg ^. key "pkg-version" . _String
|
242 | 244 |
|
243 | 245 | filterInstallPlan :: (Value -> Maybe b) -> HashMap Text b
|
244 |
| - filterInstallPlan f = |
245 |
| - Map.fromList |
246 |
| - $ mapMaybe (\pkg -> (,) (pkg ^. key "pkg-name" . _String) <$> f pkg) |
| 246 | + filterInstallPlan f = fmap snd . |
| 247 | + -- If the same package occurs more than once, choose the latest |
| 248 | + Map.fromListWith (\a b -> if parseVersion (fst a) > parseVersion (fst b) then a else b) |
| 249 | + $ mapMaybe (\pkg -> (,) (pkg ^. key "pkg-name" . _String) . (pkg ^. key "pkg-version" . _String,) <$> f pkg) |
247 | 250 | $ Vector.toList (plan ^. key "install-plan" . _Array)
|
248 | 251 |
|
| 252 | + parseVersion :: Text -> Version |
| 253 | + parseVersion s = fromMaybe (error $ "Unable to parse version " <> show s) . simpleParsec $ Text.unpack s |
| 254 | + |
249 | 255 | -- Set of components that are included in the plan.
|
250 | 256 | components :: HashSet Text
|
251 | 257 | components =
|
|
0 commit comments