about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/impure.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-10-10T04·03-0400
committergrfn <grfn@gws.fyi>2022-10-10T20·23+0000
commit0b8a967acac26b527ebedfff6658117f63f7c861 (patch)
tree30d3e9c514e954fed1cfeb0f4105a20264c9dae9 /tvix/eval/src/builtins/impure.rs
parent273ba73754e9b10f768830d5a6835bf3d14e0d8a (diff)
feat(tvix/eval): Implement builtins.pathExists r/5088
Change-Id: Ife8a690e9036868964771893ab29a9ae3a2d2365
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6919
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/impure.rs')
-rw-r--r--tvix/eval/src/builtins/impure.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs
index 32653b665c36..5cf3ca4287d8 100644
--- a/tvix/eval/src/builtins/impure.rs
+++ b/tvix/eval/src/builtins/impure.rs
@@ -15,10 +15,11 @@ use crate::{
 };
 
 fn impure_builtins() -> Vec<Builtin> {
-    vec![Builtin::new(
-        "readDir",
-        &[true],
-        |args: Vec<Value>, vm: &mut VM| {
+    vec![
+        Builtin::new("pathExists", &[true], |args: Vec<Value>, vm: &mut VM| {
+            Ok(super::coerce_value_to_path(&args[0], vm)?.exists().into())
+        }),
+        Builtin::new("readDir", &[true], |args: Vec<Value>, vm: &mut VM| {
             let path = super::coerce_value_to_path(&args[0], vm)?;
             let mk_err = |err: io::Error| ErrorKind::IO {
                 path: Some(path.clone()),
@@ -50,8 +51,8 @@ fn impure_builtins() -> Vec<Builtin> {
                 );
             }
             Ok(Value::attrs(NixAttrs::from_map(res)))
-        },
-    )]
+        }),
+    ]
 }
 
 /// Return all impure builtins, that is all builtins which may perform I/O