git.iko.soy/typeable/cabal2nix
on master help sign in
Get latest cabal file when version is not specified
4f7daefDmitry Malikov
cabal2nix.cabal+1−1
@@ -46,7 +46,7 @@ Executable cabal2nix
46 main-is: Cabal2Nix.hs
46 main-is: Cabal2Nix.hs
47 hs-source-dirs: src
47 hs-source-dirs: src
48 Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
48 Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
49− filepath, directory, process, HTTP
49+ filepath, directory, process, HTTP, hackage-db
50 Extensions: PatternGuards, RecordWildCards, CPP
50 Extensions: PatternGuards, RecordWildCards, CPP
51 Ghc-Options: -Wall
51 Ghc-Options: -Wall
52 other-modules: Cabal2Nix.CorePackages
52 other-modules: Cabal2Nix.CorePackages
src/Cabal2Nix/Hackage.hs+15−2
@@ -2,7 +2,8 @@ module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
2
2
3import Control.Monad ( unless )
3import Control.Monad ( unless )
4import Data.List ( isPrefixOf )
4import Data.List ( isPrefixOf )
5+import Data.Maybe ( fromJust )
5−import Data.Version ( showVersion )
6+import Data.Version ( showVersion, versionBranch )
6import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
7import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
7import Distribution.Text
8import Distribution.Text
8import Network.HTTP ( getRequest, rspBody )
9import Network.HTTP ( getRequest, rspBody )
@@ -11,6 +12,8 @@ import System.Directory ( doesFileExist, getHomeDirectory, createDirectoryIfMiss
11import System.FilePath ( dropFileName, (</>), (<.>) )
12import System.FilePath ( dropFileName, (</>), (<.>) )
12import System.Process ( readProcess )
13import System.Process ( readProcess )
13
14
15+import qualified Distribution.Hackage.DB as DB
16+
14data Ext = TarGz | Cabal deriving Eq
17data Ext = TarGz | Cabal deriving Eq
15
18
16showExt :: Ext -> String
19showExt :: Ext -> String
@@ -48,7 +51,17 @@ hashCachePath (PackageIdentifier (PackageName name) version') = do
48
51
49readCabalFile :: FilePath -> IO String
52readCabalFile :: FilePath -> IO String
50readCabalFile path
53readCabalFile path
51− | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)
54+ | "cabal://" `isPrefixOf` path = do let pid p = fromJust $ simpleParse p
55+ packageName = drop 8 path
56+ case versionBranch $ pkgVersion $ pid packageName of
57+ [] -> do
58+ packageDescription <- DB.lookup packageName `fmap` DB.readHackage
59+ case packageDescription of
60+ Just d -> do
61+ let version = showVersion $ last $ DB.keys d
62+ readCabalFile $ hackagePath (pid $ packageName ++ "-" ++ version) Cabal
63+ Nothing -> error "No such package"
64+ _ -> readCabalFile $ hackagePath (pid packageName) Cabal
52 | "http://" `isPrefixOf` path = fetchUrl path
65 | "http://" `isPrefixOf` path = fetchUrl path
53 | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
66 | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
54 | otherwise = readFile path
67 | otherwise = readFile path