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 <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									07e03498f2
								
							
						
					
					
						commit
						2478a6c5ba
					
				
					 2 changed files with 2 additions and 13 deletions
				
			
		|  | @ -52,18 +52,7 @@ pub fn builtins_import( | |||
|         "import", | ||||
|         &[true], | ||||
|         move |mut args: Vec<Value>, 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 { | ||||
|  |  | |||
|  | @ -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() | ||||
|                 ) | ||||
|             } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue