git.iko.soy/typeable/cabal2nix
on master help sign in
Support local source archives
commit37f1a2ca1d1249b884527bea40eb8e0eaf58c60f authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateMon 18 Aug 2014, 00:08 (12 years ago) parent888a2e7
3 files changed+18−10
README.md+1−2 src/Cabal2Nix/Package.hs+11−7 src/Distribution/NixOS/Fetch.hs+6−1
README.md+1−2
@@ -101,10 +101,9 @@ contains the derivation as the source repository.
101101`cabal2nix` currently supports the following respository types:
102102
103103* directory
104−* source archive (zip, tar.gz, ...) downloaded from http or https URL.
104+* source archive (zip, tar.gz, ...) from http or https URL or local file.
105105* git, mercurial, svn or bazaar repository
106106
107−
108107### Hackage4nix
109108
110109The `hackage4nix` utility re-generates *all* expressions found in the
src/Cabal2Nix/Package.hs+11−7
@@ -124,14 +124,18 @@ cabalFromDirectory dir = do
124124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
125125
126126cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
127−cabalFromFile failHard file = do
128− content <- MaybeT $ either (const Nothing) Just <$> Compat.tryIO (readFile file)
129− case Cabal.parsePackageDescription content of
130− Cabal.ParseFailed e -> do
131− guard failHard
132− liftIO $ do
127+cabalFromFile failHard file =
128+ -- readFile throws an error if it's used on binary files which contain sequences
129+ -- that do not represent valid characters. To catch that exception, we need to
130+ -- wrap the whole block in `catchIO`, because of lazy IO. The `case` will force
131+ -- the reading of the file, so we will always catch the expression here.
132+ MaybeT $ flip Compat.catchIO (const $ return Nothing) $ do
133+ content <- readFile file
134+ case Cabal.parsePackageDescription content of
135+ Cabal.ParseFailed e | failHard -> do
133136 let (line, err) = ParseUtils.locatedErrorMsg e
134137 msg = maybe "" ((++ ": ") . show) line ++ err
135138 putStrLn $ "*** error parsing cabal file: " ++ msg
136139 exitFailure
137− Cabal.ParseOk _ a -> return a
140+ Cabal.ParseFailed _ -> return Nothing
141+ Cabal.ParseOk _ a -> return (Just a)
src/Distribution/NixOS/Fetch.hs+6−1
@@ -62,7 +62,12 @@ fetch f = runMaybeT . fetchers where
6262 existsFile <- liftIO $ doesFileExist path
6363 existsDir <- liftIO $ doesDirectoryExist path
6464 guard $ existsDir || existsFile
65− process (DerivationSource "" path "" "", path)
65+ process (DerivationSource "" path "" "", path) <|> localArchive path
66+
67+ localArchive :: FilePath -> MaybeT IO (DerivationSource, a)
68+ localArchive path = do
69+ unpacked <- snd <$> fetchWith (False, "zip") (Source ("file://" ++ path) "" Nothing)
70+ process (DerivationSource "" path "" "", unpacked)
6671
6772 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
6873 process (derivSource, file) = (,) derivSource <$> f file