nix flake info --json: Show TreeInfo

This commit is contained in:
Eelco Dolstra 2020-04-02 11:51:34 +02:00
parent 74024515a3
commit ed13457dbf
4 changed files with 7 additions and 19 deletions

View file

@ -76,18 +76,6 @@ LockedNode::LockedNode(const nlohmann::json & json)
throw Error("lockfile contains mutable flakeref '%s'", lockedRef); 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 StorePath LockedNode::computeStorePath(Store & store) const
{ {
return info.computeStorePath(store); return info.computeStorePath(store);
@ -193,7 +181,7 @@ nlohmann::json LockFile::toJson() const
if (auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(node)) { if (auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(node)) {
n["original"] = fetchers::attrsToJson(lockedNode->originalRef.toAttrs()); n["original"] = fetchers::attrsToJson(lockedNode->originalRef.toAttrs());
n["locked"] = fetchers::attrsToJson(lockedNode->lockedRef.toAttrs()); n["locked"] = fetchers::attrsToJson(lockedNode->lockedRef.toAttrs());
n["info"] = treeInfoToJson(lockedNode->info); n["info"] = lockedNode->info.toJson();
if (!lockedNode->isFlake) n["flake"] = false; if (!lockedNode->isFlake) n["flake"] = false;
} }

View file

@ -81,10 +81,4 @@ std::shared_ptr<const Input> Input::applyOverrides(
return shared_from_this(); return shared_from_this();
} }
StorePath TreeInfo::computeStorePath(Store & store) const
{
assert(narHash);
return store.makeFixedOutputPath(true, narHash, "source");
}
} }

View file

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "path.hh" #include "path.hh"
#include "hash.hh"
#include <nlohmann/json_fwd.hpp>
namespace nix { class Store; } namespace nix { class Store; }
@ -21,6 +24,8 @@ struct TreeInfo
} }
StorePath computeStorePath(Store & store) const; StorePath computeStorePath(Store & store) const;
nlohmann::json toJson() const;
}; };
} }

View file

@ -103,6 +103,7 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
j["url"] = flake.lockedRef.to_string(); j["url"] = flake.lockedRef.to_string();
j["original"] = attrsToJson(flake.originalRef.toAttrs()); j["original"] = attrsToJson(flake.originalRef.toAttrs());
j["locked"] = attrsToJson(flake.lockedRef.toAttrs()); j["locked"] = attrsToJson(flake.lockedRef.toAttrs());
j["info"] = flake.sourceInfo->info.toJson();
if (auto rev = flake.lockedRef.input->getRev()) if (auto rev = flake.lockedRef.input->getRev())
j["revision"] = rev->to_string(Base16, false); j["revision"] = rev->to_string(Base16, false);
if (flake.sourceInfo->info.revCount) if (flake.sourceInfo->info.revCount)