about summary refs log tree commit diff
path: root/tvix/serde/src
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/serde/src')
-rw-r--r--tvix/serde/src/de.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/tvix/serde/src/de.rs b/tvix/serde/src/de.rs
index 43efc71c6f67..49a069a51588 100644
--- a/tvix/serde/src/de.rs
+++ b/tvix/serde/src/de.rs
@@ -2,6 +2,7 @@
 
 use serde::de::value::{MapDeserializer, SeqDeserializer};
 use serde::de::{self, EnumAccess, VariantAccess};
+pub use tvix_eval::Evaluation;
 use tvix_eval::Value;
 
 use crate::error::Error;
@@ -28,12 +29,26 @@ impl de::IntoDeserializer<'_, Error> for NixDeserializer {
     }
 }
 
+/// Evaluate the Nix code in `src` and attempt to deserialise the
+/// value it returns to `T`.
 pub fn from_str<'code, T>(src: &'code str) -> Result<T, Error>
 where
     T: serde::Deserialize<'code>,
 {
+    from_str_with_config(src, |_| /* no extra config */ ())
+}
+
+/// Evaluate the Nix code in `src`, with extra configuration for the
+/// `tvix_eval::Evaluation` provided by the given closure.
+pub fn from_str_with_config<'code, T, F>(src: &'code str, config: F) -> Result<T, Error>
+where
+    T: serde::Deserialize<'code>,
+    F: FnOnce(&mut Evaluation),
+{
     // First step is to evaluate the Nix code ...
-    let mut eval = tvix_eval::Evaluation::new(src, None);
+    let mut eval = Evaluation::new(src, None);
+    config(&mut eval);
+
     eval.strict = true;
     let source = eval.source_map();
     let result = eval.evaluate();