feat(tvix/glue): use TvixStoreIO as derivation builtin state

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>
This commit is contained in:
Ryan Lahfa 2024-01-16 05:31:20 +01:00 committed by clbot
parent 43b9e25025
commit 12ae96cff2
7 changed files with 124 additions and 102 deletions

View file

@ -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 = {