From ac9d2a5b069172e2f3d81da655dcca02632d2bd5 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron <886074+teto@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:29:05 +0200 Subject: [PATCH] nix flake show: log attribute name that "must be a derivation" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I would run `nix flake show` on a flake than hit: === ├───ihaskell: package 'ihaskell-wrapper' ├───ihaskell-96: package 'ihaskell-wrapper' ├───ihaskell-96-dev: package 'ghc-shell-for-ihaskell-0.10.4.0' error: expected a derivation === and it is not obvious what package is the culprit here since nix stops rightaway. Co-authored-by: Robert Hensing --- src/nix/flake.cc | 6 ++++-- tests/functional/flakes/show.sh | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 04d4ec8eb..5e3510a38 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1303,8 +1303,10 @@ struct CmdFlakeShow : FlakeCommand, MixJSON try { if (visitor.isDerivation()) showDerivation(); - else - throw Error("expected a derivation"); + else { + auto name = visitor.getAttrPathStr(state->s.name); + logger->warn(fmt("%s is not a derivation", name)); + } } catch (IFDError & e) { if (!json) { logger->cout( diff --git a/tests/functional/flakes/show.sh b/tests/functional/flakes/show.sh index a08db115a..0cdbdb8f2 100755 --- a/tests/functional/flakes/show.sh +++ b/tests/functional/flakes/show.sh @@ -107,3 +107,26 @@ in assert show_output.packages.${builtins.currentSystem}.default == { }; true ' + + +# Test that nix keeps going even when packages.$SYSTEM contains not derivations +cat >flake.nix < show-output.json +# shellcheck disable=SC2016 +nix eval --impure --expr ' +let show_output = builtins.fromJSON (builtins.readFile ./show-output.json); +in +assert show_output.packages.${builtins.currentSystem}.not-a-derivation == {}; +true +' +