about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/Cargo.toml7
-rw-r--r--tvix/eval/src/builtins/mod.rs7
-rw-r--r--tvix/eval/src/errors.rs15
-rw-r--r--tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.exp (renamed from tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.exp)0
-rw-r--r--tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.nix (renamed from tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.nix)0
5 files changed, 26 insertions, 3 deletions
diff --git a/tvix/eval/Cargo.toml b/tvix/eval/Cargo.toml
index d47ad8c39737..cf46d4bbd464 100644
--- a/tvix/eval/Cargo.toml
+++ b/tvix/eval/Cargo.toml
@@ -27,6 +27,7 @@ serde_json = "1.0"
 smol_str = "0.1"
 tabwriter = "1.2"
 test-strategy = { version = "0.2.1", optional = true }
+toml = "0.6.0"
 xml-rs = "0.8.4"
 
 [dev-dependencies]
@@ -42,7 +43,7 @@ git = "https://github.com/JamesGuthrie/test-generator.git"
 rev = "82e799979980962aec1aa324ec6e0e4cad781f41"
 
 [features]
-default = [ "impure", "arbitrary", "nix_tests", "backtrace_overflow" ]
+default = ["impure", "arbitrary", "nix_tests", "backtrace_overflow"]
 
 # Enables running the Nix language test suite from the original C++
 # Nix implementation (at version 2.3) against Tvix.
@@ -52,10 +53,10 @@ nix_tests = []
 impure = []
 
 # Enables Arbitrary impls for internal types (required to run tests)
-arbitrary = [ "proptest", "test-strategy", "imbl/proptest" ]
+arbitrary = ["proptest", "test-strategy", "imbl/proptest"]
 
 # For debugging use only; not appropriate for production use.
-backtrace_overflow = [ "backtrace-on-stack-overflow" ]
+backtrace_overflow = ["backtrace-on-stack-overflow"]
 
 [[bench]]
 name = "eval"
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index b1ea408a8ca4..4f3c93ec1451 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -355,6 +355,13 @@ mod pure_builtins {
         Ok(json_str.into())
     }
 
+    #[builtin("fromTOML")]
+    fn builtin_from_toml(_: &mut VM, toml: Value) -> Result<Value, ErrorKind> {
+        let toml_str = toml.to_str()?;
+
+        toml::from_str(&toml_str).map_err(|err| err.into())
+    }
+
     #[builtin("genericClosure")]
     fn builtin_generic_closure(vm: &mut VM, input: Value) -> Result<Value, ErrorKind> {
         let attrs = input.to_attrs()?;
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index ccc2d8976440..8c0d6124201e 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -134,6 +134,9 @@ pub enum ErrorKind {
     /// Errors converting JSON to a value
     FromJsonError(String),
 
+    /// Errors converting TOML to a value
+    FromTomlError(String),
+
     /// An unexpected argument was supplied to a function that takes formal parameters
     UnexpectedArgument {
         arg: NixString,
@@ -246,6 +249,12 @@ impl From<serde_json::Error> for ErrorKind {
     }
 }
 
+impl From<toml::de::Error> for ErrorKind {
+    fn from(err: toml::de::Error) -> Self {
+        Self::FromTomlError(format!("error in TOML serialization: {err}"))
+    }
+}
+
 #[derive(Clone, Debug)]
 pub struct Error {
     kind: ErrorKind,
@@ -434,6 +443,10 @@ to a missing value in the attribute set(s) included via `with`."#,
                 write!(f, "Error converting JSON to a Nix value: {msg}")
             }
 
+            ErrorKind::FromTomlError(msg) => {
+                write!(f, "Error converting TOML to a Nix value: {msg}")
+            }
+
             ErrorKind::UnexpectedArgument { arg, .. } => {
                 write!(
                     f,
@@ -749,6 +762,7 @@ impl Error {
             | ErrorKind::ImportCompilerError { .. }
             | ErrorKind::IO { .. }
             | ErrorKind::FromJsonError(_)
+            | ErrorKind::FromTomlError(_)
             | ErrorKind::Xml(_)
             | ErrorKind::TvixError(_)
             | ErrorKind::TvixBug { .. }
@@ -795,6 +809,7 @@ impl Error {
             ErrorKind::RelativePathResolution(_) => "E032",
             ErrorKind::DivisionByZero => "E033",
             ErrorKind::Xml(_) => "E034",
+            ErrorKind::FromTomlError(_) => "E035",
 
             // Special error code for errors from other Tvix
             // components. We may want to introduce a code namespacing
diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.exp b/tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.exp
index d0dd3af2c814..d0dd3af2c814 100644
--- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.exp
+++ b/tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.exp
diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.nix b/tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.nix
index 963932689942..963932689942 100644
--- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromTOML.nix
+++ b/tvix/eval/src/tests/nix_tests/eval-okay-fromTOML.nix