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

Adding sparse protocol #304583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkgs/build-support/rust/import-cargo-lock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}" {} ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[registries.sparse-crates-io]
index = "sparse+https://index.crates.io/"

[registries.crates-io]
protocol = "git"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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" }
Original file line number Diff line number Diff line change
@@ -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
'';
}
Original file line number Diff line number Diff line change
@@ -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);
}