aboutsummaryrefslogtreecommitdiff
path: root/src/nix/flake.cc
diff options
context:
space:
mode:
authorMatthew Kenigsberg <matthewkenigsberg@gmail.com>2020-05-21 16:58:02 -0600
committerMatthew Kenigsberg <matthewkenigsberg@gmail.com>2020-05-21 17:06:11 -0600
commit8d67794da1b1307c3d117058f85649b05fe7c554 (patch)
treeb5804c625b6d24f065839e16064f1114b7be42b0 /src/nix/flake.cc
parent5f64655ff429be08aa0787761697787e7050f373 (diff)
handle circular flake dependencies in list-inputs
Diffstat (limited to 'src/nix/flake.cc')
-rw-r--r--src/nix/flake.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index d255bdda5..59bb40110 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -158,20 +158,26 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON
else {
logger->stdout("%s", flake.flake.lockedRef);
+ std::unordered_set<std::shared_ptr<Node>> visited;
+
std::function<void(const Node & node, const std::string & prefix)> recurse;
recurse = [&](const Node & node, const std::string & prefix)
{
for (const auto & [i, input] : enumerate(node.inputs)) {
- //auto tree2 = tree.child(i + 1 == inputs.inputs.size());
+ bool firstVisit = visited.insert(input.second).second;
bool last = i + 1 == node.inputs.size();
+ auto lockedNode = std::dynamic_pointer_cast<const LockedNode>(input.second);
+
logger->stdout("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s",
prefix + (last ? treeLast : treeConn), input.first,
- std::dynamic_pointer_cast<const LockedNode>(input.second)->lockedRef);
- recurse(*input.second, prefix + (last ? treeNull : treeLine));
+ lockedNode ? lockedNode->lockedRef : flake.flake.lockedRef);
+
+ if (firstVisit) recurse(*input.second, prefix + (last ? treeNull : treeLine));
}
};
+ visited.insert(flake.lockFile.root);
recurse(*flake.lockFile.root, "");
}
}