git.iko.soy/typeable/stackage2nix
on 9bf94e1 help sign in
4 files changed+20−28
since splitsnapshots
unifiedsplit
README.md+1−1 nix/lib.nix+1−1 src/AllCabalHashes.hs+18−25 stackage2nix.cabal−1
README.md+1−1
@@ -1,4 +1,4 @@
1−# stackage2nix (DEPRECATED)
1+# stackage2nix
22
33[![Build Status](https://travis-ci.org/typeable/stackage2nix.svg?branch=master)](https://travis-ci.org/typeable/stackage2nix)
44
nix/lib.nix+1−1
@@ -23,7 +23,7 @@ rec {
2323 buildInputs = [ git ];
2424 installPhase = ''
2525 mkdir -p $out
26− git clone --bare --branch hackage https://github.com/commercialhaskell/all-cabal-hashes.git $out
26+ git clone --branch hackage https://github.com/commercialhaskell/all-cabal-hashes.git $out
2727 '';
2828 SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt";
2929 };
src/AllCabalHashes.hs+18−25
@@ -3,9 +3,8 @@ module AllCabalHashes where
33import Control.Lens hiding ((<.>))
44import Data.Aeson as A
55import Data.ByteString as BS
6−import Data.ByteString.Char8 as B8
6+import Data.ByteString.Lazy as BSL
77import Data.Map as M
8−import Data.Tagged (Tagged(..))
98import Data.Text as T
109import Distribution.Nixpkgs.Hashes as NH
1110import Distribution.Package
@@ -41,34 +40,28 @@ readPackageByHash repoDir sha1Hash = do
4140 let repoOpts = defaultRepositoryOptions { repoPath = repoDir }
4241 repo <- openLgRepository repoOpts
4342 buf <- runLgRepository repo $ do
44− oid <- parseOid sha1Hash
45− catBlob (Tagged oid)
46− parseCabal ("Git SHA1 " ++ show sha1Hash) buf
43+ BlobObj (Blob _ contents) <- lookupObject =<< parseOid sha1Hash
44+ case contents of
45+ BlobString bs -> return bs
46+ BlobStringLazy bsl -> return $ BSL.toStrict bsl
47+ _ -> fail $ "Git SHA1 " ++ show sha1Hash ++ ": expected single Blob"
48+ cabal <- let (_, res) = runParseResult (parseGenericPackageDescription buf)
49+ in case res of Right a -> return a
50+ Left (_, err) -> fail ("Git SHA1 " ++ show sha1Hash ++ ": " ++ show err)
51+ let
52+ hash = printSHA256 (digest (digestByName "sha256") buf)
53+ pkg = setCabalFileHash hash cabal
54+ return (pkg, hash)
4755
4856readPackageByName :: FilePath -> PackageIdentifier -> IO (GenericPackageDescription, SHA256Hash)
4957readPackageByName repoDir (PackageIdentifier name version) = do
50− let cabalFile = unPackageName name </> display version </> unPackageName name <.> "cabal"
51− let repoOpts = defaultRepositoryOptions { repoPath = repoDir }
52− repo <- openLgRepository repoOpts
53− buf <- runLgRepository repo $ do
54− headCommit <- resolveReference "HEAD" >>= \case
55− Nothing -> fail "Failed to parse HEAD ref"
56− Just oid -> lookupCommit $ Tagged oid
57− blobOid <- commitTreeEntry headCommit (B8.pack cabalFile) >>= \case
58− Nothing -> fail (cabalFile ++ ": no such file at HEAD")
59− Just (BlobEntry oid PlainBlob) -> pure oid
60− Just (BlobEntry _ _) -> fail (cabalFile ++ " is not a plain blob")
61− _ -> fail (cabalFile ++ " points to a non-blob!")
62− catBlob blobOid
63− parseCabal cabalFile buf
64−
65−parseCabal :: String -> BS.ByteString -> IO (GenericPackageDescription, SHA256Hash)
66−parseCabal what blob = do
67− cabal <- let (_, res) = runParseResult (parseGenericPackageDescription blob)
58+ let cabalFile = repoDir </> unPackageName name </> display version </> unPackageName name <.> "cabal"
59+ buf <- BS.readFile cabalFile
60+ cabal <- let (_, res) = runParseResult (parseGenericPackageDescription buf)
6861 in case res of Right a -> return a
69− Left (_, err) -> fail (what ++ ": " ++ show err)
62+ Left (_, err) -> fail (cabalFile ++ ": " ++ show err)
7063 let
71− hash = NH.printSHA256 (SSL.digest (SSL.digestByName "sha256") blob)
64+ hash = NH.printSHA256 (SSL.digest (SSL.digestByName "sha256") buf)
7265 pkg = setCabalFileHash hash cabal
7366 return (pkg, hash)
7467
stackage2nix.cabal−1
@@ -51,7 +51,6 @@ library
5151 , optparse-applicative
5252 , pretty
5353 , stackage-curator >= 0.15
54− , tagged
5554 , text
5655 , unordered-containers
5756 , yaml