cabal2nix 1.38 → 1.39
raw patch · 2 files changed
+21/−7 lines, 2 files
Files
- cabal2nix.cabal +6/−5
- src/Cabal2Nix/Hackage.hs +15/−2
cabal2nix.cabal view
@@ -1,5 +1,5 @@ Name: cabal2nix-Version: 1.38+Version: 1.39 Copyright: Peter Simons, Andres Loeh License: BSD3 License-File: LICENSE@@ -10,7 +10,7 @@ Synopsis: Convert Cabal files into Nix build instructions Cabal-Version: >= 1.8 Build-Type: Custom-Tested-With: GHC == 6.12.3, GHC == 7.0.4, GHC == 7.4.1+Tested-With: GHC == 6.12.3, GHC == 7.0.4, GHC == 7.4.1, GHC == 7.4.2 Data-files: README.md Description: The @cabal2nix@ utility converts Cabal files into Nix build instructions. The@@ -25,14 +25,15 @@ > Recognized URI schemes: > > cabal://pkgname-pkgversion download the specified package from Hackage+ > cabal://pkgname download latest version of the specified package from Hackage > http://host/path fetch the Cabal file via HTTP > file:///local/path load the Cabal file from the local disk > /local/path abbreviated version of file URI . The only required argument is the path to the cabal file. For example: .- > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.38/cabal2nix.cabal- > cabal2nix cabal://cabal2nix-1.38+ > cabal2nix http://hackage.haskell.org/packages/archive/cabal2nix/1.39/cabal2nix.cabal+ > cabal2nix cabal://cabal2nix-1.39 . If the @--sha256@ option has not been specified, cabal2nix calls @nix-prefetch-url@ to determine the hash automatically. This causes@@ -46,7 +47,7 @@ main-is: Cabal2Nix.hs hs-source-dirs: src Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,- filepath, directory, process, HTTP+ filepath, directory, process, HTTP, hackage-db Extensions: PatternGuards, RecordWildCards, CPP Ghc-Options: -Wall other-modules: Cabal2Nix.CorePackages
src/Cabal2Nix/Hackage.hs view
@@ -2,7 +2,8 @@ import Control.Monad ( unless ) import Data.List ( isPrefixOf )-import Data.Version ( showVersion )+import Data.Maybe ( fromJust )+import Data.Version ( showVersion, versionBranch ) import Distribution.Package ( PackageIdentifier(..), PackageName(..) ) import Distribution.Text import Network.HTTP ( getRequest, rspBody )@@ -11,6 +12,8 @@ import System.FilePath ( dropFileName, (</>), (<.>) ) import System.Process ( readProcess ) +import qualified Distribution.Hackage.DB as DB+ data Ext = TarGz | Cabal deriving Eq showExt :: Ext -> String@@ -48,7 +51,17 @@ readCabalFile :: FilePath -> IO String readCabalFile path- | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)+ | "cabal://" `isPrefixOf` path = do let pid p = fromJust $ simpleParse p+ packageName = drop 8 path+ case versionBranch $ pkgVersion $ pid packageName of+ [] -> do+ packageDescription <- DB.lookup packageName `fmap` DB.readHackage+ case packageDescription of+ Just d -> do+ let version = showVersion $ last $ DB.keys d+ readCabalFile $ hackagePath (pid $ packageName ++ "-" ++ version) Cabal+ Nothing -> error "No such package"+ _ -> readCabalFile $ hackagePath (pid packageName) Cabal | "http://" `isPrefixOf` path = fetchUrl path | "file://" `isPrefixOf` path = readCabalFile (drop 7 path) | otherwise = readFile path