about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/builtins/mod.rs35
-rw-r--r--tvix/eval/src/tests/mod.rs39
2 files changed, 38 insertions, 36 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index dcc158d10189..7fd66d5afc75 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -945,7 +945,7 @@ mod pure_builtins {
     }
 }
 
-fn builtin_tuple(builtin: Builtin) -> (&'static str, Value) {
+pub(crate) fn builtin_tuple(builtin: Builtin) -> (&'static str, Value) {
     (builtin.name(), Value::Builtin(builtin))
 }
 
@@ -1036,39 +1036,6 @@ pub fn placeholders() -> Vec<(&'static str, Value)> {
                 Ok(Value::attrs(NixAttrs::from_iter(res.into_iter())))
             },
         ),
-        Builtin::new(
-            "derivation",
-            &[BuiltinArgument {
-                strict: true,
-                name: "attrs",
-            }],
-            None,
-            |args: Vec<Value>, vm: &mut VM| {
-                vm.emit_warning(WarningKind::NotImplemented("builtins.derivation"));
-
-                // We do not implement derivations yet, so this function sets mock
-                // values on the fields that a real derivation would contain.
-                //
-                // Crucially this means we do not yet *validate* the values either.
-                let input = args[0].to_attrs()?;
-                let attrs = input.update(NixAttrs::from_iter(
-                    [
-                        (
-                            "outPath",
-                            "/nix/store/00000000000000000000000000000000-mock",
-                        ),
-                        (
-                            "drvPath",
-                            "/nix/store/00000000000000000000000000000000-mock.drv",
-                        ),
-                        ("type", "derivation"),
-                    ]
-                    .into_iter(),
-                ));
-
-                Ok(Value::Attrs(Box::new(attrs)))
-            },
-        ),
     ];
 
     ph.into_iter().map(builtin_tuple).collect()
diff --git a/tvix/eval/src/tests/mod.rs b/tvix/eval/src/tests/mod.rs
index 9692d50bf11b..9bf9ef353c49 100644
--- a/tvix/eval/src/tests/mod.rs
+++ b/tvix/eval/src/tests/mod.rs
@@ -1,7 +1,37 @@
+use builtin_macros::builtins;
 use pretty_assertions::assert_eq;
-
 use test_generator::test_resources;
 
+#[builtins]
+mod mock_builtins {
+    //! Builtins which are required by language tests, but should not
+    //! actually exist in //tvix/eval.
+    use crate::*;
+
+    #[builtin("derivation")]
+    fn builtin_type_of(vm: &mut VM, input: Value) -> Result<Value, ErrorKind> {
+        vm.emit_warning(WarningKind::NotImplemented("builtins.derivation"));
+
+        let input = input.to_attrs()?;
+        let attrs = input.update(NixAttrs::from_iter(
+            [
+                (
+                    "outPath",
+                    "/nix/store/00000000000000000000000000000000-mock",
+                ),
+                (
+                    "drvPath",
+                    "/nix/store/00000000000000000000000000000000-mock.drv",
+                ),
+                ("type", "derivation"),
+            ]
+            .into_iter(),
+        ));
+
+        Ok(Value::Attrs(Box::new(attrs)))
+    }
+}
+
 fn eval_test(code_path: &str, expect_success: bool) {
     let base = code_path
         .strip_suffix("nix")
@@ -17,7 +47,12 @@ fn eval_test(code_path: &str, expect_success: bool) {
         return;
     }
 
-    let eval = crate::Evaluation::new_impure(&code, Some(code_path.into()));
+    let mut eval = crate::Evaluation::new_impure(&code, Some(code_path.into()));
+    eval.builtins.extend(
+        mock_builtins::builtins()
+            .into_iter()
+            .map(crate::builtins::builtin_tuple),
+    );
 
     let result = eval.evaluate();