git.iko.soy/typeable/cabal2nix
on master help sign in
Support local source archives
37f1a2cBenno Fünfstück
README.md+1−2
@@ -101,10 +101,9 @@ contains the derivation as the source repository.
101`cabal2nix` currently supports the following respository types:
101`cabal2nix` currently supports the following respository types:
102
102
103* directory
103* 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.
105* git, mercurial, svn or bazaar repository
105* git, mercurial, svn or bazaar repository
106
106
107−
108### Hackage4nix
107### Hackage4nix
109
108
110The `hackage4nix` utility re-generates *all* expressions found in the
109The `hackage4nix` utility re-generates *all* expressions found in the
src/Cabal2Nix/Package.hs+11−7
@@ -124,14 +124,18 @@ cabalFromDirectory dir = do
124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
124 _ -> liftIO $ hPutStrLn stderr "*** found zero or more than one cabal file. Exiting." >> exitFailure
125
125
126cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
126cabalFromFile :: Bool -> FilePath -> MaybeT IO Cabal.GenericPackageDescription
127−cabalFromFile failHard file = do
127+cabalFromFile failHard file =
128− content <- MaybeT $ either (const Nothing) Just <$> Compat.tryIO (readFile 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
129− case Cabal.parsePackageDescription content of
134+ case Cabal.parsePackageDescription content of
130− Cabal.ParseFailed e -> do
135+ Cabal.ParseFailed e | failHard -> do
131− guard failHard
132− liftIO $ do
133 let (line, err) = ParseUtils.locatedErrorMsg e
136 let (line, err) = ParseUtils.locatedErrorMsg e
134 msg = maybe "" ((++ ": ") . show) line ++ err
137 msg = maybe "" ((++ ": ") . show) line ++ err
135 putStrLn $ "*** error parsing cabal file: " ++ msg
138 putStrLn $ "*** error parsing cabal file: " ++ msg
136 exitFailure
139 exitFailure
140+ Cabal.ParseFailed _ -> return Nothing
137− Cabal.ParseOk _ a -> return a
141+ Cabal.ParseOk _ a -> return (Just a)
src/Distribution/NixOS/Fetch.hs+6−1
@@ -62,7 +62,12 @@ fetch f = runMaybeT . fetchers where
62 existsFile <- liftIO $ doesFileExist path
62 existsFile <- liftIO $ doesFileExist path
63 existsDir <- liftIO $ doesDirectoryExist path
63 existsDir <- liftIO $ doesDirectoryExist path
64 guard $ existsDir || existsFile
64 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)
66
71
67 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
72 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
68 process (derivSource, file) = (,) derivSource <$> f file
73 process (derivSource, file) = (,) derivSource <$> f file