feat(tvix/build): don't force outputs to be in store_dir

There's no need to require builds to also put their outputs in store_dir.

So rename store_dir to inputs_dir and make outputs consume paths, not
basenames.

Also document the possibility for builds to write to inputs_dir. Let's
see if we want to make this a constraint later.

Change-Id: Ib4df20afcdde2d771c269c422f04c7e95587cd0f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10447
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-12-27 17:56:28 +01:00 committed by clbot
parent 3e63d7be42
commit 4d6137964b
3 changed files with 73 additions and 78 deletions

View file

@ -52,22 +52,15 @@ where
command_args.push(derivation.builder.clone());
command_args.extend_from_slice(&derivation.arguments);
// produce output_paths, which is the basename of each output (sorted)
// since Derivation is validated, we know output paths can be parsed.
// TODO: b/264 will remove the need to parse them here
let mut outputs: Vec<String> = derivation
// produce output_paths, which is the absolute path of each output (sorted)
let mut output_paths: Vec<String> = derivation
.outputs
.values()
.map(|output| {
let output_storepath = StorePathRef::from_absolute_path(output.path.as_bytes())
.expect("invalid output storepath");
output_storepath.to_string()
})
.map(|e| e.path[1..].to_owned())
.collect();
// Sort the outputs. We can use sort_unstable, as these are unique strings.
outputs.sort_unstable();
output_paths.sort_unstable();
// Produce environment_vars. We use a BTreeMap while producing them, so the
// resulting Vec is sorted by key.
@ -151,13 +144,13 @@ where
BuildRequest {
command_args,
outputs,
outputs: output_paths,
environment_vars,
inputs,
inputs_dir: nix_compat::store_path::STORE_DIR.into(),
constraints,
working_dir: "build".into(),
scratch_paths: vec!["build".into()],
store_dir: nix_compat::store_path::STORE_DIR.into(),
scratch_paths: vec!["build".into(), "nix/store".into()],
}
}
@ -245,10 +238,11 @@ mod test {
assert_eq!(
BuildRequest {
command_args: vec![":".to_string()],
outputs: vec!["fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo".to_string()],
command_args: vec![":".into()],
outputs: vec!["nix/store/fhaj6gmwns62s6ypkcldbaj2ybvkhx3p-foo".into()],
environment_vars: expected_environment_vars,
inputs: vec![INPUT_NODE_FOO.clone()],
inputs_dir: nix_compat::store_path::STORE_DIR.into(),
constraints: Some(BuildConstraints {
system: derivation.system.clone(),
min_memory: 0,
@ -256,9 +250,8 @@ mod test {
available_ro_paths: vec![],
provide_bin_sh: true,
}),
working_dir: "build".to_string(),
scratch_paths: vec!["build".to_string()],
store_dir: nix_compat::store_path::STORE_DIR.to_string(),
working_dir: "build".into(),
scratch_paths: vec!["build".into(), "nix/store".into()],
},
build_request
);
@ -314,9 +307,10 @@ mod test {
assert_eq!(
BuildRequest {
command_args: vec![":".to_string()],
outputs: vec!["4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar".to_string()],
outputs: vec!["nix/store/4q0pg5zpfmznxscq3avycvf9xdvx50n3-bar".into()],
environment_vars: expected_environment_vars,
inputs: vec![],
inputs_dir: nix_compat::store_path::STORE_DIR.into(),
constraints: Some(BuildConstraints {
system: derivation.system.clone(),
min_memory: 0,
@ -324,9 +318,8 @@ mod test {
available_ro_paths: vec![],
provide_bin_sh: true,
}),
working_dir: "build".to_string(),
scratch_paths: vec!["build".to_string()],
store_dir: nix_compat::store_path::STORE_DIR.to_string(),
working_dir: "build".into(),
scratch_paths: vec!["build".into(), "nix/store".into()],
},
build_request
);