diff options
author | Griffin Smith <root@gws.fyi> | 2022-10-10T04·47-0400 |
---|---|---|
committer | grfn <grfn@gws.fyi> | 2022-10-10T23·38+0000 |
commit | 90ec632fd11a8767954f064a9344af8830d9fdc6 (patch) | |
tree | a7df1fd3765ab564966da915954571aa33469c38 /tvix/eval/src/builtins/impure.rs | |
parent | 9669fa8ff1abd64bdc4fc481e0dc976919c1dc56 (diff) |
feat(tvix/eval): Implement builtins.getEnv r/5096
Change-Id: I09f512a60989a37184e73e521d4a3aa23f33a1a8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6922 Autosubmit: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI Reviewed-by: Adam Joseph <adam@westernsemico.com> Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'tvix/eval/src/builtins/impure.rs')
-rw-r--r-- | tvix/eval/src/builtins/impure.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index c8423b6ac316..2315904f143b 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -1,6 +1,7 @@ use std::{ cell::RefCell, collections::{BTreeMap, HashMap}, + env, fs::File, io::{self, Read}, rc::Rc, @@ -10,13 +11,18 @@ use std::{ use crate::{ errors::ErrorKind, observer::NoOpObserver, - value::{Builtin, NixAttrs, NixString, Thunk}, + value::{Builtin, CoercionKind, NixAttrs, NixString, Thunk}, vm::VM, SourceCode, Value, }; fn impure_builtins() -> Vec<Builtin> { vec![ + Builtin::new("getEnv", &[true], |args: Vec<Value>, vm: &mut VM| { + Ok(env::var(args[0].coerce_to_string(CoercionKind::Weak, vm)?) + .unwrap_or_else(|_| "".into()) + .into()) + }), Builtin::new("pathExists", &[true], |args: Vec<Value>, vm: &mut VM| { Ok(super::coerce_value_to_path(&args[0], vm)?.exists().into()) }), |