depot/third_party/nixpkgs/pkgs/build-support/rust/fetchcrate.nix

18 lines
442 B
Nix
Raw Normal View History

{ lib, fetchzip, fetchurl }:
{ crateName ? args.pname
, pname ? null
, version
, unpack ? true
, ...
} @ args:
assert pname == null || pname == crateName;
(if unpack then fetchzip else fetchurl) ({
name = "${crateName}-${version}.tar.gz";
url = "https://crates.io/api/v1/crates/${crateName}/${version}/download";
} // lib.optionalAttrs unpack {
extension = "tar.gz";
} // removeAttrs args [ "crateName" "pname" "version" "unpack" ])