crane/lib/registryFromSparse.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

26 lines
620 B
Nix

{ registryFromDownloadUrl, lib }:
{ indexUrl
, configSha256
, fetchurlExtraArgs ? { }
}:
let
slashTerminatedIndexUrl = if lib.hasSuffix "/" indexUrl then indexUrl else "${indexUrl}/";
configContents = builtins.readFile "${builtins.fetchurl {
url = "${slashTerminatedIndexUrl}config.json";
sha256 = configSha256;
}}";
config = builtins.fromJSON configContents;
dl = config.dl or (throw ''
registry config does not have a "dl" endpoint:
${configContents}
'');
in
registryFromDownloadUrl {
inherit dl fetchurlExtraArgs;
registryPrefix = "sparse+";
indexUrl = slashTerminatedIndexUrl;
}