From 2478a6c5bac5d72f5a7a08709c84e471a1f3c763 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 4 Oct 2022 23:21:49 +0300 Subject: feat(tvix/eval): coerce values to paths when importing This enables the use of string paths (and, in the future, derivations), as long as their string values represent an absolute path. Change-Id: I4b198efeb70415ed52f58bd1da6fa79a24dad14c Reviewed-on: https://cl.tvl.fyi/c/depot/+/6866 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/builtins/impure.rs | 13 +------------ tvix/eval/src/errors.rs | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index d73e5ccfa8..348963e893 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -52,18 +52,7 @@ pub fn builtins_import( "import", &[true], move |mut args: Vec, vm: &mut VM| { - let path = match args.pop().unwrap() { - Value::Path(path) => path, - Value::String(_) => { - return Err(ErrorKind::NotImplemented("importing from string-paths")) - } - other => { - return Err(ErrorKind::TypeError { - expected: "path or string", - actual: other.type_of(), - }) - } - }; + let path = super::coerce_value_to_path(&args.pop().unwrap(), vm)?; let contents = std::fs::read_to_string(&path).map_err(|err| ErrorKind::ReadFileError { diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index b374696171..50b1e9e31c 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -262,7 +262,7 @@ to a missing value in the attribute set(s) included via `with`."#, ErrorKind::NotAnAbsolutePath(given) => { format!( - "string {} doesn't represent an absolute path", + "string '{}' does not represent an absolute path", given.to_string_lossy() ) } -- cgit 1.4.1