aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/fetchers/registry.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-02-06 14:27:31 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-02-06 14:27:31 +0100
commit379852a152cc2299bfd0a02e0229112ad322319c (patch)
tree773e8c806755379d03e033a50880fbbf1494ccb9 /src/libstore/fetchers/registry.cc
parentbe2580be0172a29843ed64e01216da1c0ed9e935 (diff)
Registry: Use attr notation instead of URLs
Diffstat (limited to 'src/libstore/fetchers/registry.cc')
-rw-r--r--src/libstore/fetchers/registry.cc50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/libstore/fetchers/registry.cc b/src/libstore/fetchers/registry.cc
index 9c74f118d..1fd42a169 100644
--- a/src/libstore/fetchers/registry.cc
+++ b/src/libstore/fetchers/registry.cc
@@ -19,31 +19,51 @@ std::shared_ptr<Registry> Registry::read(
auto json = nlohmann::json::parse(readFile(path));
auto version = json.value("version", 0);
- if (version != 1)
- throw Error("flake registry '%s' has unsupported version %d", path, version);
- auto flakes = json["flakes"];
- for (auto i = flakes.begin(); i != flakes.end(); ++i) {
- // FIXME: remove 'uri' soon.
- auto url = i->value("url", i->value("uri", ""));
- if (url.empty())
- throw Error("flake registry '%s' lacks a 'url' attribute for entry '%s'",
- path, i.key());
- registry->entries.push_back(
- {inputFromURL(i.key()), inputFromURL(url)});
+ // FIXME: remove soon
+ if (version == 1) {
+ auto flakes = json["flakes"];
+ for (auto i = flakes.begin(); i != flakes.end(); ++i) {
+ auto url = i->value("url", i->value("uri", ""));
+ if (url.empty())
+ throw Error("flake registry '%s' lacks a 'url' attribute for entry '%s'",
+ path, i.key());
+ registry->entries.push_back(
+ {inputFromURL(i.key()), inputFromURL(url)});
+ }
}
+ else if (version == 2) {
+ for (auto & i : json["flakes"])
+ registry->entries.push_back(
+ { inputFromAttrs(jsonToAttrs(i["from"]))
+ , inputFromAttrs(jsonToAttrs(i["to"]))
+ });
+ }
+
+ else
+ throw Error("flake registry '%s' has unsupported version %d", path, version);
+
+
return registry;
}
void Registry::write(const Path & path)
{
+ nlohmann::json arr;
+ for (auto & elem : entries) {
+ nlohmann::json obj;
+ obj["from"] = attrsToJson(elem.first->toAttrs());
+ obj["to"] = attrsToJson(elem.second->toAttrs());
+ arr.emplace_back(std::move(obj));
+ }
+
nlohmann::json json;
- json["version"] = 1;
- for (auto & elem : entries)
- json["flakes"][elem.first->to_string()] = { {"url", elem.second->to_string()} };
+ json["version"] = 2;
+ json["flakes"] = std::move(arr);
+
createDirs(dirOf(path));
- writeFile(path, json.dump(4));
+ writeFile(path, json.dump(2));
}
void Registry::add(