1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-03 06:11:46 +02:00

Merge pull request #10722 from obsidiansystems/ca-obj-docs

Content addressing store objects
This commit is contained in:
Robert Hensing 2024-05-20 15:58:29 +02:00 committed by GitHub
commit 67db9e0c64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 240 additions and 65 deletions

View file

@ -1216,16 +1216,19 @@ nlohmann::json DerivationOutput::toJSON(
},
[&](const DerivationOutput::CAFixed & dof) {
res["path"] = store.printStorePath(dof.path(store, drvName, outputName));
res["hashAlgo"] = dof.ca.printMethodAlgo();
res["method"] = std::string { dof.ca.method.render() };
res["hashAlgo"] = printHashAlgo(dof.ca.hash.algo);
res["hash"] = dof.ca.hash.to_string(HashFormat::Base16, false);
// FIXME print refs?
},
[&](const DerivationOutput::CAFloating & dof) {
res["hashAlgo"] = std::string { dof.method.renderPrefix() } + printHashAlgo(dof.hashAlgo);
res["method"] = std::string { dof.method.render() };
res["hashAlgo"] = printHashAlgo(dof.hashAlgo);
},
[&](const DerivationOutput::Deferred &) {},
[&](const DerivationOutput::Impure & doi) {
res["hashAlgo"] = std::string { doi.method.renderPrefix() } + printHashAlgo(doi.hashAlgo);
res["method"] = std::string { doi.method.render() };
res["hashAlgo"] = printHashAlgo(doi.hashAlgo);
res["impure"] = true;
},
}, raw);
@ -1245,12 +1248,13 @@ DerivationOutput DerivationOutput::fromJSON(
keys.insert(key);
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashAlgorithm> {
auto & str = getString(valueAt(json, "hashAlgo"));
std::string_view s = str;
ContentAddressMethod method = ContentAddressMethod::parsePrefix(s);
auto & method_ = getString(valueAt(json, "method"));
ContentAddressMethod method = ContentAddressMethod::parse(method_);
if (method == TextIngestionMethod {})
xpSettings.require(Xp::DynamicDerivations);
auto hashAlgo = parseHashAlgo(s);
auto & hashAlgo_ = getString(valueAt(json, "hashAlgo"));
auto hashAlgo = parseHashAlgo(hashAlgo_);
return { std::move(method), std::move(hashAlgo) };
};
@ -1260,7 +1264,7 @@ DerivationOutput DerivationOutput::fromJSON(
};
}
else if (keys == (std::set<std::string_view> { "path", "hashAlgo", "hash" })) {
else if (keys == (std::set<std::string_view> { "path", "method", "hashAlgo", "hash" })) {
auto [method, hashAlgo] = methodAlgo();
auto dof = DerivationOutput::CAFixed {
.ca = ContentAddress {
@ -1273,7 +1277,7 @@ DerivationOutput DerivationOutput::fromJSON(
return dof;
}
else if (keys == (std::set<std::string_view> { "hashAlgo" })) {
else if (keys == (std::set<std::string_view> { "method", "hashAlgo" })) {
xpSettings.require(Xp::CaDerivations);
auto [method, hashAlgo] = methodAlgo();
return DerivationOutput::CAFloating {
@ -1286,7 +1290,7 @@ DerivationOutput DerivationOutput::fromJSON(
return DerivationOutput::Deferred {};
}
else if (keys == (std::set<std::string_view> { "hashAlgo", "impure" })) {
else if (keys == (std::set<std::string_view> { "method", "hashAlgo", "impure" })) {
xpSettings.require(Xp::ImpureDerivations);
auto [method, hashAlgo] = methodAlgo();
return DerivationOutput::Impure {