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·47-0400
committergrfn <grfn@gws.fyi>2022-10-10T23·38+0000
commit9669fa8ff1abd64bdc4fc481e0dc976919c1dc56 (patch)
tree20bc26bc00226cc9316cce6c93a866a4c910b388 /tvix/eval/src/builtins/impure.rs
parent1f84d9081130eb55b911a2542ac4781ee1438fc4 (diff)
feat(tvix/eval): Implement builtins.readFile r/5095
Change-Id: If3fd0b087009a2bfbad8bb7aca0aa20de906eb12
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6921
Tested-by: BuildkiteCI
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/builtins/impure.rs')
-rw-r--r--tvix/eval/src/builtins/impure.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs
index 5cf3ca4287d8..c8423b6ac316 100644
--- a/tvix/eval/src/builtins/impure.rs
+++ b/tvix/eval/src/builtins/impure.rs
@@ -1,7 +1,8 @@
 use std::{
     cell::RefCell,
     collections::{BTreeMap, HashMap},
-    io,
+    fs::File,
+    io::{self, Read},
     rc::Rc,
     time::{SystemTime, UNIX_EPOCH},
 };
@@ -52,6 +53,11 @@ fn impure_builtins() -> Vec<Builtin> {
             }
             Ok(Value::attrs(NixAttrs::from_map(res)))
         }),
+        Builtin::new("readFile", &[true], |args: Vec<Value>, vm: &mut VM| {
+            let mut buf = String::new();
+            File::open(&super::coerce_value_to_path(&args[0], vm)?)?.read_to_string(&mut buf)?;
+            Ok(buf.into())
+        }),
     ]
 }