From 5332c439d008a51b578a1e255bce98040a697191 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 17 Jun 2020 17:13:01 +0200 Subject: [PATCH] InstallableFlake: Show all possible attribute names E.g. $ nix run nixpkgs#hello error: --- Error ---------- nix flake 'flake:nixpkgs' does not provide attribute 'apps.x86_64-linux.hello' or 'hello' instead of $ nix run nixpkgs#hello error: --- Error ---------- nix flake 'flake:nixpkgs' does not provide attribute 'hello' --- src/nix/installables.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/nix/installables.cc b/src/nix/installables.cc index c41aa859c..01be68cdb 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -440,6 +440,16 @@ ref openEvalCache( })); } +static std::string showAttrPaths(const std::vector & paths) +{ + std::string s; + for (const auto & [n, i] : enumerate(paths)) { + if (n > 0) s += n + 1 == paths.size() ? " or " : ", "; + s += '\''; s += i; s += '\''; + } + return s; +} + std::tuple InstallableFlake::toDerivation() { @@ -477,7 +487,7 @@ std::tuple InstallableF } throw Error("flake '%s' does not provide attribute %s", - flakeRef, concatStringsSep(", ", quoteStrings(attrPaths))); + flakeRef, showAttrPaths(getActualAttrPaths())); } std::vector InstallableFlake::toDerivations() @@ -505,7 +515,7 @@ std::pair InstallableFlake::toValue(EvalState & state) } throw Error("flake '%s' does not provide attribute %s", - flakeRef, concatStringsSep(", ", quoteStrings(attrPaths))); + flakeRef, showAttrPaths(getActualAttrPaths())); } std::vector, std::string>>