From eb3b05ad6d71e05b7ce249f820df5389067aa246 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 21 May 2024 05:29:52 -0600 Subject: [PATCH] print type and value in "flake attr is not a derivation" errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This turns errors like: error: flake output attribute 'hydraJobs' is not a derivation or path into errors like: error: expected flake output attribute 'hydraJobs' to be a derivation or path but found a set: { binaryTarball = «thunk»; build = «thunk»; etc> } This change affects all InstallableFlake commands. Source: https://git.lix.systems/lix-project/lix/commit/20981461d4a2a62c68f4bc7c4258473f7cd7d8e1 Signed-off-by: Jörg Thalheim --- .../print-value-in-installable-flake-error.md | 18 ++++++++++++++++++ src/libcmd/installable-flake.cc | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 doc/manual/rl-next/print-value-in-installable-flake-error.md diff --git a/doc/manual/rl-next/print-value-in-installable-flake-error.md b/doc/manual/rl-next/print-value-in-installable-flake-error.md new file mode 100644 index 000000000000..73b23c6781df --- /dev/null +++ b/doc/manual/rl-next/print-value-in-installable-flake-error.md @@ -0,0 +1,18 @@ +--- +synopsis: `nix flake` commands that expect derivations now print the failing value and its type +prs: 10778 +--- + +In errors like `flake output attribute 'nixosConfigurations.yuki.config' is not a derivation or path`, the message now includes the failing value and type. + +Before: + +``` + error: flake output attribute 'nixosConfigurations.yuki.config' is not a derivation or path +```` + +After: + +``` + error: expected flake output attribute 'nixosConfigurations.yuki.config' to be a derivation or path but found a set: { appstream = «thunk»; assertions = «thunk»; boot = { bcache = «thunk»; binfmt = «thunk»; binfmtMiscRegistrations = «thunk»; blacklistedKernelModules = «thunk»; bootMount = «thunk»; bootspec = «thunk»; cleanTmpDir = «thunk»; consoleLogLevel = «thunk»; «43 attributes elided» }; «48 attributes elided» } +``` diff --git a/src/libcmd/installable-flake.cc b/src/libcmd/installable-flake.cc index 6ff837ddc4b2..d42fa7aacccf 100644 --- a/src/libcmd/installable-flake.cc +++ b/src/libcmd/installable-flake.cc @@ -106,9 +106,14 @@ DerivedPathsWithInfo InstallableFlake::toDerivedPaths() fmt("while evaluating the flake output attribute '%s'", attrPath))) { return { *derivedPathWithInfo }; + } else { + throw Error( + "expected flake output attribute '%s' to be a derivation or path but found %s: %s", + attrPath, + showType(v), + ValuePrinter(*this->state, v, errorPrintOptions) + ); } - else - throw Error("flake output attribute '%s' is not a derivation or path", attrPath); } auto drvPath = attr->forceDerivation();