rustPlatform.importCargoLock: Adding sparse protocol

When added the new sparse protocol the derivation is not handling properly Cargo.lock with sparse+ registries
This commit is contained in:
Ruben Sanchez Diez 2024-04-16 10:09:02 +02:00
parent b0b73738b4
commit e6dc0fb1a1
6 changed files with 135 additions and 1 deletions

View File

@ -12,6 +12,8 @@
# Additional registries to pull sources from
# { "https://<registry index URL>" = "https://<registry download URL>"; }
# or if the registry is using the new sparse protocol
# { "sparse+https://<registry download URL>" = "https://<registry download URL>"; }
# where:
# - "index URL" is the "index" value of the configuration entry for that registry
# https://doc.rust-lang.org/cargo/reference/registries.html#using-an-alternate-registry
@ -117,7 +119,8 @@ let
gitParts = parseGit pkg.source;
registryIndexUrl = lib.removePrefix "registry+" pkg.source;
in
if lib.hasPrefix "registry+" pkg.source && builtins.hasAttr registryIndexUrl registries then
if (lib.hasPrefix "registry+" pkg.source || lib.hasPrefix "sparse+" pkg.source)
&& builtins.hasAttr registryIndexUrl registries then
let
crateTarball = fetchCrate pkg registries.${registryIndexUrl};
in runCommand "${pkg.name}-${pkg.version}" {} ''

View File

@ -0,0 +1,5 @@
[registries.sparse-crates-io]
index = "sparse+https://index.crates.io/"
[registries.crates-io]
protocol = "git"

View File

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "basic-sparse"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "sparse+https://index.crates.io/"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.14"
source = "sparse+https://index.crates.io/"
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "sparse+https://index.crates.io/"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "sparse+https://index.crates.io/"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "sparse+https://index.crates.io/"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "sparse+https://index.crates.io/"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "sparse+https://index.crates.io/"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "sparse+https://index.crates.io/"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

View File

@ -0,0 +1,9 @@
[package]
name = "basic-sparse"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = { version = "0.8", registry = "sparse-crates-io" }

View File

@ -0,0 +1,33 @@
{ lib, rustPlatform }:
let
fs = lib.fileset;
in
rustPlatform.buildRustPackage {
pname = "basic-sparse";
version = "0.1.0";
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./.cargo/config.toml
./Cargo.toml
./Cargo.lock
./src
];
};
cargoLock = {
lockFile = ./Cargo.lock;
extraRegistries = {
"sparse+https://index.crates.io/" = "https://static.crates.io/crates";
};
};
doInstallCheck = true;
postConfigure = ''
cargo metadata --offline
'';
installCheckPhase = ''
$out/bin/basic-sparse
'';
}

View File

@ -0,0 +1,9 @@
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
// Always draw zero :).
let roll: u8 = rng.gen_range(0..1);
assert_eq!(roll, 0);
}