Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libstore/include/nix/store/provenance.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct BuildProvenance : Provenance
*/
std::optional<std::string> buildHost;

/**
* The system type of the derivation.
*/
std::string system;

/**
* The provenance of the derivation, if known.
*/
Expand All @@ -34,10 +39,12 @@ struct BuildProvenance : Provenance
const StorePath & drvPath,
const OutputName & output,
std::optional<std::string> buildHost,
std::string system,
std::shared_ptr<const Provenance> next)
: drvPath(drvPath)
, output(output)
, buildHost(std::move(buildHost))
, system(std::move(system))
, next(std::move(next))
{
}
Expand Down
7 changes: 6 additions & 1 deletion src/libstore/provenance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nlohmann::json BuildProvenance::to_json() const
{"drv", drvPath.to_string()},
{"output", output},
{"buildHost", buildHost},
{"system", system},
{"next", next ? next->to_json() : nlohmann::json(nullptr)},
};
}
Expand All @@ -23,7 +24,11 @@ Provenance::Register registerBuildProvenance("build", [](nlohmann::json json) {
if (auto p = optionalValueAt(obj, "buildHost"))
buildHost = p->get<std::optional<std::string>>();
auto buildProv = make_ref<BuildProvenance>(
StorePath(getString(valueAt(obj, "drv"))), getString(valueAt(obj, "output")), buildHost, next);
StorePath(getString(valueAt(obj, "drv"))),
getString(valueAt(obj, "output")),
buildHost,
getString(valueAt(obj, "system")),
next);
return buildProv;
});

Expand Down
6 changes: 3 additions & 3 deletions src/libstore/unix/build/derivation-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1867,9 +1867,9 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()

newInfo.deriver = drvPath;
newInfo.ultimate = true;
if (drvProvenance)
newInfo.provenance =
std::make_shared<const BuildProvenance>(drvPath, outputName, settings.getHostName(), drvProvenance);
if (experimentalFeatureSettings.isEnabled(Xp::Provenance))
newInfo.provenance = std::make_shared<const BuildProvenance>(
drvPath, outputName, settings.getHostName(), drv.platform, drvProvenance);
store.signPathInfo(newInfo);

finish(newInfo.path);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/provenance-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ R""(
# nix provenance show /run/current-system
/nix/store/k145bdxhdb89i4fkvgdisdz1yh2wiymm-nixos-system-machine-25.05.20251210.d2b1213
← copied from cache.flakehub.com
← built from derivation /nix/store/w3p3xkminq61hs00kihd34w1dglpj5s9-nixos-system-machine-25.05.20251210.d2b1213.drv (output out) on build-machine
← built from derivation /nix/store/w3p3xkminq61hs00kihd34w1dglpj5s9-nixos-system-machine-25.05.20251210.d2b1213.drv (output out) on build-machine for x86_64-linux
← instantiated from flake output github:my-org/my-repo/6b03eb949597fe96d536e956a2c14da9901dbd21?dir=machine#nixosConfigurations.machine.config.system.build.toplevel
```

Expand Down
5 changes: 3 additions & 2 deletions src/nix/provenance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ struct CmdProvenanceShow : StorePathsCommand
} else if (auto build = std::dynamic_pointer_cast<const BuildProvenance>(provenance)) {
logger->cout(
"← built from derivation " ANSI_BOLD "%s" ANSI_NORMAL " (output " ANSI_BOLD "%s" ANSI_NORMAL
") on " ANSI_BOLD "%s" ANSI_NORMAL,
") on " ANSI_BOLD "%s" ANSI_NORMAL " for " ANSI_BOLD "%s" ANSI_NORMAL,
store.printStorePath(build->drvPath),
build->output,
build->buildHost.value_or("unknown host").c_str());
build->buildHost.value_or("unknown host").c_str(),
build->system);
provenance = build->next;
} else if (auto flake = std::dynamic_pointer_cast<const FlakeProvenance>(provenance)) {
// Collapse subpath/tree provenance into the flake provenance for legibility.
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/flakes/provenance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ builder=$(nix eval --raw "$flake1Dir#packages.$system.default._builder")
"type": "flake"
},
"output": "out",
"system": "$system",
"type": "build"
}
EOF
Expand Down Expand Up @@ -115,6 +116,7 @@ nix copy --from "file://$binaryCache" "$outPath" --no-check-sigs
"type": "flake"
},
"output": "out",
"system": "$system",
"type": "build"
},
"type": "copied"
Expand All @@ -126,7 +128,7 @@ EOF
[[ $(nix provenance show "$outPath") = $(cat <<EOF
$outPath
← copied from file://$binaryCache
← built from derivation $drvPath (output out) on test-host
← built from derivation $drvPath (output out) on test-host for $system
← instantiated from flake output git+file://$flake1Dir?ref=refs/heads/master&rev=$rev#packages.$system.default
EOF
) ]]
Expand Down