-
Notifications
You must be signed in to change notification settings - Fork 8
Provenance #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Provenance #321
Changes from all commits
e096c4b
607804e
1d8d430
1a638ee
8c9d6b2
c8a845e
05e14c5
62e4faf
e7453a4
84e8f4b
89bb2f4
c426593
b03ddaf
959bc7d
06305fb
e4ab014
a4734c6
094f8dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #pragma once | ||
|
|
||
| #include "nix/util/provenance.hh" | ||
| #include "nix/fetchers/fetchers.hh" | ||
|
|
||
| namespace nix { | ||
|
|
||
| struct TreeProvenance : Provenance | ||
| { | ||
| ref<nlohmann::json> attrs; | ||
|
|
||
| TreeProvenance(const fetchers::Input & input); | ||
|
|
||
| nlohmann::json to_json() const override; | ||
| }; | ||
|
|
||
| } // namespace nix |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include "nix/fetchers/provenance.hh" | ||
| #include "nix/fetchers/attrs.hh" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace nix { | ||
|
|
||
| TreeProvenance::TreeProvenance(const fetchers::Input & input) | ||
| : attrs(make_ref<nlohmann::json>([&]() { | ||
| // Remove the narHash attribute from the provenance info, as it's redundant (it's already recorded in the store | ||
| // path info). | ||
| auto attrs2 = input.attrs; | ||
| attrs2.erase("narHash"); | ||
| return fetchers::attrsToJSON(attrs2); | ||
| }())) | ||
| { | ||
| } | ||
|
|
||
| nlohmann::json TreeProvenance::to_json() const | ||
| { | ||
| return nlohmann::json{ | ||
| {"type", "tree"}, | ||
| {"attrs", *attrs}, | ||
| }; | ||
| } | ||
|
|
||
| } // namespace nix |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,30 @@ | |
| #include "nix/store/store-api.hh" | ||
| #include "nix/fetchers/git-utils.hh" | ||
| #include "nix/fetchers/fetch-settings.hh" | ||
| #include "nix/util/provenance.hh" | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace nix::fetchers { | ||
|
|
||
| struct FetchurlProvenance : Provenance | ||
| { | ||
| std::string url; | ||
|
|
||
| FetchurlProvenance(const std::string & url) | ||
| : url(url) | ||
| { | ||
| } | ||
|
|
||
| nlohmann::json to_json() const override | ||
| { | ||
| return nlohmann::json{ | ||
| {"type", "fetchurl"}, | ||
| {"url", url}, | ||
| }; | ||
| } | ||
| }; | ||
|
Comment on lines
+12
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for "fetchurl" references in the codebase
echo "=== Searching for 'fetchurl' ==="
rg -n "fetchurl" --type-list | head -5
rg -n "fetchurl" 2>/dev/null | head -20
echo -e "\n=== Searching for Provenance deserialization patterns ==="
rg -n "from_json|Provenance::from_json" 2>/dev/null | head -20
echo -e "\n=== Searching for type dispatch/registry in provenance ==="
rg -n "\"type\"" src/libutil src/libfetchers src/libstore 2>/dev/null | grep -i provenance | head -20Repository: DeterminateSystems/nix-src Length of output: 4928 🏁 Script executed: #!/bin/bash
# Look for Provenance class definition and from_json implementation
echo "=== Finding Provenance class definition ==="
fd -e "\.hh" -e "\.cc" | xargs rg -l "class Provenance" 2>/dev/null
echo -e "\n=== Search for from_json in provenance files ==="
fd -e "\.hh" -e "\.cc" | xargs rg -A 10 "from_json.*Provenance" 2>/dev/null | head -40Repository: DeterminateSystems/nix-src Length of output: 163 🏁 Script executed: #!/bin/bash
# Look for JSON type dispatching for provenance
echo "=== Searching for provenance type mapping ==="
rg -n "type.*provenance\|provenance.*type" -i src/ 2>/dev/null | head -20
echo -e "\n=== Checking for nlohmann json deserialization ==="
rg -n "nlohmann::json\|\.get\(\)" src/libfetchers src/libutil -A 2 2>/dev/null | grep -A 2 "type\|fetchurl" | head -30Repository: DeterminateSystems/nix-src Length of output: 167 🏁 Script executed: #!/bin/bash
# Read the from_json implementation
echo "=== src/libutil/provenance.cc from_json implementation ==="
sed -n '32,80p' src/libutil/provenance.cc
echo -e "\n=== Check full provenance.cc ==="
wc -l src/libutil/provenance.cc src/libfetchers/provenance.cc src/libstore/provenance.cc 2>/dev/null
echo -e "\n=== Read src/libutil/provenance.cc entirely ==="
cat -n src/libutil/provenance.ccRepository: DeterminateSystems/nix-src Length of output: 2603 🏁 Script executed: #!/bin/bash
# Check what files include/define FetchurlProvenance
echo "=== Files mentioning FetchurlProvenance ==="
rg -n "FetchurlProvenance" --type cc --type hh 2>/dev/null
echo -e "\n=== Check src/libfetchers/provenance.cc ==="
cat -n src/libfetchers/provenance.cc 2>/dev/null || echo "File not found"
echo -e "\n=== Check all provenance related headers ==="
fd -e ".hh" | xargs rg -l "Provenance" 2>/dev/null | head -10Repository: DeterminateSystems/nix-src Length of output: 1529 🏁 Script executed: #!/bin/bash
# Read provenance headers
echo "=== src/libutil/include/nix/util/provenance.hh ==="
cat -n src/libutil/include/nix/util/provenance.hh
echo -e "\n=== src/libstore/include/nix/store/provenance.hh ==="
cat -n src/libstore/include/nix/store/provenance.hhRepository: DeterminateSystems/nix-src Length of output: 3463 🏁 Script executed: #!/bin/bash
# Check for registration patterns
echo "=== Looking for RegisteredTypes registration ==="
rg -n "registeredTypes\|RegisteredTypes\|register.*[Pp]rovenance" -A 3 -B 1 --type cc --type hh 2>/dev/null | head -60
echo -e "\n=== Check tarball.cc for FetchurlProvenance context ==="
sed -n '1,50p' src/libfetchers/tarball.ccRepository: DeterminateSystems/nix-src Length of output: 1265 🏁 Script executed: #!/bin/bash
# Search for Provenance::Register usage pattern
echo "=== Looking for Provenance::Register instantiation ==="
rg -n "Provenance::Register\|Register.*type" -B 2 -A 5 --type cc --type hh 2>/dev/null
echo -e "\n=== Check full src/libstore/provenance.cc ==="
cat -n src/libstore/provenance.cc
echo -e "\n=== Search for registration in fetchers/provenance ==="
cat -n src/libfetchers/provenance.ccRepository: DeterminateSystems/nix-src Length of output: 2218 🏁 Script executed: #!/bin/bash
# Look for how other provenance types register themselves
echo "=== Check for registrations across all provenance implementations ==="
find . -name "provenance*" -type f \( -name "*.cc" -o -name "*.hh" \) 2>/dev/null | xargs cat -n 2>/dev/null | grep -A 10 "Register"
echo -e "\n=== Full tarball.cc provenance section ==="
sed -n '12,100p' src/libfetchers/tarball.ccRepository: DeterminateSystems/nix-src Length of output: 3819 Register The Provenance::Register registerFetchurlProvenance("fetchurl", [](nlohmann::json json) {
auto & obj = getObject(json);
return make_ref<FetchurlProvenance>(getString(valueAt(obj, "url")));
});Additionally, URLs in provenance may contain credentials or signed tokens; consider redacting sensitive components before serialization. 🤖 Prompt for AI Agents |
||
|
|
||
| DownloadFileResult downloadFile( | ||
| Store & store, | ||
| const Settings & settings, | ||
|
|
@@ -83,6 +104,13 @@ DownloadFileResult downloadFile( | |
| }, | ||
| hashString(HashAlgorithm::SHA256, sink.s)); | ||
| info.narSize = sink.s.size(); | ||
| if (experimentalFeatureSettings.isEnabled(Xp::Provenance)) { | ||
| auto sanitizedUrl = request.uri.parsed(); | ||
| if (sanitizedUrl.authority) | ||
| sanitizedUrl.authority->password.reset(); | ||
| sanitizedUrl.query.clear(); | ||
| info.provenance = std::make_shared<FetchurlProvenance>(sanitizedUrl.to_string()); | ||
| } | ||
| auto source = StringSource{sink.s}; | ||
| store.addToStore(info, source, NoRepair, NoCheckSigs); | ||
| storePath = std::move(info.path); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ headers = files( | |
| 'flake.hh', | ||
| 'flakeref.hh', | ||
| 'lockfile.hh', | ||
| 'provenance.hh', | ||
| 'settings.hh', | ||
| 'url-name.hh', | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #include "nix/util/provenance.hh" | ||
|
|
||
| namespace nix { | ||
|
|
||
| struct FlakeProvenance : Provenance | ||
| { | ||
| std::shared_ptr<const Provenance> next; | ||
| std::string flakeOutput; | ||
|
|
||
| FlakeProvenance(std::shared_ptr<const Provenance> next, std::string flakeOutput) | ||
| : next(std::move(next)) | ||
| , flakeOutput(std::move(flakeOutput)) {}; | ||
|
|
||
| nlohmann::json to_json() const override; | ||
| }; | ||
|
|
||
| } // namespace nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having to call this, is there any way we could maybe make this automatic?
(Mostly thinking about protecting from developer error -- if I have to write code here for whatever reason, and add a new path where I should have called
setRootProvenancebut forgot to, that's probably not great. But if it's integrated into the construction of e.g.attrPath, that means we can't forget it because it'll always happen)