From 3d701943d17e9b34820ca2f26e1f63a5031584da Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 4 Jan 2025 00:05:35 -0500 Subject: feat: allow for querying multiple substituters (#49) --- README.md | 2 +- src/cli.rs | 11 ++++++++--- src/command.rs | 13 +++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0235703..139f5a4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Arguments: Options: -c, --configuration Flake reference pointing to a NixOS or nix-darwin configuration - -b, --binary-cache URL of the substituter to check [default: https://cache.nixos.org] + -b, --binary-caches URLs of the substituters to check (can be passed more than once) [default: https://cache.nixos.org] -f, --flake Flake reference of nixpkgs (or other package repository) [default: nixpkgs] -s, --show-missing Show a list of store paths not found in the substituter -h, --help Print help diff --git a/src/cli.rs b/src/cli.rs index 41587c8..edfba5d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,9 +11,14 @@ pub struct Cli { #[arg(short, long, conflicts_with("installables"))] pub configuration: Option, - /// URL of the substituter to check - #[arg(short, long, default_value = "https://cache.nixos.org")] - pub binary_cache: String, + /// URLs of the substituters to check (can be passed more than once) + #[arg( + alias = "binary-cache", + short, + long, + default_value = "https://cache.nixos.org" + )] + pub binary_caches: Vec, /// Flake reference of nixpkgs (or other package repository) #[arg(short, long, default_value = "nixpkgs")] diff --git a/src/command.rs b/src/command.rs index 8e8a312..be1dd4c 100644 --- a/src/command.rs +++ b/src/command.rs @@ -26,7 +26,7 @@ impl Run for crate::Cli { resolve_installables(installables).await? }; - check_store_paths(&self.binary_cache, &store_paths, self.show_missing).await?; + check_store_paths(&self.binary_caches, &store_paths, self.show_missing).await?; Ok(()) } @@ -63,12 +63,12 @@ async fn resolve_installables(installables: Vec) -> Result> #[allow(clippy::cast_precision_loss)] #[instrument(skip(store_paths))] async fn check_store_paths( - binary_cache: &str, + binary_caches: &Vec, store_paths: &Vec, show_missing: bool, ) -> Result<()> { let num_store_paths = store_paths.len(); - println!("🌡️ Checking for {num_store_paths} store path(s) in {binary_cache}",); + println!("🌡️ Checking for {num_store_paths} store path(s) in: {binary_caches:?}"); let http = ::default(); let progress_bar = ProgressBar::new(num_store_paths as u64).with_style(progress_style()?); @@ -78,7 +78,12 @@ async fn check_store_paths( let http = &http; let progress_bar = &progress_bar; async move { - let has_store_path = http.has_store_path(binary_cache, store_path).await?; + let mut has_store_path = false; + for binary_cache in binary_caches { + if http.has_store_path(binary_cache, store_path).await? { + has_store_path = true; + } + } progress_bar.inc(1); anyhow::Ok((has_store_path, store_path.as_str())) -- cgit v1.2.3