fix(tvix/glue/derivation): fix __structuredAttrs "outputs" handling

In case structured attrs is enabled, rather than adding a
space-separated list to the "outputs" environment variable, a "proper"
list is added to the JSON itself, at the "outputs" key.

Fixes b/395.

Reported-By: Alyssa Ross <hi@alyssa.is>
Change-Id: I2834ede9cfcf49d5e81e1056bf8f9bb9b65ddad8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11386
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
This commit is contained in:
Florian Klink 2024-04-09 00:30:12 +03:00 committed by clbot
parent f1496f5722
commit 84ad8a0bbd
2 changed files with 12 additions and 3 deletions

View file

@ -316,8 +316,16 @@ pub(crate) mod derivation_builtins {
output_names.push(output_name.to_str()?.to_owned());
}
// Add drv.environment[outputs] unconditionally.
insert_env(&mut drv, arg_name, output_names.join(" ").into())?;
match structured_attrs.as_mut() {
// add outputs to the json itself (as a list of strings)
Some(structured_attrs) => {
structured_attrs.insert(arg_name.into(), output_names.into());
}
// add drv.environment["outputs"] as a space-separated list
None => {
insert_env(&mut drv, arg_name, output_names.join(" ").into())?;
}
}
// drv.environment[$output_name] is added after the loop,
// with whatever is in drv.outputs[$output_name].
}

View file

@ -180,7 +180,8 @@ mod tests {
#[test_case(r#"(builtins.derivation { name = "foo"; system = ":"; builder = ":"; __structuredAttrs = true; foo = "bar"; outputChecks = {out = {maxClosureSize = 256 * 1024 * 1024; disallowedRequisites = [ "dev" ];};}; }).outPath"#, "/nix/store/pcywah1nwym69rzqdvpp03sphfjgyw1l-foo"; "structuredAttrs-outputChecks-outPath")]
// structured attrs and __ignoreNulls. ignoreNulls is inactive (so foo ends up in __json, yet __ignoreNulls itself is not present.
#[test_case(r#"(builtins.derivation { name = "foo"; system = ":"; builder = ":"; __ignoreNulls = false; foo = null; __structuredAttrs = true; }).drvPath"#, "/nix/store/rldskjdcwa3p7x5bqy3r217va1jsbjsc-foo.drv"; "structuredAttrs-and-ignore-nulls-drvPath")]
// structured attrs, setting outputs.
#[test_case(r#"(builtins.derivation { name = "test"; system = "aarch64-linux"; builder = "/bin/sh"; __structuredAttrs = true; outputs = [ "out"]; }).drvPath"#, "/nix/store/6sgawp30zibsh525p7c948xxd22y2ngy-test.drv"; "structuredAttrs-outputs-drvPath")]
fn test_outpath(code: &str, expected_path: &str) {
let value = eval(code).value.expect("must succeed");