fix(tvix/glue): produce context for builtins.(path|filterSource)
Fixes b/392. Output paths were created, depending on a plain store path but no context string was attached to track that plain dependency. Context string propagation tests are strengthened to prevent any regression on this. Change-Id: Ifd6671aeba6949324b0bb9f0f766b87db728d484 Signed-off-by: Ryan Lahfa <tvl@lahfa.xyz> Reviewed-on: https://cl.tvl.fyi/c/depot/+/11351 Reviewed-by: Alyssa Ross <hi@alyssa.is> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
3821fd4224
commit
e9a23bb478
3 changed files with 24 additions and 5 deletions
|
|
@ -123,6 +123,7 @@ mod import_builtins {
|
||||||
use nix_compat::nixhash::{CAHash, NixHash};
|
use nix_compat::nixhash::{CAHash, NixHash};
|
||||||
use tvix_eval::generators::Gen;
|
use tvix_eval::generators::Gen;
|
||||||
use tvix_eval::{generators::GenCo, ErrorKind, Value};
|
use tvix_eval::{generators::GenCo, ErrorKind, Value};
|
||||||
|
use tvix_eval::{NixContextElement, NixString};
|
||||||
|
|
||||||
use tvix_castore::B3Digest;
|
use tvix_castore::B3Digest;
|
||||||
|
|
||||||
|
|
@ -242,7 +243,13 @@ mod import_builtins {
|
||||||
Ok::<_, std::io::Error>(state.path_info_service.as_ref().put(path_info).await?)
|
Ok::<_, std::io::Error>(state.path_info_service.as_ref().put(path_info).await?)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(output_path.to_absolute_path().into())
|
// We need to attach context to the final output path.
|
||||||
|
let outpath = output_path.to_absolute_path();
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
NixString::new_context_from(NixContextElement::Plain(outpath.clone()).into(), outpath)
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[builtin("filterSource")]
|
#[builtin("filterSource")]
|
||||||
|
|
@ -256,7 +263,7 @@ mod import_builtins {
|
||||||
let root_node = filtered_ingest(Rc::clone(&state), co, &p, Some(&filter)).await?;
|
let root_node = filtered_ingest(Rc::clone(&state), co, &p, Some(&filter)).await?;
|
||||||
let name = tvix_store::import::path_to_name(&p)?;
|
let name = tvix_store::import::path_to_name(&p)?;
|
||||||
|
|
||||||
Ok(state
|
let outpath = state
|
||||||
.tokio_handle
|
.tokio_handle
|
||||||
.block_on(async {
|
.block_on(async {
|
||||||
let (_, nar_sha256) = state
|
let (_, nar_sha256) = state
|
||||||
|
|
@ -278,8 +285,12 @@ mod import_builtins {
|
||||||
path: Some(p.to_path_buf()),
|
path: Some(p.to_path_buf()),
|
||||||
error: err.into(),
|
error: err.into(),
|
||||||
})?
|
})?
|
||||||
.to_absolute_path()
|
.to_absolute_path();
|
||||||
.into())
|
|
||||||
|
Ok(
|
||||||
|
NixString::new_context_from(NixContextElement::Plain(outpath.clone()).into(), outpath)
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
[ true true true true true true true true true true true true true true true true true true true true true true true true true true ]
|
[ true true true true true true true true true true true true true true true true true true true true true true true true true true true true ]
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
outputs = [ "out" "bar" ];
|
outputs = [ "out" "bar" ];
|
||||||
};
|
};
|
||||||
|
a-path-drv = builtins.path {
|
||||||
|
name = "a-path-drv";
|
||||||
|
path = ./eval-okay-context-introspection.nix;
|
||||||
|
};
|
||||||
|
another-path-drv = builtins.filterSource (_: true) ./eval-okay-context-introspection.nix;
|
||||||
|
|
||||||
# `substr` propagates context, we truncate to an empty string and concatenate to the target
|
# `substr` propagates context, we truncate to an empty string and concatenate to the target
|
||||||
# to infect it with the context of `copied`.
|
# to infect it with the context of `copied`.
|
||||||
|
|
@ -37,6 +42,9 @@ in
|
||||||
(builtins.hasContext "${(builtins.toFile "myself" "${./eval-okay-context-introspection.nix}")}")
|
(builtins.hasContext "${(builtins.toFile "myself" "${./eval-okay-context-introspection.nix}")}")
|
||||||
# `derivation` should produce context.
|
# `derivation` should produce context.
|
||||||
(builtins.hasContext "${drv}")
|
(builtins.hasContext "${drv}")
|
||||||
|
# `builtins.path` / `builtins.filterSource` should produce context.
|
||||||
|
(builtins.hasContext "${a-path-drv}")
|
||||||
|
(builtins.hasContext "${another-path-drv}")
|
||||||
# Low-level test to ensure that interpolation is working as expected.
|
# Low-level test to ensure that interpolation is working as expected.
|
||||||
(builtins.length (builtins.attrNames (builtins.getContext "${drv}${other-drv}")) == 2)
|
(builtins.length (builtins.attrNames (builtins.getContext "${drv}${other-drv}")) == 2)
|
||||||
(builtins.getContext "${drv}${other-drv}" == mergeContext drv other-drv)
|
(builtins.getContext "${drv}${other-drv}" == mergeContext drv other-drv)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue