diff options
author | Vincent Ambo <mail@tazj.in> | 2023-01-23T13·18+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-01-27T12·21+0000 |
commit | f22b9cb0d7ba4dbab614de0d4331bbe896f23d60 (patch) | |
tree | d409b4146d3ae96eaaa7e514495b1cd33296061e /tvix/cli/src/derivation.rs | |
parent | de10a924f2586461d0323cc74b179aa0e8b1d1c4 (diff) |
feat(tvix/cli): faux implementation of builtins.toFile r/5770
This adds an implementation of this builtin which correctly calculates paths, but does not actually write anything to the store or verify references. Change-Id: Ie9764cbc1d13a73d8dc9350910304e2b7cad3fe8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7910 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/cli/src/derivation.rs')
-rw-r--r-- | tvix/cli/src/derivation.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs index 260e27e5707e..d57503a696d4 100644 --- a/tvix/cli/src/derivation.rs +++ b/tvix/cli/src/derivation.rs @@ -333,6 +333,37 @@ mod derivation_builtins { new_attrs.into_iter(), )))) } + + #[builtin("toFile")] + fn builtin_to_file( + state: Rc<RefCell<KnownPaths>>, + _: &mut VM, + name: Value, + content: Value, + ) -> Result<Value, ErrorKind> { + let name = name + .to_str() + .context("evaluating the `name` parameter of builtins.toFile")?; + let content = content + .to_str() + .context("evaluating the `content` parameter of builtins.toFile")?; + + let mut refscan = state.borrow().reference_scanner(); + refscan.scan_str(content.as_str()); + let refs = refscan.finalise(); + + // TODO: fail on derivation references (only "plain" is allowed here) + + let path = tvix_derivation::path_with_references(name.as_str(), content.as_str(), refs) + .map_err(Error::InvalidDerivation)? + .to_absolute_path(); + + state.borrow_mut().plain(&path); + + // TODO: actually persist the file in the store at that path ... + + Ok(Value::String(path.into())) + } } pub use derivation_builtins::builtins as derivation_builtins; |