refactor(tvix): move tvix glue code into glue crate

There's various bits and pieces in tvix-cli that use both the store and
evaluator, as well as nix-compat. For example, builtins.derivation, as
well as the reference scanning implementation.

This "glue code" currently isn't accessible from anywhere else, but it'd
be very useful if it were.

Move it out into a `glue` crate, and make `tvix-cli` a consumer of it.

All the KnownPaths setup and passing around, as well as NIX_PATH
handling is also something that should probably be moved into the glue
crate as well, but that's something left for a future CL.

Change-Id: I080ed3d1825ab23790666486840f301f00856277
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9908
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
Florian Klink 2023-11-03 13:34:37 +02:00 committed by clbot
parent a51d277764
commit 3196fe0143
17 changed files with 154 additions and 22 deletions

View file

@ -1,24 +1,18 @@
mod derivation;
mod errors;
mod known_paths;
mod refscan;
mod tvix_io;
mod tvix_store_io;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use std::{fs, path::PathBuf};
use tvix_glue::add_derivation_builtins;
use tvix_glue::known_paths::KnownPaths;
use clap::Parser;
use known_paths::KnownPaths;
use rustyline::{error::ReadlineError, Editor};
use tvix_castore::blobservice::MemoryBlobService;
use tvix_castore::directoryservice::MemoryDirectoryService;
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_io::TvixStoreIO;
#[derive(Parser)]
struct Args {
@ -69,7 +63,6 @@ struct Args {
/// evaluation succeeded.
fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> bool {
let mut eval = tvix_eval::Evaluation::new_impure(code, path);
let known_paths: Rc<RefCell<KnownPaths>> = Default::default();
eval.strict = args.strict;
@ -80,9 +73,11 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
directory_service.clone(),
));
let tokio_runtime = tokio::runtime::Runtime::new().unwrap();
let known_paths: Rc<RefCell<KnownPaths>> = Default::default();
add_derivation_builtins(&mut eval, known_paths.clone());
eval.io_handle = Box::new(tvix_io::TvixIO::new(
let tokio_runtime = tokio::runtime::Runtime::new().unwrap();
eval.io_handle = Box::new(tvix_glue::tvix_io::TvixIO::new(
known_paths.clone(),
TvixStoreIO::new(
blob_service,
@ -100,13 +95,6 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
.map(|p| format!("nix=/__corepkgs__:{}", p))
.or_else(|| Some("nix=/__corepkgs__".to_string()));
eval.builtins
.extend(derivation::derivation_builtins(known_paths));
// Add the actual `builtins.derivation` from compiled Nix code
eval.src_builtins
.push(("derivation", include_str!("derivation.nix")));
let source_map = eval.source_map();
let result = {
let mut compiler_observer =