about summary refs log tree commit diff
path: root/tvix/glue/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-11-03T11·34+0200
committerclbot <clbot@tvl.fyi>2023-11-04T15·18+0000
commit3196fe0143b6ff729c177fa5d17fa03c9e9627c9 (patch)
tree33a6cbb1a965a739e8cdd96dc2faec79b83635de /tvix/glue/src
parenta51d277764d73582bc9bf816f6f4163d2df7f9c4 (diff)
refactor(tvix): move tvix glue code into glue crate r/6936
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>
Diffstat (limited to '')
-rw-r--r--tvix/glue/src/.skip-subtree (renamed from tvix/cli/src/.skip-subtree)0
-rw-r--r--tvix/glue/src/derivation.nix (renamed from tvix/cli/src/derivation.nix)0
-rw-r--r--tvix/glue/src/derivation.rs (renamed from tvix/cli/src/derivation.rs)0
-rw-r--r--tvix/glue/src/errors.rs (renamed from tvix/cli/src/errors.rs)0
-rw-r--r--tvix/glue/src/fetchurl.nix (renamed from tvix/cli/src/fetchurl.nix)0
-rw-r--r--tvix/glue/src/known_paths.rs (renamed from tvix/cli/src/known_paths.rs)0
-rw-r--r--tvix/glue/src/lib.rs28
-rw-r--r--tvix/glue/src/refscan.rs (renamed from tvix/cli/src/refscan.rs)0
-rw-r--r--tvix/glue/src/tvix_io.rs (renamed from tvix/cli/src/tvix_io.rs)7
-rw-r--r--tvix/glue/src/tvix_store_io.rs (renamed from tvix/cli/src/tvix_store_io.rs)0
10 files changed, 32 insertions, 3 deletions
diff --git a/tvix/cli/src/.skip-subtree b/tvix/glue/src/.skip-subtree
index a16a2afe1f1e..a16a2afe1f1e 100644
--- a/tvix/cli/src/.skip-subtree
+++ b/tvix/glue/src/.skip-subtree
diff --git a/tvix/cli/src/derivation.nix b/tvix/glue/src/derivation.nix
index 9355cc3a96f0..9355cc3a96f0 100644
--- a/tvix/cli/src/derivation.nix
+++ b/tvix/glue/src/derivation.nix
diff --git a/tvix/cli/src/derivation.rs b/tvix/glue/src/derivation.rs
index 86a271a3966d..86a271a3966d 100644
--- a/tvix/cli/src/derivation.rs
+++ b/tvix/glue/src/derivation.rs
diff --git a/tvix/cli/src/errors.rs b/tvix/glue/src/errors.rs
index 5cbddcbba811..5cbddcbba811 100644
--- a/tvix/cli/src/errors.rs
+++ b/tvix/glue/src/errors.rs
diff --git a/tvix/cli/src/fetchurl.nix b/tvix/glue/src/fetchurl.nix
index 3f182a5a319b..3f182a5a319b 100644
--- a/tvix/cli/src/fetchurl.nix
+++ b/tvix/glue/src/fetchurl.nix
diff --git a/tvix/cli/src/known_paths.rs b/tvix/glue/src/known_paths.rs
index 07373ef0da7a..07373ef0da7a 100644
--- a/tvix/cli/src/known_paths.rs
+++ b/tvix/glue/src/known_paths.rs
diff --git a/tvix/glue/src/lib.rs b/tvix/glue/src/lib.rs
new file mode 100644
index 000000000000..acb81d31445f
--- /dev/null
+++ b/tvix/glue/src/lib.rs
@@ -0,0 +1,28 @@
+use std::{cell::RefCell, rc::Rc};
+
+use known_paths::KnownPaths;
+
+pub mod derivation;
+pub mod errors;
+pub mod known_paths;
+pub mod refscan;
+pub mod tvix_io;
+pub mod tvix_store_io;
+
+/// Adds derivation-related builtins to the passed [tvix_eval::Evaluation].
+///
+/// These are `derivation` and `derivationStrict`.
+///
+/// As they need to interact with `known_paths`, we also need to pass in
+/// `known_paths`.
+pub fn add_derivation_builtins(
+    eval: &mut tvix_eval::Evaluation,
+    known_paths: Rc<RefCell<KnownPaths>>,
+) {
+    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")));
+}
diff --git a/tvix/cli/src/refscan.rs b/tvix/glue/src/refscan.rs
index 0e0bb6c77828..0e0bb6c77828 100644
--- a/tvix/cli/src/refscan.rs
+++ b/tvix/glue/src/refscan.rs
diff --git a/tvix/cli/src/tvix_io.rs b/tvix/glue/src/tvix_io.rs
index 74f91138bff8..caadbeb5e663 100644
--- a/tvix/cli/src/tvix_io.rs
+++ b/tvix/glue/src/tvix_io.rs
@@ -8,15 +8,16 @@
 //! otherwise fundamental features like nixpkgs bootstrapping and hash
 //! calculation will not work.
 
-use crate::KnownPaths;
 use std::cell::RefCell;
 use std::io;
 use std::path::{Path, PathBuf};
 use std::rc::Rc;
 use tvix_eval::{EvalIO, FileType};
 
+use crate::known_paths::KnownPaths;
+
 // TODO: Merge this together with TvixStoreIO?
-pub(crate) struct TvixIO<T: EvalIO> {
+pub struct TvixIO<T: EvalIO> {
     /// Ingested paths must be reported to this known paths tracker
     /// for accurate build reference scanning.
     known_paths: Rc<RefCell<KnownPaths>>,
@@ -26,7 +27,7 @@ pub(crate) struct TvixIO<T: EvalIO> {
 }
 
 impl<T: EvalIO> TvixIO<T> {
-    pub(crate) fn new(known_paths: Rc<RefCell<KnownPaths>>, actual: T) -> Self {
+    pub fn new(known_paths: Rc<RefCell<KnownPaths>>, actual: T) -> Self {
         Self {
             known_paths,
             actual,
diff --git a/tvix/cli/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs
index 9be896ffc40f..9be896ffc40f 100644
--- a/tvix/cli/src/tvix_store_io.rs
+++ b/tvix/glue/src/tvix_store_io.rs