Skip to content

Commit

Permalink
hackage2nix: Always print extraVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarice committed Jul 2, 2020
1 parent 30d5c33 commit 09cea16
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions hackage2nix/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ main = do
globalPackageMaintainers = Map.unionsWith Set.union [ Map.singleton p (Set.singleton m) | (m,ps) <- Map.toList (packageMaintainers config), p <- Set.toList ps ]

pkgs <- runParIO $ flip parMapM (Map.toAscList db) $ \(name, vs) -> do
defs <- forM (Set.toAscList vs) $ \v -> liftIO $ do
defs <- fmap concat . forM (Set.toAscList vs) $ \v -> liftIO $ do
let pkgId :: PackageIdentifier
pkgId = PackageIdentifier name v

(descr, cabalSHA256) <- readPackage hackageRepository pkgId
meta <- readPackageMeta hackageRepository pkgId

let isInDefaultPackageSet, isHydraEnabled, isBroken :: Bool
let isInDefaultPackageSet, isInExtraPackageSet, isHydraEnabled, isBroken :: Bool
isInDefaultPackageSet = (== Just v) (Map.lookup name generatedDefaultPackageSet)
isInExtraPackageSet = maybe False (Set.member v) (Map.lookup name extraPackageSet)
isHydraEnabled = isInDefaultPackageSet && not (isBroken || name `Set.member` dontDistributePackages config)
isBroken = any (withinRange v) [ vr | Dependency pn vr _ <- brokenPackages config, pn == name ]

Expand All @@ -151,8 +152,11 @@ main = do
flagAssignment :: FlagAssignment -- We don't use the flags from Stackage Nightly here, because
flagAssignment = configureCabalFlags pkgId -- they are chosen specifically for GHC 7.10.2.

attr :: String
attr = if isInDefaultPackageSet then unPackageName name else mangle pkgId
attrDefault :: String
attrDefault = unPackageName name

attrExtra :: String
attrExtra = mangle pkgId

drv :: Derivation
drv = fromGenericPackageDescription haskellResolver nixpkgsResolver targetPlatform (compilerInfo config) flagAssignment [] descr
Expand All @@ -167,8 +171,17 @@ main = do

overrides :: Doc
overrides = fcat $ punctuate space [ pPrint b <> semi | b <- Set.toList (view (dependencies . each) drv `Set.union` view extraFunctionArgs drv), not (isFromHackage b) ]
return $ render $ nest 2 $
hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides <> semi)

renderFromAttr :: String -> String
renderFromAttr attr = render $ nest 2 $
hang (doubleQuotes (text attr) <+> equals <+> text "callPackage") 2 (parens (pPrint drv)) <+> (braces overrides <> semi)

resDefault :: [ String ]
resDefault = if isInDefaultPackageSet then [ renderFromAttr attrDefault ] else []

resExtra :: [ String ]
resExtra = if isInExtraPackageSet || (not isInDefaultPackageSet) then [ renderFromAttr attrExtra ] else []
return $ resDefault ++ resExtra

return (intercalate "\n\n" defs)

Expand Down

0 comments on commit 09cea16

Please sign in to comment.