refactor(tvix/cli): split CLI-specific IO logic into TvixIO type

This adds a wrapper type TvixIO<T: EvalIO>, which can wrap around an
arbitrary EvalIO implementation and perform actions needed for the
Tvix CLI (marking imported paths as known, and handling __corepkgs__).

Change-Id: I5fc1ca199b9f94b21a89103b84575e0f8f58dff9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8579
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Vincent Ambo 2023-05-17 18:33:22 +03:00 committed by tazjin
parent 7f99eb44a5
commit ba4807e1de
3 changed files with 84 additions and 11 deletions

View file

@ -3,6 +3,7 @@ mod errors;
mod known_paths;
mod nix_compat;
mod refscan;
mod tvix_io;
use std::cell::RefCell;
use std::rc::Rc;
@ -62,7 +63,10 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
let known_paths: Rc<RefCell<KnownPaths>> = Default::default();
eval.strict = args.strict;
eval.io_handle = Box::new(nix_compat::NixCompatIO::new(known_paths.clone()));
eval.io_handle = Box::new(tvix_io::TvixIO::new(
known_paths.clone(),
nix_compat::NixCompatIO::new(),
));
// bundle fetchurl.nix (used in nixpkgs) by resolving <nix> to
// `/__corepkgs__`, which has special handling in [`nix_compat`].