From 4910d74086a85876e093136a0e8ebc547b467af7 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 8 Mar 2024 21:43:54 -0800 Subject: [PATCH 1/2] Print derivation paths in `nix eval` `nix eval` forces values and prints derivations as attribute sets, so commands that print derivations (e.g. `nix eval nixpkgs#bash`) will infinitely loop and segfault. Printing derivations as `.drv` paths makes `nix eval` complete as expected. Further work is needed, but this is better than a segfault. --- src/nix/eval.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nix/eval.cc b/src/nix/eval.cc index 2044c8c2b..088be3b17 100644 --- a/src/nix/eval.cc +++ b/src/nix/eval.cc @@ -120,8 +120,17 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption } else { - state->forceValueDeep(*v); - logger->cout("%s", ValuePrinter(*state, *v, PrintOptions { .force = true })); + logger->cout( + "%s", + ValuePrinter( + *state, + *v, + PrintOptions { + .force = true, + .derivationPaths = true + } + ) + ); } } }; From 7f45b1c8d8caf4beeb68c981ae813d6251a7ee63 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 11 Mar 2024 09:21:24 -0700 Subject: [PATCH 2/2] Add release note --- doc/manual/rl-next/nix-eval-derivations.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 doc/manual/rl-next/nix-eval-derivations.md diff --git a/doc/manual/rl-next/nix-eval-derivations.md b/doc/manual/rl-next/nix-eval-derivations.md new file mode 100644 index 000000000..ed0a73384 --- /dev/null +++ b/doc/manual/rl-next/nix-eval-derivations.md @@ -0,0 +1,13 @@ +--- +synopsis: "`nix eval` prints derivations as `.drv` paths" +prs: 10200 +--- + +`nix eval` will now print derivations as their `.drv` paths, rather than as +attribute sets. This makes commands like `nix eval nixpkgs#bash` terminate +instead of infinitely looping into recursive self-referential attributes: + +```ShellSession +$ nix eval nixpkgs#bash +«derivation /nix/store/m32cbgbd598f4w299g0hwyv7gbw6rqcg-bash-5.2p26.drv» +```