module Distribution.Nixpkgs.Haskell.Hackage ( readHashedHackage, readHashedHackage', module Distribution.Hackage.DB ) where
import Data.ByteString.Lazy ( ByteString )
import Distribution.Hackage.DB
import qualified Distribution.Hackage.DB.Parsed as Unparsed ( parsePackage )
import qualified Distribution.Hackage.DB.Unparsed as Unparsed
import Distribution.Nixpkgs.Hashes
import OpenSSL.Digest ( digest, digestByName )
readHashedHackage :: IO Hackage
readHashedHackage = hackagePath >>= readHashedHackage'
readHashedHackage' :: FilePath -> IO Hackage
readHashedHackage' = fmap parseUnparsedHackage . Unparsed.readHackage'
where
parseUnparsedHackage :: Unparsed.Hackage -> Hackage
parseUnparsedHackage = mapWithKey (mapWithKey . parsePackage)
parsePackage :: String -> Version -> ByteString -> GenericPackageDescription
parsePackage name version buf =
let pkg = Unparsed.parsePackage name version buf
hash = printSHA256 (digest (digestByName "sha256") buf)
in
pkg { packageDescription = (packageDescription pkg) {
customFieldsPD = ("X-Cabal-File-Hash", hash) : customFieldsPD (packageDescription pkg)
}
}