about summary refs log tree commit diff
path: root/tvix/eval/src/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/builtins')
-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(),
             )),