feat(tvix/eval): Implement builtins.getEnv

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>
This commit is contained in:
Griffin Smith 2022-10-10 00:47:45 -04:00 committed by grfn
parent 9669fa8ff1
commit 90ec632fd1

View file

@ -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())
}),