about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/builtins/impure.rs12
-rw-r--r--tvix/eval/src/io.rs6
2 files changed, 17 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs
index 01a09393720d..904706dc65d9 100644
--- a/tvix/eval/src/builtins/impure.rs
+++ b/tvix/eval/src/builtins/impure.rs
@@ -4,7 +4,7 @@ use smol_str::SmolStr;
 use std::{
     collections::BTreeMap,
     env,
-    rc::Weak,
+    rc::{Rc, Weak},
     time::{SystemTime, UNIX_EPOCH},
 };
 
@@ -74,6 +74,16 @@ pub(super) fn builtins() -> BTreeMap<&'static str, Value> {
         .map(|b| (b.name(), Value::Builtin(b)))
         .collect();
 
+    map.insert(
+        "storeDir",
+        Value::Thunk(Thunk::new_suspended_native(Rc::new(Box::new(
+            |vm: &mut VM| match vm.io().store_dir() {
+                None => Ok(Value::Null),
+                Some(dir) => Ok(Value::String(dir.into())),
+            },
+        )))),
+    );
+
     // currentTime pins the time at which evaluation was started
     {
         let seconds = match SystemTime::now().duration_since(UNIX_EPOCH) {
diff --git a/tvix/eval/src/io.rs b/tvix/eval/src/io.rs
index 3215e5a7ddb7..4e7404ef9c53 100644
--- a/tvix/eval/src/io.rs
+++ b/tvix/eval/src/io.rs
@@ -41,6 +41,12 @@ pub trait EvalIO {
     /// Read the directory at the specified path and return the names
     /// of its entries associated with their [`FileType`].
     fn read_dir(&self, path: PathBuf) -> Result<Vec<(SmolStr, FileType)>, ErrorKind>;
+
+    /// Returns the root of the store directory, if such a thing
+    /// exists in the evaluation context.
+    fn store_dir(&self) -> Option<String> {
+        None
+    }
 }
 
 /// Implementation of [`EvalIO`] that simply uses the equivalent