diff options
author | Nick Van den Broeck <nick.van.den.broeck666@gmail.com> | 2019-02-25 13:46:37 +0100 |
---|---|---|
committer | Nick Van den Broeck <nick.van.den.broeck666@gmail.com> | 2019-03-07 12:00:10 +0100 |
commit | 6542de98c298b6dc268b358166bd2f5bea2cc230 (patch) | |
tree | 46b1e13b1ae18ba929e6a09a1ea59b7589f8db8a | |
parent | 9ff1a9ea65bdeb520becb843b8300a23fb88a5a9 (diff) |
Implemented writeRegistry
-rw-r--r-- | src/libexpr/primops/flake.cc | 12 | ||||
-rw-r--r-- | src/libexpr/primops/flake.hh | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc index ac0421549..9d1da84f1 100644 --- a/src/libexpr/primops/flake.cc +++ b/src/libexpr/primops/flake.cc @@ -31,6 +31,18 @@ static std::unique_ptr<FlakeRegistry> readRegistry(const Path & path) return registry; } +/* Write the registry or lock file to a file. */ +static void writeRegistry(FlakeRegistry registry, Path path = "./flake.lock") +{ + nlohmann::json json = {}; + json["value"] = 0; // Not sure whether this should be 0. + json["flakes"] = {}; + for (auto elem : registry.entries) { + json["flakes"][elem.first] = elem.second.ref.to_string(); + } + writeFile(path, json.dump(4)); // The '4' is the number of spaces used in the indentation in the json file. +} + const FlakeRegistry & EvalState::getFlakeRegistry() { std::call_once(_flakeRegistryInit, [&]() diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh index 194b969a2..90c6bc7d2 100644 --- a/src/libexpr/primops/flake.hh +++ b/src/libexpr/primops/flake.hh @@ -35,4 +35,6 @@ struct Flake }; Flake getFlake(EvalState & state, const FlakeRef & flakeRef); + +void writeRegistry(FlakeRegistry); } |