diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-31T12·28+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-12-31T21·55+0000 |
commit | e2b6c77bfc4d00ba275d8029fe333d6064c268e9 (patch) | |
tree | 839d5b030fb04105e784e834b26cf13360a5dfd9 | |
parent | 06db871bd75a714a61434dd4b13bc87e1319ba92 (diff) |
feat(tvix/cli): allow configuring different services r/7292
At some point, tvix-cli needs to talk to the outside world to persist things into a real store. Introduce the same CLI options to configure {Blob,Directory,PathInfo}Service URLs. We need to be a bit careful with how we set up stores, and make this separate from setting up TvixStoreIO, as it's holding a Rc<RefCell<KnonPath>> which not Send. At some point, we might make this a Arc<RwLock<_>> later anyways, and then this can be simplified a bit, but for now, this is sufficient. Change-Id: I87d84ca3a10ce947e194ff985073791469773f35 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10474 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/cli/src/main.rs | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index 149b08fa8e71..a45061412c1c 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -7,12 +7,12 @@ use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path}; use clap::Parser; use rustyline::{error::ReadlineError, Editor}; -use tvix_castore::blobservice::MemoryBlobService; -use tvix_castore::directoryservice::MemoryDirectoryService; +use tvix_castore::blobservice::{self, BlobService}; +use tvix_castore::directoryservice::{self, DirectoryService}; use tvix_eval::observer::{DisassemblingObserver, TracingObserver}; use tvix_eval::Value; use tvix_glue::tvix_store_io::TvixStoreIO; -use tvix_store::pathinfoservice::MemoryPathInfoService; +use tvix_store::pathinfoservice::{self, PathInfoService}; #[derive(Parser)] struct Args { @@ -56,6 +56,37 @@ struct Args { /// return value. #[clap(long)] strict: bool, + + #[arg(long, env, default_value = "memory://")] + blob_service_addr: String, + + #[arg(long, env, default_value = "memory://")] + directory_service_addr: String, + + #[arg(long, env, default_value = "memory://")] + path_info_service_addr: String, +} + +/// Construct the three store handles from their addrs. +async fn construct_services( + blob_service_addr: impl AsRef<str>, + directory_service_addr: impl AsRef<str>, + path_info_service_addr: impl AsRef<str>, +) -> std::io::Result<( + Arc<dyn BlobService>, + Arc<dyn DirectoryService>, + Box<dyn PathInfoService>, +)> { + let blob_service = blobservice::from_addr(blob_service_addr.as_ref()).await?; + let directory_service = directoryservice::from_addr(directory_service_addr.as_ref()).await?; + let path_info_service = pathinfoservice::from_addr( + path_info_service_addr.as_ref(), + blob_service.clone(), + directory_service.clone(), + ) + .await?; + + Ok((blob_service, directory_service, path_info_service)) } /// Interprets the given code snippet, printing out warnings, errors @@ -63,27 +94,35 @@ struct Args { /// evaluation succeeded. fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> bool { let mut eval = tvix_eval::Evaluation::new_impure(); - eval.strict = args.strict; - let blob_service = Arc::new(MemoryBlobService::default()); - let directory_service = Arc::new(MemoryDirectoryService::default()); - let path_info_service = Arc::new(MemoryPathInfoService::new( - blob_service.clone(), - directory_service.clone(), - )); + let tokio_runtime = tokio::runtime::Runtime::new().expect("failed to setup tokio runtime"); + + let (blob_service, directory_service, path_info_service) = tokio_runtime + .block_on({ + let blob_service_addr = args.blob_service_addr.clone(); + let directory_service_addr = args.directory_service_addr.clone(); + let path_info_service_addr = args.path_info_service_addr.clone(); + async move { + construct_services( + blob_service_addr, + directory_service_addr, + path_info_service_addr, + ) + .await + } + }) + .expect("unable to setup {blob|directory|pathinfo}service before interpreter setup"); let known_paths: Rc<RefCell<KnownPaths>> = Default::default(); add_derivation_builtins(&mut eval, known_paths.clone()); configure_nix_path(&mut eval, &args.nix_search_path); - - let tokio_runtime = tokio::runtime::Runtime::new().unwrap(); eval.io_handle = Box::new(tvix_glue::tvix_io::TvixIO::new( - known_paths.clone(), + known_paths, TvixStoreIO::new( blob_service, directory_service, - path_info_service, + path_info_service.into(), // we need an Arc<_> here. tokio_runtime.handle().clone(), ), )); |