diff options
author | Ryan Lahfa <tvl@lahfa.xyz> | 2024-01-16T04·31+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-18T14·28+0000 |
commit | 12ae96cff2e925f502cee8afb4f8dcf54aba27d8 (patch) | |
tree | 661f8bf7401b524d9ac3dc6770eddd10b3bdb4d7 /tvix/cli/src/main.rs | |
parent | 43b9e25025eef302369ff27074bfa5bbfb1c7115 (diff) |
feat(tvix/glue): use TvixStoreIO as derivation builtin state r/7410
We propagate a `TvixStoreIO` as the `state` of our derivation-specific builtins in the glue crate. The evaluators `io_handle` itself is using a Rc<dyn EvalIO>. An earlier version of TvixStoreIO was also introducing generics over the different internal services themselves, but we opted for instead hardcoding this to Arc<dyn …> for the sake of less macro voodoo. Change-Id: I535c476f06b840858fa3070c4a237ece47f7a15b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10636 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: raitobezarius <tvl@lahfa.xyz> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/cli/src/main.rs')
-rw-r--r-- | tvix/cli/src/main.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index d7878c9a09b7..1e54d094b517 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -1,14 +1,13 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::{fs, path::PathBuf}; -use tvix_glue::known_paths::KnownPaths; -use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path}; - use clap::Parser; use rustyline::{error::ReadlineError, Editor}; +use std::rc::Rc; +use std::{fs, path::PathBuf}; +use tvix_eval::builtins::impure_builtins; use tvix_eval::observer::{DisassemblingObserver, TracingObserver}; -use tvix_eval::Value; +use tvix_eval::{EvalIO, Value}; +use tvix_glue::tvix_io::TvixIO; use tvix_glue::tvix_store_io::TvixStoreIO; +use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path}; #[derive(Parser)] struct Args { @@ -67,9 +66,6 @@ struct Args { /// and the result itself. The return value indicates whether /// 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 tokio_runtime = tokio::runtime::Runtime::new().expect("failed to setup tokio runtime"); let (blob_service, directory_service, path_info_service) = tokio_runtime @@ -88,15 +84,21 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b }) .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); - eval.io_handle = Box::new(tvix_glue::tvix_io::TvixIO::new(TvixStoreIO::new( - blob_service, - directory_service, - path_info_service, + let tvix_store_io = Rc::new(TvixStoreIO::new( + blob_service.clone(), + directory_service.clone(), + path_info_service.into(), tokio_runtime.handle().clone(), - ))); + )); + + let mut eval = tvix_eval::Evaluation::new( + Box::new(TvixIO::new(tvix_store_io.clone() as Rc<dyn EvalIO>)) as Box<dyn EvalIO>, + true, + ); + eval.strict = args.strict; + eval.builtins.extend(impure_builtins()); + add_derivation_builtins(&mut eval, tvix_store_io); + configure_nix_path(&mut eval, &args.nix_search_path); let source_map = eval.source_map(); let result = { |