Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustPlatform.importCargoLock: use fetchCrate #234650

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions pkgs/build-support/rust/import-cargo-lock.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchgit, fetchurl, lib, writers, python3Packages, runCommand, cargo, jq }:
{ lib, fetchgit, fetchCrate, writers, python3Packages, runCommand, cargo, jq }:

{
# Cargo lock file
Expand Down Expand Up @@ -87,21 +87,6 @@ let
value = hash;
}) outputHashes;

# We can't use the existing fetchCrate function, since it uses a
# recursive hash of the unpacked crate.
fetchCrate = pkg: downloadUrl:
let
checksum = pkg.checksum or parsedLockFile.metadata."checksum ${pkg.name} ${pkg.version} (${pkg.source})";
in
assert lib.assertMsg (checksum != null) ''
Package ${pkg.name} does not have a checksum.
'';
fetchurl {
name = "crate-${pkg.name}-${pkg.version}.tar.gz";
url = "${downloadUrl}/${pkg.name}/${pkg.version}/download";
sha256 = checksum;
};

registries = {
"https://github.com/rust-lang/crates.io-index" = "https://crates.io/api/v1/crates";
} // extraRegistries;
Expand All @@ -119,7 +104,18 @@ let
in
if lib.hasPrefix "registry+" pkg.source && builtins.hasAttr registryIndexUrl registries then
let
crateTarball = fetchCrate pkg registries.${registryIndexUrl};
checksum = pkg.checksum or parsedLockFile.metadata."checksum ${pkg.name} ${pkg.version} (${pkg.source})";
crateTarball =
assert lib.assertMsg (checksum != null) ''
Package ${pkg.name} does not have a checksum.
'';
fetchCrate {
pname = pkg.name;
inherit (pkg) version;
registryDl = registries.${registryIndexUrl};
sha256 = checksum;
unpack = false;
};
in runCommand "${pkg.name}-${pkg.version}" {} ''
mkdir $out
tar xf "${crateTarball}" -C $out --strip-components=1
Expand Down