core/pkgs/build-support/rust/fetchcrate.nix

34 lines
675 B
Nix
Raw Normal View History

2024-06-30 08:16:52 +00:00
{
lib,
fetchzip,
fetchurl,
}:
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
{
crateName ? args.pname,
pname ? null,
2024-05-02 00:46:19 +00:00
# The `dl` field of the registry's index configuration
# https://doc.rust-lang.org/cargo/reference/registry-index.html#index-configuration
2024-06-30 08:16:52 +00:00
registryDl ? "https://crates.io/api/v1/crates",
version,
unpack ? true,
...
}@args:
2024-05-02 00:46:19 +00:00
assert pname == null || pname == crateName;
2024-06-30 08:16:52 +00:00
(if unpack then fetchzip else fetchurl) (
{
name = "${crateName}-${version}.tar.gz";
url = "${registryDl}/${crateName}/${version}/download";
}
// lib.optionalAttrs unpack { extension = "tar.gz"; }
// removeAttrs args [
"crateName"
"pname"
"registryDl"
"version"
"unpack"
]
)