crane/lib/registryFromDownloadUrl.nix
James Baker 75f7d715f8
Natively support sparse registries (#324)
With Cargo 1.68.0, sparse registries were made stable. With sparse
registries, index metadata is stored in an HTTP api rather than in
a git repository.

As relevant to Crane, the relevant changes are mostly that registries
do not always start with `registry+` and mostly start with `registry+`
or `sparse+` depending on whether the registry is sparse or not.

This PR adjusts the core of Crane to differentiate between `registry`
and `sparse`, and adds a new sparse registry factory to make things
easy.

---------

Co-authored-by: Ivan Petkov <ivanppetkov@gmail.com>
2023-06-13 02:03:18 +00:00

33 lines
667 B
Nix

{ lib
}:
# https://doc.rust-lang.org/cargo/reference/registries.html
{ dl
, indexUrl
, registryPrefix ? "registry+"
, fetchurlExtraArgs ? { }
}:
let
matches = m: builtins.match ".*${lib.escapeRegex m}.*" dl;
hasMarker = lib.any (m: null != matches m) [
"{crate}"
"{version}"
"{prefix}"
"{lowerprefix}"
"{sha256-checksum}"
];
fullDownloadUrl = if hasMarker then dl else "${dl}/{crate}/{version}/download";
registryIndexUrl =
if lib.hasPrefix registryPrefix indexUrl
then indexUrl
else "${registryPrefix}${indexUrl}";
in
{
"${registryIndexUrl}" = {
inherit fetchurlExtraArgs;
downloadUrl = fullDownloadUrl;
};
}