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/impure.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs
index 41e3805b2d0e..7073deaaa7ac 100644
--- a/tvix/eval/src/builtins/impure.rs
+++ b/tvix/eval/src/builtins/impure.rs
@@ -3,8 +3,6 @@ use std::{
     time::{SystemTime, UNIX_EPOCH},
 };
 
-use smol_str::SmolStr;
-
 use crate::{
     value::{Builtin, NixString},
     Value,
@@ -22,5 +20,17 @@ pub(super) fn builtins() -> BTreeMap<NixString, Value> {
         .map(|b| (b.name().into(), Value::Builtin(b)))
         .collect();
 
+    // currentTime pins the time at which evaluation was started
+    {
+        let seconds = match SystemTime::now().duration_since(UNIX_EPOCH) {
+            Ok(dur) => dur.as_secs() as i64,
+
+            // This case is hit if the system time is *before* epoch.
+            Err(err) => -(err.duration().as_secs() as i64),
+        };
+
+        map.insert(NixString::from("currentTime"), Value::Integer(seconds));
+    }
+
     map
 }