2022-01-30 03:12:22 +03:00
|
|
|
{ crateRegistries
|
|
|
|
, lib
|
|
|
|
}:
|
2021-12-27 01:05:23 +03:00
|
|
|
|
|
|
|
{ name
|
|
|
|
, version
|
|
|
|
, source
|
2022-01-30 03:12:22 +03:00
|
|
|
, checksum
|
2021-12-27 01:05:23 +03:00
|
|
|
, ...
|
2022-01-30 03:12:22 +03:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
substr = builtins.substring;
|
|
|
|
|
|
|
|
# https://doc.rust-lang.org/cargo/reference/registries.html
|
|
|
|
nameLen = builtins.stringLength name;
|
|
|
|
prefix =
|
|
|
|
if nameLen == 1 then "1"
|
|
|
|
else if nameLen == 2 then "2"
|
|
|
|
else if nameLen == 3 then "3/${substr 0 1 name}"
|
|
|
|
else "${substr 0 2 name}/${substr 2 4 name}";
|
|
|
|
|
2023-06-13 05:03:18 +03:00
|
|
|
knownRegistries = "\n " + lib.concatStringsSep "\n " (builtins.attrNames crateRegistries) + "\n";
|
2022-11-21 03:22:13 +03:00
|
|
|
registry = crateRegistries.${source} or (throw ''
|
2022-01-30 03:12:22 +03:00
|
|
|
not sure how to download crates from ${source}.
|
2023-06-13 05:03:18 +03:00
|
|
|
known registries are: ${knownRegistries}
|
2022-01-30 03:12:22 +03:00
|
|
|
for example, this can be resolved with:
|
|
|
|
|
|
|
|
craneLib = crane.lib.''${system}.appendCrateRegistries [
|
|
|
|
(lib.registryFromDownloadUrl {
|
2024-03-20 00:55:28 +03:00
|
|
|
dl = "https://static.crates.io/crates";
|
2022-01-30 03:12:22 +03:00
|
|
|
indexUrl = "https://github.com/rust-lang/crates.io-index";
|
|
|
|
})
|
|
|
|
|
|
|
|
# Or, alternatively
|
|
|
|
(lib.registryFromGitIndex {
|
|
|
|
url = "https://github.com/Hirevo/alexandrie-index";
|
|
|
|
rev = "90df25daf291d402d1ded8c32c23d5e1498c6725";
|
|
|
|
})
|
2023-06-13 05:03:18 +03:00
|
|
|
|
|
|
|
# Or even
|
|
|
|
(lib.registryFromSparse {
|
|
|
|
indexUrl = "https://index.crates.io/";
|
|
|
|
configSha256 = "d16740883624df970adac38c70e35cf077a2a105faa3862f8f99a65da96b14a3";
|
|
|
|
})
|
2022-01-30 03:12:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
# Then use the new craneLib instance as you would normally
|
|
|
|
craneLib.buildPackage {
|
|
|
|
# ...
|
|
|
|
}
|
|
|
|
'');
|
|
|
|
in
|
2022-11-21 03:22:13 +03:00
|
|
|
{
|
|
|
|
fetchurlExtraArgs = registry.fetchurlExtraArgs or { };
|
|
|
|
url = builtins.replaceStrings
|
|
|
|
[
|
|
|
|
"{crate}"
|
|
|
|
"{version}"
|
|
|
|
"{prefix}"
|
|
|
|
"{lowerprefix}"
|
|
|
|
"{sha256-checksum}"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
name
|
|
|
|
version
|
|
|
|
prefix
|
|
|
|
(lib.toLower prefix)
|
|
|
|
checksum
|
|
|
|
]
|
|
|
|
registry.downloadUrl;
|
|
|
|
}
|