about summary refs log tree commit diff
path: root/tvix/cli/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/cli/src/main.rs')
-rw-r--r--tvix/cli/src/main.rs67
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(),
         ),
     ));