git.iko.soy/typeable/cabal2nix
on 1663fb8 help sign in
29 lines 1.3 kB history raw
1module Cabal2Nix.Hackage ( readHashedHackage, module Distribution.Hackage.DB ) where
3import Data.ByteString.Lazy ( ByteString )
4import Data.Digest.Pure.SHA ( sha256, showDigest )
5import Distribution.Hackage.DB
6import qualified Distribution.Hackage.DB.Parsed as Unparsed ( parsePackage )
7import qualified Distribution.Hackage.DB.Unparsed as Unparsed
9-- | A variant of 'readHackage' that adds the SHA256 digest of the
10-- original Cabal file to the parsed 'GenericPackageDescription'. That
11-- hash is required to build packages with an "edited" cabal file,
12-- because Nix needs to download the edited file and patch it into the
13-- original tarball.
15readHashedHackage :: IO Hackage
16readHashedHackage = fmap parseUnparsedHackage Unparsed.readHackage
17 where
18 parseUnparsedHackage :: Unparsed.Hackage -> Hackage
19 parseUnparsedHackage = mapWithKey (mapWithKey . parsePackage)
21 parsePackage :: String -> Version -> ByteString -> GenericPackageDescription
22 parsePackage name version buf =
23 let pkg = Unparsed.parsePackage name version buf
24 hash = showDigest (sha256 buf)
25 in
26 pkg { packageDescription = (packageDescription pkg) {
27 customFieldsPD = ("x-cabal-file-hash", hash) : customFieldsPD (packageDescription pkg)
28 }
29 }