Skip to content

Add tags to BuildProvenance#374

Open
edolstra wants to merge 2 commits intomainfrom
provenance-tags
Open

Add tags to BuildProvenance#374
edolstra wants to merge 2 commits intomainfrom
provenance-tags

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Feb 27, 2026

Motivation

These are name/value pairs from the build host that can be configured through the build-provenance-tags setting.

Context

Summary by CodeRabbit

  • New Features

    • Added a new build-provenance-tags setting to record arbitrary name/value metadata for builds.
    • Build provenance now includes and displays those tags alongside existing provenance details.
  • Tests

    • Functional tests updated to include sample provenance tags for verification.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

Adds support for recording build provenance tags (arbitrary name/value pairs): new Settings entry, parsing/serialization for map<string,string>, BuildProvenance gains tags (constructor, JSON in/out), derivation construction passes tags, and textual provenance display prints them.

Changes

Cohort / File(s) Summary
Configuration & Settings
src/libstore/include/nix/store/globals.hh, src/libstore/globals.cc
Added buildProvenanceTags setting (type Setting<std::map<std::string,std::string>>) and template specializations to parse/serialize JSON ↔ map.
BuildProvenance Core
src/libstore/include/nix/store/provenance.hh, src/libstore/provenance.cc
Added tags member to BuildProvenance, extended constructor signature, and updated to_json/deserialization to include tags.
Derivation Integration
src/libstore/unix/build/derivation-builder.cc
Passes settings.buildProvenanceTags.get() into BuildProvenance when registering outputs.
Display & Output
src/nix/provenance.cc
Prints each provenance tag as tag <name>: <value> in textual provenance output.
Tests & Defaults
tests/functional/common/init.sh, tests/functional/flakes/provenance.sh
Added build-provenance-tags config to test init and updated test expectations to include tags (JSON and textual).
Cleanup
src/libcmd/include/nix/cmd/installable-attr-path.hh
Removed transitive #include <nlohmann/json.hpp>.

Sequence Diagram(s)

sequenceDiagram
    participant Settings as Settings (config)
    participant Deriver as DerivationBuilder
    participant Store as BuildProvenance
    participant JSON as JSON (serialization)
    participant CLI as CLI/display

    Settings->>Deriver: provide buildProvenanceTags (map)
    Deriver->>Store: construct BuildProvenance(..., tags)
    Store->>JSON: to_json() includes "tags"
    Note right of JSON: JSON persisted/stored
    JSON->>Store: registerBuildProvenance(... parse "tags" ...)
    Store->>CLI: when displaying, emit "tag <name>: <value>"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • grahamc

Poem

🐰 I hopped through settings, tags in tow,
I left small notes where build logs go,
A pr and branch, neatly in line,
Provenance tagged — how fine, how fine! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a tags feature to the BuildProvenance data structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch provenance-tags

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/functional/common/init.sh (1)

56-56: Keep test config parity across NixOS and non-NixOS paths.

build-provenance-tags is only set in one branch right now. Adding it to the NixOS branch too will prevent configuration drift if/when the same provenance expectations are enabled there.

💡 Proposed patch
 cat > "$test_nix_conf" <<EOF
 # TODO: this is not needed for all tests and prevents stable commands from be tested in isolation
 experimental-features = ${experimental_features:-}
 flake-registry = $TEST_ROOT/registry.json
 show-trace = true
+build-provenance-tags = {"pr": "1234", "branch": "main"}
 EOF
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/functional/common/init.sh` at line 56, The NixOS branch of the test
init script is missing the build-provenance-tags assignment; add the same line
build-provenance-tags = {"pr": "1234", "branch": "main"} into the NixOS
configuration branch (the block that configures NixOS paths/variables in
tests/functional/common/init.sh) so both NixOS and non-NixOS branches set
identical provenance tags.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/libstore/provenance.cc`:
- Around line 27-29: The current parsing of tags uses optionalValueAt(obj,
"tags") and immediately calls p->get<std::map<std::string, std::string>>(),
which throws if the JSON value is null; update the code to detect a null value
before calling get — e.g., after obtaining p from optionalValueAt(obj, "tags")
check p->is_null() (or equivalent) and only call p->get<std::map<std::string,
std::string>>() when not null, leaving the tags map empty when the JSON value is
null.

---

Nitpick comments:
In `@tests/functional/common/init.sh`:
- Line 56: The NixOS branch of the test init script is missing the
build-provenance-tags assignment; add the same line build-provenance-tags =
{"pr": "1234", "branch": "main"} into the NixOS configuration branch (the block
that configures NixOS paths/variables in tests/functional/common/init.sh) so
both NixOS and non-NixOS branches set identical provenance tags.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe3515c and 0345e76.

📒 Files selected for processing (9)
  • src/libcmd/include/nix/cmd/installable-attr-path.hh
  • src/libstore/globals.cc
  • src/libstore/include/nix/store/globals.hh
  • src/libstore/include/nix/store/provenance.hh
  • src/libstore/provenance.cc
  • src/libstore/unix/build/derivation-builder.cc
  • src/nix/provenance.cc
  • tests/functional/common/init.sh
  • tests/functional/flakes/provenance.sh
💤 Files with no reviewable changes (1)
  • src/libcmd/include/nix/cmd/installable-attr-path.hh

@github-actions
Copy link

github-actions bot commented Feb 27, 2026

@github-actions github-actions bot temporarily deployed to pull request February 27, 2026 22:49 Inactive
These are name/value pairs from the build host that can be configured
through the `build-provenance-tags` setting.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/libstore/include/nix/store/provenance.hh (1)

1-6: Consider adding #include <map> for std::map usage.

The file uses std::map<std::string, std::string> but doesn't directly include <map>. While it may be transitively included through one of the existing headers, directly including required standard library headers makes the code more robust against changes in transitive dependencies.

Suggested include addition
 `#pragma` once
 
 `#include` "nix/util/provenance.hh"
 `#include` "nix/store/path.hh"
 `#include` "nix/store/outputs-spec.hh"
+
+#include <map>
+#include <string>
 
 namespace nix {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/libstore/include/nix/store/provenance.hh` around lines 1 - 6, This header
uses std::map<std::string, std::string> (in provenance-related declarations) but
doesn't include the <map> header; add a direct include for <map> near the top of
src/libstore/include/nix/store/provenance.hh (alongside the other includes) so
std::map is available even if transitive includes change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/libstore/include/nix/store/provenance.hh`:
- Around line 1-6: This header uses std::map<std::string, std::string> (in
provenance-related declarations) but doesn't include the <map> header; add a
direct include for <map> near the top of
src/libstore/include/nix/store/provenance.hh (alongside the other includes) so
std::map is available even if transitive includes change.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0345e76 and 461106e.

📒 Files selected for processing (8)
  • src/libstore/globals.cc
  • src/libstore/include/nix/store/globals.hh
  • src/libstore/include/nix/store/provenance.hh
  • src/libstore/provenance.cc
  • src/libstore/unix/build/derivation-builder.cc
  • src/nix/provenance.cc
  • tests/functional/common/init.sh
  • tests/functional/flakes/provenance.sh
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/libstore/unix/build/derivation-builder.cc
  • src/libstore/provenance.cc
  • tests/functional/common/init.sh
  • tests/functional/flakes/provenance.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant