From 12ae96cff2e925f502cee8afb4f8dcf54aba27d8 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 16 Jan 2024 05:31:20 +0100 Subject: feat(tvix/glue): use TvixStoreIO as derivation builtin state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. An earlier version of TvixStoreIO was also introducing generics over the different internal services themselves, but we opted for instead hardcoding this to Arc for the sake of less macro voodoo. Change-Id: I535c476f06b840858fa3070c4a237ece47f7a15b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10636 Reviewed-by: raitobezarius Autosubmit: raitobezarius Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/cli/src/main.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'tvix/cli/src/main.rs') 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, 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, args: &Args, explain: bool) -> b }) .expect("unable to setup {blob|directory|pathinfo}service before interpreter setup"); - let known_paths: Rc> = 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)) as Box, + 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 = { -- cgit 1.4.1