From 20c894e232ab75b3ad79d1e8a8b3c47ba1394af2 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 26 Dec 2023 01:30:05 +0100 Subject: feat(tvix/glue): context-aware `toFile` This removes the reference tracking and uses instead the context for references and returns some. Change-Id: Ic359ca6b903b63f1a9c679c566004c617b792442 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10435 Autosubmit: raitobezarius Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/glue/src/builtins/derivation.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'tvix/glue') diff --git a/tvix/glue/src/builtins/derivation.rs b/tvix/glue/src/builtins/derivation.rs index 57abe11b1912..95314f4b9dc9 100644 --- a/tvix/glue/src/builtins/derivation.rs +++ b/tvix/glue/src/builtins/derivation.rs @@ -464,30 +464,23 @@ pub(crate) mod derivation_builtins { .to_str() .context("evaluating the `name` parameter of builtins.toFile")?; let content = content - .to_str() + .to_contextful_str() .context("evaluating the `content` parameter of builtins.toFile")?; - let mut refscan = state.borrow().reference_scanner(); - refscan.scan(content.as_str()); - let refs = { - let paths = state.borrow(); - refscan - .finalise() - .into_iter() - .map(|path| paths[&path].path.to_string()) - .collect::>() - }; - - // TODO: fail on derivation references (only "plain" is allowed here) + if content.iter_derivation().count() > 0 || content.iter_single_outputs().count() > 0 { + return Err(ErrorKind::UnexpectedContext); + } - let path = nix_compat::store_path::build_text_path(name.as_str(), content.as_str(), refs) - .map_err(|_e| { - nix_compat::derivation::DerivationError::InvalidOutputName( - name.as_str().to_string(), - ) - }) - .map_err(DerivationError::InvalidDerivation)? - .to_absolute_path(); + let path = nix_compat::store_path::build_text_path( + name.as_str(), + content.as_str(), + content.iter_plain(), + ) + .map_err(|_e| { + nix_compat::derivation::DerivationError::InvalidOutputName(name.as_str().to_string()) + }) + .map_err(DerivationError::InvalidDerivation)? + .to_absolute_path(); state.borrow_mut().plain(&path); -- cgit 1.4.1