diff options
Diffstat (limited to 'tvix/eval/src/builtins/impure.rs')
-rw-r--r-- | tvix/eval/src/builtins/impure.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index def6ce29094c..aad55c7331e8 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -21,7 +21,7 @@ mod impure_builtins { use std::os::unix::ffi::OsStrExt; use super::*; - use crate::builtins::coerce_value_to_path; + use crate::builtins::{coerce_value_to_path, hash::hash_nix_string}; #[builtin("getEnv")] async fn builtin_get_env(co: GenCo, var: Value) -> Result<Value, ErrorKind> { @@ -30,6 +30,17 @@ mod impure_builtins { .into()) } + #[builtin("hashFile")] + #[allow(non_snake_case)] + async fn builtin_hashFile(co: GenCo, algo: Value, path: Value) -> Result<Value, ErrorKind> { + let path = match coerce_value_to_path(&co, path).await? { + Err(cek) => return Ok(Value::from(cek)), + Ok(p) => p, + }; + let s = generators::request_read_to_string(&co, path).await; + hash_nix_string(algo.to_str()?, s.to_str()?).map(Value::from) + } + #[builtin("pathExists")] async fn builtin_path_exists(co: GenCo, path: Value) -> Result<Value, ErrorKind> { match coerce_value_to_path(&co, path).await? { |