From ed13457dbf1a78f47f760e349985b23dfd5f16c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Apr 2020 11:51:34 +0200 Subject: [PATCH] nix flake info --json: Show TreeInfo --- src/libexpr/flake/lockfile.cc | 14 +------------- src/libfetchers/fetchers.cc | 6 ------ src/libfetchers/tree-info.hh | 5 +++++ src/nix/flake.cc | 1 + 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index f73b1ac25..3751e5b90 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -76,18 +76,6 @@ LockedNode::LockedNode(const nlohmann::json & json) throw Error("lockfile contains mutable flakeref '%s'", lockedRef); } -static nlohmann::json treeInfoToJson(const TreeInfo & info) -{ - nlohmann::json json; - assert(info.narHash); - json["narHash"] = info.narHash.to_string(SRI); - if (info.revCount) - json["revCount"] = *info.revCount; - if (info.lastModified) - json["lastModified"] = *info.lastModified; - return json; -} - StorePath LockedNode::computeStorePath(Store & store) const { return info.computeStorePath(store); @@ -193,7 +181,7 @@ nlohmann::json LockFile::toJson() const if (auto lockedNode = std::dynamic_pointer_cast(node)) { n["original"] = fetchers::attrsToJson(lockedNode->originalRef.toAttrs()); n["locked"] = fetchers::attrsToJson(lockedNode->lockedRef.toAttrs()); - n["info"] = treeInfoToJson(lockedNode->info); + n["info"] = lockedNode->info.toJson(); if (!lockedNode->isFlake) n["flake"] = false; } diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 5a782a4fe..765a6585f 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -81,10 +81,4 @@ std::shared_ptr Input::applyOverrides( return shared_from_this(); } -StorePath TreeInfo::computeStorePath(Store & store) const -{ - assert(narHash); - return store.makeFixedOutputPath(true, narHash, "source"); -} - } diff --git a/src/libfetchers/tree-info.hh b/src/libfetchers/tree-info.hh index 02e92759b..25cee445e 100644 --- a/src/libfetchers/tree-info.hh +++ b/src/libfetchers/tree-info.hh @@ -1,6 +1,9 @@ #pragma once #include "path.hh" +#include "hash.hh" + +#include namespace nix { class Store; } @@ -21,6 +24,8 @@ struct TreeInfo } StorePath computeStorePath(Store & store) const; + + nlohmann::json toJson() const; }; } diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 2b7497a84..93dbb9601 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -103,6 +103,7 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake) j["url"] = flake.lockedRef.to_string(); j["original"] = attrsToJson(flake.originalRef.toAttrs()); j["locked"] = attrsToJson(flake.lockedRef.toAttrs()); + j["info"] = flake.sourceInfo->info.toJson(); if (auto rev = flake.lockedRef.input->getRev()) j["revision"] = rev->to_string(Base16, false); if (flake.sourceInfo->info.revCount)