diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-06-17 17:13:01 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-06-17 17:13:01 +0200 |
commit | 5332c439d008a51b578a1e255bce98040a697191 (patch) | |
tree | ce3742b7d879ae296126f46217ed7cb142067879 | |
parent | ad66fb0a37aaa1daef6a1dfafbc098ebe02783d1 (diff) |
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'
-rw-r--r-- | src/nix/installables.cc | 14 |
1 files 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<eval_cache::EvalCache> openEvalCache( })); } +static std::string showAttrPaths(const std::vector<std::string> & 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<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation() { @@ -477,7 +487,7 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF } throw Error("flake '%s' does not provide attribute %s", - flakeRef, concatStringsSep(", ", quoteStrings(attrPaths))); + flakeRef, showAttrPaths(getActualAttrPaths())); } std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations() @@ -505,7 +515,7 @@ std::pair<Value *, Pos> InstallableFlake::toValue(EvalState & state) } throw Error("flake '%s' does not provide attribute %s", - flakeRef, concatStringsSep(", ", quoteStrings(attrPaths))); + flakeRef, showAttrPaths(getActualAttrPaths())); } std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>> |