git.iko.soy/typeable/cabal2nix
on master help sign in
Switch digest calculation code to hopenssl.
6a0189aPeter Simons
cabal2nix.cabal+2−2
@@ -94,12 +94,12 @@ library
94 , distribution-nixpkgs
94 , distribution-nixpkgs
95 , filepath
95 , filepath
96 , hackage-db
96 , hackage-db
97+ , hopenssl >= 2
97 , language-nix
98 , language-nix
98 , lens
99 , lens
99 , optparse-applicative
100 , optparse-applicative
100 , pretty >= 1.1.2
101 , pretty >= 1.1.2
101 , process
102 , process
102− , SHA
103 , split
103 , split
104 , text
104 , text
105 , transformers
105 , transformers
@@ -141,12 +141,12 @@ executable cabal2nix
141 , distribution-nixpkgs
141 , distribution-nixpkgs
142 , filepath
142 , filepath
143 , hackage-db
143 , hackage-db
144+ , hopenssl >= 2
144 , language-nix
145 , language-nix
145 , lens
146 , lens
146 , optparse-applicative
147 , optparse-applicative
147 , pretty >= 1.1.2
148 , pretty >= 1.1.2
148 , process
149 , process
149− , SHA
150 , split
150 , split
151 , text
151 , text
152 , transformers
152 , transformers
hackage2nix/HackageGit.hs+2−6
@@ -8,8 +8,7 @@ import Control.Lens hiding ( (<.>) )
8import Data.Aeson
8import Data.Aeson
9import Data.ByteString.Char8 ( ByteString )
9import Data.ByteString.Char8 ( ByteString )
10import qualified Data.ByteString.Char8 as BS
10import qualified Data.ByteString.Char8 as BS
11−import Data.ByteString.Lazy.Char8 ( fromStrict )
11+import OpenSSL.Digest ( digest, digestByName, toHex )
12−import Data.Digest.Pure.SHA ( sha256, showDigest )
13import Data.Map as Map
12import Data.Map as Map
14import Data.Set as Set
13import Data.Set as Set
15import Data.String
14import Data.String
@@ -50,10 +49,7 @@ readPackage dirPrefix (PackageIdentifier name version) = do
50 cabal <- case parsePackageDescription (decodeUTF8 buf) of
49 cabal <- case parsePackageDescription (decodeUTF8 buf) of
51 ParseOk _ a -> return a
50 ParseOk _ a -> return a
52 ParseFailed err -> fail (cabalFile ++ ": " ++ show err)
51 ParseFailed err -> fail (cabalFile ++ ": " ++ show err)
53− return (cabal, mkSHA256 buf)
52+ return (cabal, BS.unpack (toHex (digest (digestByName "sha256") buf)))
54−
55−mkSHA256 :: ByteString -> SHA256Hash
56−mkSHA256 = showDigest . sha256 . fromStrict
57
53
58declareLenses [d|
54declareLenses [d|
59 data Meta = Meta { hashes :: Map String String
55 data Meta = Meta { hashes :: Map String String
package.yaml+2−2
@@ -1,5 +1,5 @@
1name: cabal2nix
1name: cabal2nix
2−version: 2.2.1
2+version: 2.3
3synopsis: Convert Cabal files into Nix build instructions.
3synopsis: Convert Cabal files into Nix build instructions.
4author:
4author:
5 - Peter Simons
5 - Peter Simons
@@ -85,12 +85,12 @@ dependencies:
85 - distribution-nixpkgs
85 - distribution-nixpkgs
86 - filepath
86 - filepath
87 - hackage-db
87 - hackage-db
88+ - hopenssl >= 2
88 - language-nix
89 - language-nix
89 - lens
90 - lens
90 - optparse-applicative
91 - optparse-applicative
91 - pretty >= 1.1.2
92 - pretty >= 1.1.2
92 - process
93 - process
93− - SHA
94 - split
94 - split
95 - text
95 - text
96 - transformers
96 - transformers
src/Distribution/Nixpkgs/Haskell/Hackage.hs+3−2
@@ -1,10 +1,11 @@
1module Distribution.Nixpkgs.Haskell.Hackage ( readHashedHackage, readHashedHackage', module Distribution.Hackage.DB ) where
1module Distribution.Nixpkgs.Haskell.Hackage ( readHashedHackage, readHashedHackage', module Distribution.Hackage.DB ) where
2
2
3import Data.ByteString.Lazy ( ByteString )
3import Data.ByteString.Lazy ( ByteString )
4−import Data.Digest.Pure.SHA ( sha256, showDigest )
4+import Data.ByteString.Char8 ( unpack )
5import Distribution.Hackage.DB
5import Distribution.Hackage.DB
6import qualified Distribution.Hackage.DB.Parsed as Unparsed ( parsePackage )
6import qualified Distribution.Hackage.DB.Parsed as Unparsed ( parsePackage )
7import qualified Distribution.Hackage.DB.Unparsed as Unparsed
7import qualified Distribution.Hackage.DB.Unparsed as Unparsed
8+import OpenSSL.Digest ( digest, digestByName, toHex )
8
9
9-- | A variant of 'readHackage' that adds the SHA256 digest of the
10-- | A variant of 'readHackage' that adds the SHA256 digest of the
10-- original Cabal file to the parsed 'GenericPackageDescription'. That
11-- original Cabal file to the parsed 'GenericPackageDescription'. That
@@ -24,7 +25,7 @@ readHashedHackage' = fmap parseUnparsedHackage . Unparsed.readHackage'
24 parsePackage :: String -> Version -> ByteString -> GenericPackageDescription
25 parsePackage :: String -> Version -> ByteString -> GenericPackageDescription
25 parsePackage name version buf =
26 parsePackage name version buf =
26 let pkg = Unparsed.parsePackage name version buf
27 let pkg = Unparsed.parsePackage name version buf
27− hash = showDigest (sha256 buf)
28+ hash = unpack (toHex (digest (digestByName "sha256") buf))
28 in
29 in
29 pkg { packageDescription = (packageDescription pkg) {
30 pkg { packageDescription = (packageDescription pkg) {
30 customFieldsPD = ("X-Cabal-File-Hash", hash) : customFieldsPD (packageDescription pkg)
31 customFieldsPD = ("X-Cabal-File-Hash", hash) : customFieldsPD (packageDescription pkg)
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+5−4
@@ -6,8 +6,8 @@ import qualified Control.Exception as Exception
6import Control.Monad
6import Control.Monad
7import Control.Monad.IO.Class
7import Control.Monad.IO.Class
8import Control.Monad.Trans.Maybe
8import Control.Monad.Trans.Maybe
9−import qualified Data.ByteString.Lazy.Char8 as BS8
9+import qualified Data.ByteString.Lazy.Char8 as LBS8
10−import Data.Digest.Pure.SHA ( sha256, showDigest )
10+import qualified Data.ByteString.Char8 as SBS8
11import Data.List ( isSuffixOf, isPrefixOf )
11import Data.List ( isSuffixOf, isPrefixOf )
12import Data.Maybe
12import Data.Maybe
13import Data.Version
13import Data.Version
@@ -18,6 +18,7 @@ import qualified Distribution.Package as Cabal
18import Distribution.PackageDescription
18import Distribution.PackageDescription
19import qualified Distribution.PackageDescription as Cabal
19import qualified Distribution.PackageDescription as Cabal
20import Distribution.Text ( simpleParse )
20import Distribution.Text ( simpleParse )
21+import OpenSSL.Digest ( digest, digestByName, toHex )
21import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getHomeDirectory, getDirectoryContents )
22import System.Directory ( doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getHomeDirectory, getDirectoryContents )
22import System.Exit ( exitFailure )
23import System.Exit ( exitFailure )
23import System.FilePath ( (</>), (<.>) )
24import System.FilePath ( (</>), (<.>) )
@@ -145,8 +146,8 @@ cabalFromFile failHard file =
145 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
146 -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
146 -- the reading of the file, so we will always catch the expression here.
147 -- the reading of the file, so we will always catch the expression here.
147 MaybeT $ handleIO (\err -> Nothing <$ hPutStrLn stderr ("*** parsing cabal file: " ++ show err)) $ do
148 MaybeT $ handleIO (\err -> Nothing <$ hPutStrLn stderr ("*** parsing cabal file: " ++ show err)) $ do
148− buf <- BS8.readFile file
149+ buf <- LBS8.readFile file
149− let hash = showDigest (sha256 buf)
150+ let hash = SBS8.unpack (toHex (digest (digestByName "sha256") buf))
150 case parsePackage' buf of
151 case parsePackage' buf of
151 Left msg -> if failHard
152 Left msg -> if failHard
152 then fail ("*** cannot parse " ++ show file ++ ": " ++ msg)
153 then fail ("*** cannot parse " ++ show file ++ ": " ++ msg)