Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hackage2nix: Always print extraVersions #464

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 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,18 @@ 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 = [ renderFromAttr attrDefault | isInDefaultPackageSet ]

resExtra :: [ String ]
resExtra = [ renderFromAttr attrExtra | isInExtraPackageSet || not isInDefaultPackageSet ]

return $ resDefault ++ resExtra

return (intercalate "\n\n" defs)

Expand Down