git.iko.soy/typeable/cabal2nix
on master help sign in
Add new "--hackage-db=FILEPATH" command line option so that cabal2nix can use Hackage mirrors.

This patch fixes <https://github.com/NixOS/cabal2nix/issues/68>.

commit0540ffb1bffc7680cce7abba4bf58f74296d239f authorPeter Simons <simons@cryp.to> dateWed 16 Jul 2014, 12:42 (12 years ago) parentea1f7b1
3 files changed+12−8
cabal2nix.cabal+2−1 src/Cabal2Nix/Hackage.hs+6−6 src/cabal2nix.hs+4−1
cabal2nix.cabal+2−1
@@ -10,7 +10,7 @@ Category: Distribution
1010Synopsis: Convert Cabal files into Nix build instructions
1111Cabal-Version: >= 1.8
1212Build-Type: Custom
13−Tested-With: GHC >= 6.10.4 && <= 7.8.2
13+Tested-With: GHC >= 6.10.4 && <= 7.8.3
1414Data-files: README.md
1515Description:
1616 The @cabal2nix@ utility converts Cabal files into Nix build instructions. The
@@ -18,6 +18,7 @@ Description:
1818 .
1919 > Usage: cabal2nix [options] url-to-cabal-file
2020 > -h --help show this help text
21+ > --hackage-db=FILEPATH path to the local hackage db in tar format
2122 > --sha256=HASH sha256 hash of source tarball
2223 > -m MAINTAINER --maintainer=MAINTAINER maintainer of this package (may be specified multiple times)
2324 > -p PLATFORM --platform=PLATFORM supported build platforms (may be specified multiple times)
src/Cabal2Nix/Hackage.hs+6−6
@@ -57,21 +57,21 @@ hashCachePath (PackageIdentifier (PackageName name) version') = do
5757 where
5858 version = showVersion version'
5959
60−readCabalFile :: FilePath -> IO String
61−readCabalFile path
60+readCabalFile :: Maybe FilePath -> FilePath -> IO String
61+readCabalFile hackageDbPath path
6262 | "cabal://" `isPrefixOf` path = do let pid p = fromJust $ simpleParse p
6363 packageName = drop 8 path
6464 case versionBranch $ pkgVersion $ pid packageName of
6565 [] -> do
66− packageDescription <- DB.lookup packageName `fmap` DB.readHackage
66+ packageDescription <- DB.lookup packageName `fmap` maybe DB.readHackage DB.readHackage' hackageDbPath
6767 case packageDescription of
6868 Just d -> do
6969 let version = showVersion $ last $ DB.keys d
70− readCabalFile $ hackagePath (pid $ packageName ++ "-" ++ version) Cabal
70+ readCabalFile Nothing $ hackagePath (pid $ packageName ++ "-" ++ version) Cabal
7171 Nothing -> error "No such package"
72− _ -> readCabalFile $ hackagePath (pid packageName) Cabal
72+ _ -> readCabalFile Nothing $ hackagePath (pid packageName) Cabal
7373 | "http://" `isPrefixOf` path = fetchUrl path
74− | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
74+ | "file://" `isPrefixOf` path = readCabalFile Nothing (drop 7 path)
7575 | otherwise = readFile path
7676
7777fetchUrl :: String -> IO String
src/cabal2nix.hs+4−1
@@ -25,6 +25,7 @@ data Configuration = Configuration
2525 , optDoCheck :: Bool
2626 , optJailbreak :: Bool
2727 , optHyperlinkSource :: Bool
28+ , optHackageDb :: Maybe FilePath
2829 }
2930 deriving (Show)
3031
@@ -39,11 +40,13 @@ defaultConfiguration = Configuration
3940 , optDoCheck = True
4041 , optJailbreak = False
4142 , optHyperlinkSource = True
43+ , optHackageDb = Nothing
4244 }
4345
4446options :: [OptDescr (Configuration -> Configuration)]
4547options =
4648 [ Option "h" ["help"] (NoArg (\o -> o { optPrintHelp = True })) "show this help text"
49+ , Option "" ["hackage-db"] (ReqArg (\x o -> o { optHackageDb = Just x }) "FILEPATH") "path to the local hackage db in tar format"
4750 , Option "" ["sha256"] (ReqArg (\x o -> o { optSha256 = Just x }) "HASH") "sha256 hash of source tarball"
4851 , Option "m" ["maintainer"] (ReqArg (\x o -> o { optMaintainer = x : optMaintainer o }) "MAINTAINER") "maintainer of this package (may be specified multiple times)"
4952 , Option "p" ["platform"] (ReqArg (\x o -> o { optPlatform = x : optPlatform o }) "PLATFORM") "supported build platforms (may be specified multiple times)"
@@ -79,7 +82,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
7982 when (optPrintHelp cfg) (putStr usage >> exitSuccess)
8083 when (length args /= 1) (cmdlineError "*** exactly one url-to-cabal-file must be specified\n")
8184
82− cabal' <- fmap parsePackageDescription (readCabalFile (head args))
85+ cabal' <- fmap parsePackageDescription (readCabalFile (optHackageDb cfg) (head args))
8386 cabal <- case cabal' of
8487 ParseOk _ a -> return a
8588 ParseFailed err -> do