From ae9119167ebb24c95e8e45e12889ea147926ceb7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Mar 2020 22:06:57 +0100 Subject: Change the lock file to a graph This enables support for cycles between flakes. --- src/nix/flake.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/nix') diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 0887fb402..82357aef8 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -199,24 +199,25 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON stopProgressBar(); if (json) - std::cout << ((LockedInputs &) flake.lockFile).toJson() << "\n"; + std::cout << flake.lockFile.toJson() << "\n"; else { std::cout << fmt("%s\n", flake.flake.lockedRef); - std::function recurse; + std::function recurse; - recurse = [&](const LockedInputs & inputs, const std::string & prefix) + recurse = [&](const Node & node, const std::string & prefix) { - for (const auto & [i, input] : enumerate(inputs.inputs)) { + for (const auto & [i, input] : enumerate(node.inputs)) { //auto tree2 = tree.child(i + 1 == inputs.inputs.size()); - bool last = i + 1 == inputs.inputs.size(); + bool last = i + 1 == node.inputs.size(); std::cout << fmt("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s\n", - prefix + (last ? treeLast : treeConn), input.first, input.second.lockedRef); - recurse(input.second, prefix + (last ? treeNull : treeLine)); + prefix + (last ? treeLast : treeConn), input.first, + std::dynamic_pointer_cast(input.second)->lockedRef); + recurse(*input.second, prefix + (last ? treeNull : treeLine)); } }; - recurse(flake.lockFile, ""); + recurse(*flake.lockFile.root, ""); } } }; @@ -664,23 +665,26 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun if (jsonRoot) jsonRoot->attr("path", store->printStorePath(flake.flake.sourceInfo->storePath)); - std::function & jsonObj)> traverse; - traverse = [&](const LockedInputs & inputs, std::optional & jsonObj) + // FIXME: use graph output, handle cycles. + std::function & jsonObj)> traverse; + traverse = [&](const Node & node, std::optional & jsonObj) { auto jsonObj2 = jsonObj ? jsonObj->object("inputs") : std::optional(); - for (auto & input : inputs.inputs) { + for (auto & input : node.inputs) { + auto lockedInput = std::dynamic_pointer_cast(input.second); + assert(lockedInput); auto jsonObj3 = jsonObj2 ? jsonObj2->object(input.first) : std::optional(); if (!dryRun) - input.second.lockedRef.input->fetchTree(store); - auto storePath = input.second.computeStorePath(*store); + lockedInput->lockedRef.input->fetchTree(store); + auto storePath = lockedInput->computeStorePath(*store); if (jsonObj3) jsonObj3->attr("path", store->printStorePath(storePath)); sources.insert(std::move(storePath)); - traverse(input.second, jsonObj3); + traverse(*lockedInput, jsonObj3); } }; - traverse(flake.lockFile, jsonRoot); + traverse(*flake.lockFile.root, jsonRoot); if (!dryRun && !dstUri.empty()) { ref dstStore = dstUri.empty() ? openStore() : openStore(dstUri); -- cgit v1.2.3