From 207f6fed46406ffb48270ac809fb93599def192a Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 26 Dec 2023 04:12:39 +0100 Subject: feat(tvix/eval): `match` DO NOT propagate context `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 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/builtins/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index deb0f84ccc..4cf9074fb8 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::>() .into(), )), -- cgit 1.4.1