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

@ -13,24 +13,27 @@ use std::path::{Path, PathBuf};
use tvix_eval::{EvalIO, FileType};
// TODO: Merge this together with TvixStoreIO?
pub struct TvixIO<T: EvalIO> {
pub struct TvixIO<T> {
// Actual underlying [EvalIO] implementation.
actual: T,
}
impl<T: EvalIO> TvixIO<T> {
impl<T> TvixIO<T> {
pub fn new(actual: T) -> Self {
Self { actual }
}
}
impl<T: EvalIO> EvalIO for TvixIO<T> {
impl<T> EvalIO for TvixIO<T>
where
T: AsRef<dyn EvalIO>,
{
fn store_dir(&self) -> Option<String> {
self.actual.store_dir()
self.actual.as_ref().store_dir()
}
fn import_path(&self, path: &Path) -> io::Result<PathBuf> {
let imported_path = self.actual.import_path(path)?;
let imported_path = self.actual.as_ref().import_path(path)?;
Ok(imported_path)
}
@ -39,7 +42,7 @@ impl<T: EvalIO> EvalIO for TvixIO<T> {
return Ok(true);
}
self.actual.path_exists(path)
self.actual.as_ref().path_exists(path)
}
fn read_to_string(&self, path: &Path) -> io::Result<String> {
@ -56,10 +59,10 @@ impl<T: EvalIO> EvalIO for TvixIO<T> {
return Ok(include_str!("fetchurl.nix").to_string());
}
self.actual.read_to_string(path)
self.actual.as_ref().read_to_string(path)
}
fn read_dir(&self, path: &Path) -> io::Result<Vec<(bytes::Bytes, FileType)>> {
self.actual.read_dir(path)
self.actual.as_ref().read_dir(path)
}
}