git.iko.soy/typeable/cabal2nix
on master help sign in
Moved readCabalFile function into the Hackage module.
commitca2b280fa4d0692e467c138efaf172ba4cd640b7 authorPeter Simons <simons@cryp.to> dateFri 19 Aug 2011, 14:38 (15 years ago) parent801e2ae
2 files changed+24−23
src/Cabal2Nix.hs+10−19 src/Cabal2Nix/Hackage.hs+14−4
src/Cabal2Nix.hs+10−19
@@ -1,28 +1,19 @@
11module Main ( main ) where
22
3−import System.IO ( hPutStrLn, hFlush, stdout, stderr )
4−import System.Environment -- ( getArgs )
5−import Control.Exception ( bracket )
6−import System.Exit ( exitFailure )
7−import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseResult(..) )
8−import Distribution.PackageDescription ( package, packageDescription )
9−import Distribution.Text
10−import Data.List ( isPrefixOf )
11−import Control.Monad ( when )
12−import Network.HTTP ( simpleHTTP, getRequest, getResponseBody )
13−import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
14−
3+import Cabal2Nix.Hackage ( hashPackage, readCabalFile )
154import Cabal2Nix.Package ( cabal2nix )
16−import Cabal2Nix.Hackage ( hackagePath, Ext(..), hashPackage )
175import Distribution.NixOS.Derivation.Cabal
186import Distribution.NixOS.Derivation.Meta
197
20−readCabalFile :: FilePath -> IO String
21−readCabalFile path
22− | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)
23− | "http://" `isPrefixOf` path = simpleHTTP (getRequest path) >>= getResponseBody
24− | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
25− | otherwise = readFile path
8+import Control.Exception ( bracket )
9+import Control.Monad ( when )
10+import Distribution.PackageDescription ( package, packageDescription )
11+import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseResult(..) )
12+import Distribution.Text ( disp )
13+import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
14+import System.Environment ( getArgs )
15+import System.Exit ( exitFailure )
16+import System.IO ( hPutStrLn, hFlush, stdout, stderr )
2617
2718data CliOption = PrintHelp | SHA256 String | Maintainer String | Platform String | NoHaddock
2819 deriving (Eq)
src/Cabal2Nix/Hackage.hs+14−4
@@ -1,11 +1,14 @@
1−module Cabal2Nix.Hackage ( hackagePath, Ext(..), hashPackage ) where
1+module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
22
3+import Control.Monad ( when )
4+import Data.List ( isPrefixOf )
5+import Data.Version ( showVersion )
36import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
4−import System.Process ( readProcess )
7+import Distribution.Text
8+import Network.HTTP ( simpleHTTP, getRequest, getResponseBody )
59import System.Directory ( doesFileExist, getHomeDirectory, createDirectoryIfMissing )
610import System.FilePath ( dropFileName, (</>), (<.>) )
7−import Data.Version ( showVersion )
8−import Control.Monad ( when )
11+import System.Process ( readProcess )
912
1013data Ext = TarGz | Cabal deriving Eq
1114
@@ -41,3 +44,10 @@ hashCachePath (PackageIdentifier (PackageName name) version') = do
4144 return $ home ++ "/.cache/cabal2nix" </> name ++ "-" ++ version <.> "sha256"
4245 where
4346 version = showVersion version'
47+
48+readCabalFile :: FilePath -> IO String
49+readCabalFile path
50+ | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)
51+ | "http://" `isPrefixOf` path = simpleHTTP (getRequest path) >>= getResponseBody
52+ | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
53+ | otherwise = readFile path