summaryrefslogtreecommitdiff
path: root/pkgs/build-support/rust/fetchcrate.nix
blob: b34f0336691b503309769a56e6e7e1e5e0267686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
  lib,
  fetchzip,
  fetchurl,
}:

{
  crateName ? args.pname,
  pname ? null,
  # The `dl` field of the registry's index configuration
  # https://doc.rust-lang.org/cargo/reference/registry-index.html#index-configuration
  registryDl ? "https://crates.io/api/v1/crates",
  version,
  unpack ? true,
  ...
}@args:

assert pname == null || pname == crateName;

(if unpack then fetchzip else fetchurl) (
  {
    name = "${crateName}-${version}.tar.gz";
    url = "${registryDl}/${crateName}/${version}/download";

    passthru = { inherit pname version; };
  }
  // lib.optionalAttrs unpack {
    extension = "tar.gz";
  }
  // removeAttrs args [
    "crateName"
    "pname"
    "registryDl"
    "version"
    "unpack"
  ]
)