Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch remote tarballs/zips using nix-prefetch-url --unpack #585

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cabal2nix/src/Distribution/Nixpkgs/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Distribution.Nixpkgs.Fetch
, derivKindFunction
, FetchSubmodules(..)
, UnpackArchive(..)
, fetchPackedUrl
, fetch
, fetchWith
) where
Expand Down Expand Up @@ -115,6 +116,9 @@ fromDerivationSource DerivationSource{..} =
sourceCabalDir = "."
}

fetchPackedUrl :: (String -> MaybeT IO a) -> Source -> IO (Maybe (DerivationSource, a))
fetchPackedUrl f = runMaybeT . (fetchWith (False, DerivKindUrl UnpackArchive) >=> \(derivSource, file) -> (,) derivSource <$> f file)

-- | Fetch a source, trying any of the various nix-prefetch-* scripts.
fetch :: forall a.
FetchSubmodules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ fetchOrFromDB optHpack optSubmodules hackageDB src
(msrc, pkgDesc) <- fromDB hackageDB . drop (length "cabal://") $ sourceUrl src
return (msrc, False, pkgDesc)
| otherwise = do
r <- fetch optSubmodules (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
let fetcher =
if checkAny isPrefixOf ["http://", "https://"] (sourceUrl src) &&
checkAny isSuffixOf ["tar.gz", ".tgz", ".zip"] (sourceUrl src)
then fetchPackedUrl
else fetch optSubmodules
r <- fetcher (\dir -> cabalFromPath optHpack (dir </> sourceCabalDir src)) src
case r of
Nothing -> fail $ "Failed to fetch source. Does this source exist? " ++ show src
Just (derivSource, (externalSource, ranHpack, pkgDesc)) ->
return (derivSource <$ guard externalSource, ranHpack, pkgDesc)
where
checkAny f xs s = or $ (`f` s) <$> xs

loadHackageDB :: Maybe FilePath
-- ^ The path to the Hackage database.
Expand Down