about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2023-12-26T00·30+0100
committerclbot <clbot@tvl.fyi>2024-01-03T19·43+0000
commit20c894e232ab75b3ad79d1e8a8b3c47ba1394af2 (patch)
tree5dc363023d7a306d0eb16e102d1f7b9a030789d0 /tvix
parentcc098b9aaa2dc033d3decf53cdfbd20a8ac22689 (diff)
feat(tvix/glue): context-aware `toFile` r/7336
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 <tvl@lahfa.xyz>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/errors.rs9
-rw-r--r--tvix/glue/src/builtins/derivation.rs35
2 files changed, 23 insertions, 21 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs
index 6ac29492dfc3..4ba93a0aaba3 100644
--- a/tvix/eval/src/errors.rs
+++ b/tvix/eval/src/errors.rs
@@ -202,6 +202,9 @@ pub enum ErrorKind {
         context: String,
         underlying: Box<ErrorKind>,
     },
+
+    /// Unexpected context string
+    UnexpectedContext,
 }
 
 impl error::Error for Error {
@@ -484,6 +487,10 @@ to a missing value in the attribute set(s) included via `with`."#,
             ErrorKind::WithContext { .. } => {
                 panic!("internal ErrorKind::WithContext variant leaked")
             }
+
+            ErrorKind::UnexpectedContext => {
+                write!(f, "unexpected context string")
+            }
         }
     }
 }
@@ -736,6 +743,7 @@ impl Error {
             ErrorKind::InvalidAttributeName(_) => "in this attribute set",
             ErrorKind::RelativePathResolution(_) => "in this path literal",
             ErrorKind::UnexpectedArgument { .. } => "in this function call",
+            ErrorKind::UnexpectedContext => "in this string",
 
             // The spans for some errors don't have any more descriptive stuff
             // in them, or we don't utilise it yet.
@@ -810,6 +818,7 @@ impl Error {
             ErrorKind::Xml(_) => "E034",
             ErrorKind::FromTomlError(_) => "E035",
             ErrorKind::NotSerialisableToJson(_) => "E036",
+            ErrorKind::UnexpectedContext => "E037",
 
             // Special error code for errors from other Tvix
             // components. We may want to introduce a code namespacing
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::<Vec<_>>()
-        };
-
-        // 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);