From 8d67794da1b1307c3d117058f85649b05fe7c554 Mon Sep 17 00:00:00 2001 From: Matthew Kenigsberg Date: Thu, 21 May 2020 16:58:02 -0600 Subject: [PATCH 1/2] handle circular flake dependencies in list-inputs --- src/nix/flake.cc | 12 +++++++++--- 1 file 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> visited; + std::function 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(input.second); + logger->stdout("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s", prefix + (last ? treeLast : treeConn), input.first, - std::dynamic_pointer_cast(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, ""); } } From 934cc802f3c0c894ef7ef3924bbf24f46eb82c96 Mon Sep 17 00:00:00 2001 From: Matthew Kenigsberg Date: Thu, 21 May 2020 17:04:02 -0600 Subject: [PATCH 2/2] circular test --- tests/flakes.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/flakes.sh b/tests/flakes.sh index d28beb486..6a550ef32 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -661,3 +661,6 @@ sed -i $flakeB/flake.nix -e 's/456/789/' git -C $flakeB commit -a -m 'Foo' [[ $(nix eval --update-input b $flakeA#foo) = 1912 ]] + +# Test list-inputs with circular dependencies +nix flake list-inputs $flakeA \ No newline at end of file