builder: Match results of repeated derivations
`nix build --json` gives one result per installable, in order, except that Nix 2.35 repeats the results of installables that are the same derivation: two deploy targets with the same profile gave four results for two installables, and the build failed. When the counts differ, the builder now matches results by derivation path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a565260021
commit
8db6b0f36a
1 file changed
+20
-7
+20
-7
@@ -693,15 +693,28 @@ async fn run(config: &BuilderConfig, request: &BuildRequest) -> Result<BuildResu
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Built {
|
||||
#[serde(rename = "drvPath")]
|
||||
drv_path: String,
|
||||
outputs: BTreeMap<String, String>,
|
||||
}
|
||||
let built: Vec<Built> = serde_json::from_slice(&built.stdout).context("reading nix build's result")?;
|
||||
ensure!(
|
||||
built.len() == installables.len(),
|
||||
"nix build returned {} results for {} installables",
|
||||
built.len(),
|
||||
installables.len()
|
||||
);
|
||||
let mut built: Vec<Built> = serde_json::from_slice(&built.stdout).context("reading nix build's result")?;
|
||||
|
||||
// One result per installable, in order, except that some versions of Nix repeat the results
|
||||
// of installables that are the same derivation; then they're matched by derivation.
|
||||
if built.len() != installables.len() {
|
||||
let mut matched = Vec::new();
|
||||
for installable in &installables {
|
||||
let drv_path = output(
|
||||
command(config, "nix").args(["eval", "--raw"]).args(NIX_OPTIONS).arg(format!("{installable}.drvPath")),
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("finding the derivation of {installable}"))?;
|
||||
let result = built.iter().find(|b| b.drv_path == drv_path.trim());
|
||||
let result = result.with_context(|| format!("nix build returned nothing for {installable}"))?;
|
||||
matched.push(Built { drv_path: result.drv_path.clone(), outputs: result.outputs.clone() });
|
||||
}
|
||||
built = matched;
|
||||
}
|
||||
let (built_profiles, built_attrs) = built.split_at(profiles.len());
|
||||
for (profile, built) in profiles.iter_mut().zip(built_profiles) {
|
||||
profile.path = built.outputs.get("out").context("no out output")?.clone();
|
||||
|
||||
Reference in new issue
Block a user