From 1e22ef1518fb175d762006f9cae7f6312b8caedb Mon Sep 17 00:00:00 2001 From: K900 Date: Wed, 25 Sep 2024 09:39:06 +0300 Subject: [PATCH] direnv: update for new nushell behavior (#5880) Nushell 0.98 makes it so external commands returning non-zero is considered an exception[0]. Wrap the direnv invocation in a try-catch, so that even if direnv fails, we get the message from direnv, but not the traceback from nushell. [0]: https://www.nushell.sh/blog/2024-09-17-nushell_0_98_0.html#non-zero-exit-codes-are-now-errors-toc --- modules/programs/direnv.nix | 12 +++++++++--- tests/modules/programs/direnv/nushell.nix | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index 4a7636705..ccfe00e6d 100644 --- a/modules/programs/direnv.nix +++ b/modules/programs/direnv.nix @@ -140,9 +140,15 @@ in { $env.config.hooks.pre_prompt? | default [] | append {|| - let direnv = (${getExe cfg.package} export json - | from json - | default {}) + let direnv = ( + try { + ${getExe cfg.package} export json + } catch { + "" + } + | from json + | default {} + ) if ($direnv | is-empty) { return } diff --git a/tests/modules/programs/direnv/nushell.nix b/tests/modules/programs/direnv/nushell.nix index 6655f01a8..2304b8b68 100644 --- a/tests/modules/programs/direnv/nushell.nix +++ b/tests/modules/programs/direnv/nushell.nix @@ -14,6 +14,6 @@ in '' assertFileExists "${configFile}" assertFileRegex "${configFile}" \ - '^\s*let direnv = (/nix/store/.*direnv.*/bin/direnv export json$' + '^\s*/nix/store/.*direnv.*/bin/direnv export json$' ''; }