From 5e07e4b2814a3227a9ced54b7680f8d609207762 Mon Sep 17 00:00:00 2001 From: regnat Date: Tue, 16 Feb 2021 21:08:12 +0100 Subject: [PATCH] Fix `nix flake show --legacy` when the evaluation fails `nix flake show --legacy` was aborting the evaluation a bit too eagerly in case of error, so that running it on nixpkgs was only showing empty packages sets. Catch the error earlier to allow displaying the full set of packages --- src/nix/flake.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index be972f4f2..8a2730782 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -841,12 +841,17 @@ struct CmdFlakeShow : FlakeCommand auto attrs = state->listAttrFields(value, pos); for (const auto & [i, attr] : enumerate(attrs)) { bool last = i + 1 == attrs.size(); - auto value2 = state->getAttrField(value, {attr}, pos); - auto attrPath2(attrPath); - attrPath2.push_back(attr); - visit(*value2, pos, attrPath2, - fmt(ANSI_GREEN "%s%s" ANSI_NORMAL ANSI_BOLD "%s" ANSI_NORMAL, nextPrefix, last ? treeLast : treeConn, attr), - nextPrefix + (last ? treeNull : treeLine)); + try { + auto value2 = state->getAttrField(value, {attr}, pos); + auto attrPath2(attrPath); + attrPath2.push_back(attr); + visit(*value2, pos, attrPath2, + fmt(ANSI_GREEN "%s%s" ANSI_NORMAL ANSI_BOLD "%s" ANSI_NORMAL, nextPrefix, last ? treeLast : treeConn, attr), + nextPrefix + (last ? treeNull : treeLine)); + } catch (EvalError& e) { + if (!(attrPath.size() > 0 && attrPath[0] == "legacyPackages")) + throw; + } } };