Skip to content

Commit ccedf3d

Browse files
committed
Fetch .tar.gz using nix-prefetch-url --unpack
Fetching `tar.gz` files is common enough of a use-case that warrants treating them specially by bypassing other fetching options and using `nix-prefetch-url --unpack` directly. This speeds up large tarballs as `cabal2nix` currently downloads them twice as the first fetch assumes an unpacked url and thus will fail.
1 parent 8e97f51 commit ccedf3d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cabal2nix/src/Distribution/Nixpkgs/Fetch.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Distribution.Nixpkgs.Fetch
1212
, derivKindFunction
1313
, FetchSubmodules(..)
1414
, UnpackArchive(..)
15+
, fetchTarball
1516
, fetch
1617
, fetchWith
1718
) where
@@ -115,6 +116,9 @@ fromDerivationSource DerivationSource{..} =
115116
sourceCabalDir = "."
116117
}
117118

119+
fetchTarball :: (String -> MaybeT IO a) -> Source -> IO (Maybe (DerivationSource, a))
120+
fetchTarball f = runMaybeT . (fetchWith (False, DerivKindUrl UnpackArchive) >=> \(derivSource, file) -> (,) derivSource <$> f file)
121+
118122
-- | Fetch a source, trying any of the various nix-prefetch-* scripts.
119123
fetch :: forall a.
120124
FetchSubmodules

cabal2nix/src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ fetchOrFromDB optHpack optSubmodules hackageDB src
9595
(msrc, pkgDesc) <- fromDB hackageDB . drop (length "cabal://") $ sourceUrl src
9696
return (msrc, False, pkgDesc)
9797
| otherwise = do
98-
r <- fetch optSubmodules (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
98+
let fetcher =
99+
if "tar.gz" `isSuffixOf` sourceUrl src
100+
then fetchTarball
101+
else fetch optSubmodules
102+
r <- fetcher (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
99103
case r of
100104
Nothing -> fail $ "Failed to fetch source. Does this source exist? " ++ show src
101105
Just (derivSource, (externalSource, ranHpack, pkgDesc)) ->

0 commit comments

Comments
 (0)