Skip to content

Commit 5217e30

Browse files
authored
Merge pull request #343 from DeterminateSystems/build-provenance
Build provenance improvements
2 parents df396d1 + 0d6c312 commit 5217e30

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

src/libstore/include/nix/store/provenance.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ struct BuildProvenance : Provenance
2323
*/
2424
std::optional<std::string> buildHost;
2525

26+
/**
27+
* The system type of the derivation.
28+
*/
29+
std::string system;
30+
2631
/**
2732
* The provenance of the derivation, if known.
2833
*/
@@ -34,10 +39,12 @@ struct BuildProvenance : Provenance
3439
const StorePath & drvPath,
3540
const OutputName & output,
3641
std::optional<std::string> buildHost,
42+
std::string system,
3743
std::shared_ptr<const Provenance> next)
3844
: drvPath(drvPath)
3945
, output(output)
4046
, buildHost(std::move(buildHost))
47+
, system(std::move(system))
4148
, next(std::move(next))
4249
{
4350
}

src/libstore/provenance.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ nlohmann::json BuildProvenance::to_json() const
1010
{"drv", drvPath.to_string()},
1111
{"output", output},
1212
{"buildHost", buildHost},
13+
{"system", system},
1314
{"next", next ? next->to_json() : nlohmann::json(nullptr)},
1415
};
1516
}
@@ -23,7 +24,11 @@ Provenance::Register registerBuildProvenance("build", [](nlohmann::json json) {
2324
if (auto p = optionalValueAt(obj, "buildHost"))
2425
buildHost = p->get<std::optional<std::string>>();
2526
auto buildProv = make_ref<BuildProvenance>(
26-
StorePath(getString(valueAt(obj, "drv"))), getString(valueAt(obj, "output")), buildHost, next);
27+
StorePath(getString(valueAt(obj, "drv"))),
28+
getString(valueAt(obj, "output")),
29+
buildHost,
30+
getString(valueAt(obj, "system")),
31+
next);
2732
return buildProv;
2833
});
2934

src/libstore/unix/build/derivation-builder.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,9 +1867,9 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
18671867

18681868
newInfo.deriver = drvPath;
18691869
newInfo.ultimate = true;
1870-
if (drvProvenance)
1871-
newInfo.provenance =
1872-
std::make_shared<const BuildProvenance>(drvPath, outputName, settings.getHostName(), drvProvenance);
1870+
if (experimentalFeatureSettings.isEnabled(Xp::Provenance))
1871+
newInfo.provenance = std::make_shared<const BuildProvenance>(
1872+
drvPath, outputName, settings.getHostName(), drv.platform, drvProvenance);
18731873
store.signPathInfo(newInfo);
18741874

18751875
finish(newInfo.path);

src/nix/provenance-show.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ R""(
88
# nix provenance show /run/current-system
99
/nix/store/k145bdxhdb89i4fkvgdisdz1yh2wiymm-nixos-system-machine-25.05.20251210.d2b1213
1010
← copied from cache.flakehub.com
11-
← built from derivation /nix/store/w3p3xkminq61hs00kihd34w1dglpj5s9-nixos-system-machine-25.05.20251210.d2b1213.drv (output out) on build-machine
11+
← built from derivation /nix/store/w3p3xkminq61hs00kihd34w1dglpj5s9-nixos-system-machine-25.05.20251210.d2b1213.drv (output out) on build-machine for x86_64-linux
1212
← instantiated from flake output github:my-org/my-repo/6b03eb949597fe96d536e956a2c14da9901dbd21?dir=machine#nixosConfigurations.machine.config.system.build.toplevel
1313
```
1414

src/nix/provenance.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ struct CmdProvenanceShow : StorePathsCommand
5858
} else if (auto build = std::dynamic_pointer_cast<const BuildProvenance>(provenance)) {
5959
logger->cout(
6060
"← built from derivation " ANSI_BOLD "%s" ANSI_NORMAL " (output " ANSI_BOLD "%s" ANSI_NORMAL
61-
") on " ANSI_BOLD "%s" ANSI_NORMAL,
61+
") on " ANSI_BOLD "%s" ANSI_NORMAL " for " ANSI_BOLD "%s" ANSI_NORMAL,
6262
store.printStorePath(build->drvPath),
6363
build->output,
64-
build->buildHost.value_or("unknown host").c_str());
64+
build->buildHost.value_or("unknown host").c_str(),
65+
build->system);
6566
provenance = build->next;
6667
} else if (auto flake = std::dynamic_pointer_cast<const FlakeProvenance>(provenance)) {
6768
// Collapse subpath/tree provenance into the flake provenance for legibility.

tests/functional/flakes/provenance.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ builder=$(nix eval --raw "$flake1Dir#packages.$system.default._builder")
4040
"type": "flake"
4141
},
4242
"output": "out",
43+
"system": "$system",
4344
"type": "build"
4445
}
4546
EOF
@@ -115,6 +116,7 @@ nix copy --from "file://$binaryCache" "$outPath" --no-check-sigs
115116
"type": "flake"
116117
},
117118
"output": "out",
119+
"system": "$system",
118120
"type": "build"
119121
},
120122
"type": "copied"
@@ -126,7 +128,7 @@ EOF
126128
[[ $(nix provenance show "$outPath") = $(cat <<EOF
127129
$outPath
128130
← copied from file://$binaryCache
129-
← built from derivation [1m$drvPath[0m (output [1mout[0m) on [1mtest-host[0m
131+
← built from derivation [1m$drvPath[0m (output [1mout[0m) on [1mtest-host[0m for [1m$system[0m
130132
← instantiated from flake output git+file://$flake1Dir?ref=refs/heads/master&rev=$rev#packages.$system.default
131133
EOF
132134
) ]]

0 commit comments

Comments
 (0)