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 <tvl@lahfa.xyz> Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
09ec8b6fcf
commit
207f6fed46
1 changed files with 13 additions and 6 deletions
|
@ -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(),
|
||||
)),
|
||||
|
|
Loading…
Reference in a new issue