From f22b9cb0d7ba4dbab614de0d4331bbe896f23d60 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 23 Jan 2023 16:18:23 +0300 Subject: feat(tvix/cli): faux implementation of builtins.toFile 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 --- tvix/cli/src/derivation.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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>, + _: &mut VM, + name: Value, + content: Value, + ) -> Result { + 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; -- cgit 1.4.1