about summary refs log tree commit diff
path: root/tvix/glue/src/builtins
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2023-12-13T13·52+0100
committerclbot <clbot@tvl.fyi>2023-12-14T13·15+0000
commit7165ebc43bfb1b53929fb31673c512bbbdbe4096 (patch)
tree99e818716faca25777ea15499ce670a506269bed /tvix/glue/src/builtins
parenta30dd0905a08a78bb0573136064dd334a0567f6a (diff)
fix(tvix/eval): remove incorrect imports when coercing r/7218
The default behavior of string coercion in C++ Nix is to weakly coerce
and import to store if necessary. There is a flag to make it strongly
coerce (coerceMore) and a flag that controls whether path values have
the corresponding file/directory imported into the store before
returning the (store) path as a string (copyToStore). We need to
implement our equivalent to the copyToStore (import_paths) flag for the
benefit of weak coercions that don't import into the store (dirOf,
baseNameOf, readFile, ...) and strong coercions that don't import into
the store (toString).

This makes coerce_to_string as well as CoercionKind weirder and more
versatile, but prevents us from reimplementing parts of the coercion
logic constantly as can be seen in the case of baseNameOf.

Note that it is not possible to test this properly in //tvix/eval tests
due to the lack of an appropriate EvalIO implementation being available.
Tests should be added to //tvix/glue down the line.

Change-Id: I8fb8ab99c7fe08e311d2ba1c36960746bf22f566
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10361
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: Adam Joseph <adam@westernsemico.com>
Diffstat (limited to 'tvix/glue/src/builtins')
-rw-r--r--tvix/glue/src/builtins/derivation.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/tvix/glue/src/builtins/derivation.rs b/tvix/glue/src/builtins/derivation.rs
index 6eedbc13e7e3..993e7612aed4 100644
--- a/tvix/glue/src/builtins/derivation.rs
+++ b/tvix/glue/src/builtins/derivation.rs
@@ -161,7 +161,7 @@ async fn handle_derivation_parameters(
         "args" => {
             let args = value.to_list()?;
             for arg in args {
-                match strong_coerce_to_string(co, arg).await? {
+                match strong_importing_coerce_to_string(co, arg).await? {
                     Err(cek) => return Ok(Err(cek)),
                     Ok(s) => drv.arguments.push(s),
                 }
@@ -194,12 +194,21 @@ async fn handle_derivation_parameters(
     Ok(Ok(true))
 }
 
-async fn strong_coerce_to_string(
+async fn strong_importing_coerce_to_string(
     co: &GenCo,
     val: Value,
 ) -> Result<Result<String, CatchableErrorKind>, ErrorKind> {
     let val = generators::request_force(co, val).await;
-    match generators::request_string_coerce(co, val, CoercionKind::Strong).await {
+    match generators::request_string_coerce(
+        co,
+        val,
+        CoercionKind {
+            strong: true,
+            import_paths: true,
+        },
+    )
+    .await
+    {
         Err(cek) => Ok(Err(cek)),
         Ok(val_str) => Ok(Ok(val_str.as_str().to_string())),
     }
@@ -268,7 +277,7 @@ pub(crate) mod derivation_builtins {
             key: &str,
         ) -> Result<Result<Option<String>, CatchableErrorKind>, ErrorKind> {
             if let Some(attr) = attrs.select(key) {
-                match strong_coerce_to_string(co, attr.clone()).await? {
+                match strong_importing_coerce_to_string(co, attr.clone()).await? {
                     Err(cek) => return Ok(Err(cek)),
                     Ok(str) => return Ok(Ok(Some(str))),
                 }
@@ -283,7 +292,7 @@ pub(crate) mod derivation_builtins {
                 continue;
             }
 
-            match strong_coerce_to_string(&co, value.clone()).await? {
+            match strong_importing_coerce_to_string(&co, value.clone()).await? {
                 Err(cek) => return Ok(Value::Catchable(cek)),
                 Ok(val_str) => {
                     // handle_derivation_parameters tells us whether the