From 57e6b30d181ae6baff0909a61544ecbe1f642936 Mon Sep 17 00:00:00 2001 From: K900 Date: Thu, 26 Sep 2024 20:07:37 +0300 Subject: [PATCH] direnv: work around nushell bug try/catch in a pipeline does not always work correctly in 0.98, so avoid the try-catch entirely. Upstream issue: https://github.com/nushell/nushell/issues/13868 --- modules/programs/direnv.nix | 12 ++++++------ tests/modules/programs/direnv/nushell.nix | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index ccfe00e6d..1b409991c 100644 --- a/modules/programs/direnv.nix +++ b/modules/programs/direnv.nix @@ -141,12 +141,12 @@ in { | default [] | append {|| let direnv = ( - try { - ${getExe cfg.package} export json - } catch { - "" - } - | from json + # We want to get the stdout from direnv even if it exits with non-zero, + # because it will have the DIRENV_ internal variables defined. + do { ${getExe cfg.package} export json } + | complete + | get stdout + | from json --strict | default {} ) if ($direnv | is-empty) { diff --git a/tests/modules/programs/direnv/nushell.nix b/tests/modules/programs/direnv/nushell.nix index 2304b8b68..502b325d5 100644 --- a/tests/modules/programs/direnv/nushell.nix +++ b/tests/modules/programs/direnv/nushell.nix @@ -13,7 +13,6 @@ "home-files/.config/nushell/config.nu"; in '' assertFileExists "${configFile}" - assertFileRegex "${configFile}" \ - '^\s*/nix/store/.*direnv.*/bin/direnv export json$' + assertFileRegex "${configFile}" '/nix/store/.*direnv.*/bin/direnv export json' ''; }