about summary refs log tree commit diff
path: root/tvix/glue
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/glue')
-rw-r--r--tvix/glue/benches/eval.rs7
-rw-r--r--tvix/glue/src/builtins/fetchers.rs42
-rw-r--r--tvix/glue/src/builtins/mod.rs18
-rw-r--r--tvix/glue/src/tests/mod.rs6
-rw-r--r--tvix/glue/src/tvix_store_io.rs3
5 files changed, 69 insertions, 7 deletions
diff --git a/tvix/glue/benches/eval.rs b/tvix/glue/benches/eval.rs
index 4e1886c4018e..11435707aca6 100644
--- a/tvix/glue/benches/eval.rs
+++ b/tvix/glue/benches/eval.rs
@@ -8,7 +8,9 @@ use tvix_castore::{
 };
 use tvix_eval::{builtins::impure_builtins, EvalIO};
 use tvix_glue::{
-    builtins::add_derivation_builtins, configure_nix_path, tvix_io::TvixIO,
+    builtins::{add_derivation_builtins, add_fetcher_builtins},
+    configure_nix_path,
+    tvix_io::TvixIO,
     tvix_store_io::TvixStoreIO,
 };
 use tvix_store::pathinfoservice::{MemoryPathInfoService, PathInfoService};
@@ -44,7 +46,8 @@ fn interpret(code: &str) {
     );
 
     eval.builtins.extend(impure_builtins());
-    add_derivation_builtins(&mut eval, tvix_store_io);
+    add_derivation_builtins(&mut eval, Rc::clone(&tvix_store_io));
+    add_fetcher_builtins(&mut eval, tvix_store_io);
     configure_nix_path(
         &mut eval,
         // The benchmark requires TVIX_BENCH_NIX_PATH to be set, so barf out
diff --git a/tvix/glue/src/builtins/fetchers.rs b/tvix/glue/src/builtins/fetchers.rs
new file mode 100644
index 000000000000..7a5d49a725d1
--- /dev/null
+++ b/tvix/glue/src/builtins/fetchers.rs
@@ -0,0 +1,42 @@
+//! Contains builtins that fetch paths from the Internet
+
+use crate::tvix_store_io::TvixStoreIO;
+use std::rc::Rc;
+use tvix_eval::builtin_macros::builtins;
+use tvix_eval::Value;
+
+#[allow(unused_variables)] // for the `state` arg, for now
+#[builtins(state = "Rc<TvixStoreIO>")]
+pub(crate) mod fetcher_builtins {
+    use super::*;
+
+    use tvix_eval::generators::Gen;
+    use tvix_eval::{generators::GenCo, ErrorKind};
+
+    #[builtin("fetchurl")]
+    async fn builtin_fetchurl(
+        state: Rc<TvixStoreIO>,
+        co: GenCo,
+        url: Value,
+    ) -> Result<Value, ErrorKind> {
+        Err(ErrorKind::NotImplemented("fetchurl"))
+    }
+
+    #[builtin("fetchTarball")]
+    async fn builtin_fetch_tarball(
+        state: Rc<TvixStoreIO>,
+        co: GenCo,
+        args: Value,
+    ) -> Result<Value, ErrorKind> {
+        Err(ErrorKind::NotImplemented("fetchTarball"))
+    }
+
+    #[builtin("fetchGit")]
+    async fn builtin_fetch_git(
+        state: Rc<TvixStoreIO>,
+        co: GenCo,
+        args: Value,
+    ) -> Result<Value, ErrorKind> {
+        Err(ErrorKind::NotImplemented("fetchGit"))
+    }
+}
diff --git a/tvix/glue/src/builtins/mod.rs b/tvix/glue/src/builtins/mod.rs
index dff6a8947c16..4a59ec9ea6e5 100644
--- a/tvix/glue/src/builtins/mod.rs
+++ b/tvix/glue/src/builtins/mod.rs
@@ -6,6 +6,7 @@ use crate::tvix_store_io::TvixStoreIO;
 
 mod derivation;
 mod derivation_error;
+mod fetchers;
 
 pub use derivation_error::Error as DerivationError;
 
@@ -17,20 +18,30 @@ pub use derivation_error::Error as DerivationError;
 /// `known_paths`.
 pub fn add_derivation_builtins<IO>(eval: &mut tvix_eval::Evaluation<IO>, io: Rc<TvixStoreIO>) {
     eval.builtins
-        .extend(derivation::derivation_builtins::builtins(io));
+        .extend(derivation::derivation_builtins::builtins(Rc::clone(&io)));
 
     // Add the actual `builtins.derivation` from compiled Nix code
     eval.src_builtins
         .push(("derivation", include_str!("derivation.nix")));
 }
 
+/// Adds fetcher builtins to the passed [tvix_eval::Evaluation]:
+///
+/// * `fetchurl`
+/// * `fetchTarball`
+/// * `fetchGit`
+pub fn add_fetcher_builtins<IO>(eval: &mut tvix_eval::Evaluation<IO>, io: Rc<TvixStoreIO>) {
+    eval.builtins
+        .extend(fetchers::fetcher_builtins::builtins(Rc::clone(&io)));
+}
+
 #[cfg(test)]
 mod tests {
     use std::{rc::Rc, sync::Arc};
 
     use crate::tvix_store_io::TvixStoreIO;
 
-    use super::add_derivation_builtins;
+    use super::{add_derivation_builtins, add_fetcher_builtins};
     use nix_compat::store_path::hash_placeholder;
     use test_case::test_case;
     use tvix_build::buildservice::DummyBuildService;
@@ -57,7 +68,8 @@ mod tests {
 
         let mut eval = tvix_eval::Evaluation::new(io.clone() as Rc<dyn EvalIO>, false);
 
-        add_derivation_builtins(&mut eval, io);
+        add_derivation_builtins(&mut eval, Rc::clone(&io));
+        add_fetcher_builtins(&mut eval, io);
 
         // run the evaluation itself.
         eval.evaluate(str, None)
diff --git a/tvix/glue/src/tests/mod.rs b/tvix/glue/src/tests/mod.rs
index ddc139158049..ad6571e4d212 100644
--- a/tvix/glue/src/tests/mod.rs
+++ b/tvix/glue/src/tests/mod.rs
@@ -12,7 +12,10 @@ use tvix_store::pathinfoservice::{MemoryPathInfoService, PathInfoService};
 
 use rstest::rstest;
 
-use crate::{builtins::add_derivation_builtins, tvix_store_io::TvixStoreIO};
+use crate::{
+    builtins::{add_derivation_builtins, add_fetcher_builtins},
+    tvix_store_io::TvixStoreIO,
+};
 
 fn eval_test(code_path: PathBuf, expect_success: bool) {
     assert_eq!(
@@ -51,6 +54,7 @@ fn eval_test(code_path: PathBuf, expect_success: bool) {
 
     eval.strict = true;
     add_derivation_builtins(&mut eval, tvix_store_io.clone());
+    add_fetcher_builtins(&mut eval, tvix_store_io);
 
     let result = eval.evaluate(code, Some(code_path.clone()));
     let failed = match result.value {
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs
index a64e2d4c7bf0..025a8a4bf01c 100644
--- a/tvix/glue/src/tvix_store_io.rs
+++ b/tvix/glue/src/tvix_store_io.rs
@@ -475,7 +475,7 @@ mod tests {
     use tvix_eval::{EvalIO, EvaluationResult};
     use tvix_store::pathinfoservice::MemoryPathInfoService;
 
-    use crate::builtins::add_derivation_builtins;
+    use crate::builtins::{add_derivation_builtins, add_fetcher_builtins};
 
     use super::TvixStoreIO;
 
@@ -503,6 +503,7 @@ mod tests {
         let mut eval = tvix_eval::Evaluation::new(io.clone() as Rc<dyn EvalIO>, true);
 
         add_derivation_builtins(&mut eval, io.clone());
+        add_fetcher_builtins(&mut eval, io.clone());
 
         // run the evaluation itself.
         eval.evaluate(str, None)