about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2023-12-26T03·12+0100
committerclbot <clbot@tvl.fyi>2024-01-03T18·49+0000
commit207f6fed46406ffb48270ac809fb93599def192a (patch)
treed38e5384357c0a7384fa525f33a427e309a68155
parent09ec8b6fcf6ea5c04193c4539e4265a5c11a3386 (diff)
feat(tvix/eval): `match` DO NOT propagate context r/7332
`match` silently ignore the input context and do not propagate
it and successful matches.

The why is unclear but nixpkgs does rely implicitly on this behavior
because dynamic attribute selection cannot be done with contextful
strings.

Change-Id: I5167fa9b2c2db8ecab0c2fb3e9895c9cfce6eeb2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10441
Autosubmit: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r--tvix/eval/src/builtins/mod.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index deb0f84ccc9e..4cf9074fb8bf 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -3,7 +3,6 @@
 //! See //tvix/eval/docs/builtins.md for a some context on the
 //! available builtins in Nix.
 
-use crate::NixContext;
 use builtin_macros::builtins;
 use genawaiter::rc::Gen;
 use imbl::OrdMap;
@@ -23,8 +22,6 @@ use crate::{
     value::{CoercionKind, NixAttrs, NixList, NixString, Thunk, Value},
 };
 
-use crate::NixContextElement;
-
 use self::versions::{VersionPart, VersionPartsIter};
 
 mod to_xml;
@@ -79,7 +76,7 @@ pub async fn coerce_value_to_path(
 
 #[builtins]
 mod pure_builtins {
-    use crate::value::PointerEquality;
+    use crate::{value::PointerEquality, NixContext, NixContextElement};
 
     use super::*;
 
@@ -850,7 +847,7 @@ mod pure_builtins {
         if s.is_catchable() {
             return Ok(s);
         }
-        let s = s.to_str()?;
+        let s = s.to_contextful_str()?;
         let re = regex;
         if re.is_catchable() {
             return Ok(re);
@@ -861,7 +858,17 @@ mod pure_builtins {
             Some(caps) => Ok(Value::List(
                 caps.iter()
                     .skip(1)
-                    .map(|grp| grp.map(|g| Value::from(g.as_str())).unwrap_or(Value::Null))
+                    .map(|grp| {
+                        // Surprisingly, Nix does not propagate
+                        // the original context here.
+                        // Though, it accepts contextful strings as an argument.
+                        // An example of such behaviors in nixpkgs
+                        // can be observed in make-initrd.nix when it comes
+                        // to compressors which are matched over their full command
+                        // and then a compressor name will be extracted from that.
+                        grp.map(|g| Value::String(g.as_str().into()))
+                            .unwrap_or(Value::Null)
+                    })
                     .collect::<imbl::Vector<Value>>()
                     .into(),
             )),