Skip to content

Commit 5fa6300

Browse files
committed
Add --substituter option
This allows nix-index to e.g. work offline with custom substituter. Fixes #125.
1 parent 0fc3804 commit 5fa6300

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/bin/nix-channel-index.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use futures::{future, StreamExt};
1010
use nix_index::files::{FileNode, FileType};
1111
use nix_index::hydra::Fetcher;
1212
use nix_index::listings;
13-
use nix_index::{errors::*, CACHE_URL};
13+
use nix_index::{errors::*};
1414
use rusqlite::Connection;
1515

1616
/// The main function of this module: creates a new command-not-found database.
1717
async fn update_index(args: &Args) -> Result<()> {
18-
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(Error::ParseProxy)?;
18+
let fetcher = Fetcher::new(args.substituter.to_string()).map_err(Error::ParseProxy)?;
1919
let connection = Connection::open_in_memory().map_err(|e| Error::CreateDatabase {
2020
path: args.output.clone(),
2121
source: Box::new(e),
@@ -197,6 +197,10 @@ struct Args {
197197
#[clap(short = 's', long = "platform")]
198198
systems: Option<Vec<String>>,
199199

200+
/// The substituter (binary cache) URL to query
201+
#[clap(long, default_value = "https://cache.nixos.org")]
202+
substituter: String,
203+
200204
/// Show a stack trace in the case of a Nix evaluation error
201205
#[clap(long)]
202206
show_trace: bool,

src/bin/nix-index.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use nix_index::files::FileTree;
1414
use nix_index::hydra::Fetcher;
1515
use nix_index::listings::{self, try_load_paths_cache};
1616
use nix_index::package::StorePath;
17-
use nix_index::CACHE_URL;
1817
use separator::Separatable;
1918

2019
/// The main function of this module: creates a new nix-index database.
@@ -30,7 +29,7 @@ async fn update_index(args: &Args) -> Result<()> {
3029
};
3130

3231
eprintln!("+ querying available packages");
33-
let fetcher = Fetcher::new(CACHE_URL.to_string()).map_err(Error::ParseProxy)?;
32+
let fetcher = Fetcher::new(args.substituter.to_string()).map_err(Error::ParseProxy)?;
3433
let (files, watch) = match cached {
3534
Some((f, w)) => (Either::Left(f), w),
3635
None => {
@@ -150,6 +149,10 @@ struct Args {
150149
#[clap(short = 's', long, value_name = "platform")]
151150
system: Option<String>,
152151

152+
/// The substituter (binary cache) URL to query
153+
#[clap(long, default_value = "https://cache.nixos.org")]
154+
substituter: String,
155+
153156
/// Zstandard compression level
154157
#[clap(short, long = "compression", default_value = "22")]
155158
compression_level: i32,

src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,3 @@ pub mod nixpkgs;
1616
pub mod package;
1717
pub mod util;
1818
pub mod workset;
19-
20-
/// The URL of the binary cache that we use to fetch file listings and references.
21-
///
22-
/// Hardcoded for now, but may be made a configurable option in the future.
23-
pub const CACHE_URL: &str = "https://cache.nixos.org";

0 commit comments

Comments
 (0)