From 2cd3234928f60bbff695a7ee56115ef7799c47cd Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Thu, 22 Oct 2026 11:53:25 +0200 Subject: [PATCH] gpg-agent: don't abort nushell startup when tty is unavailable The nushell integration set $env.GPG_TTY = (tty) unconditionally. Unlike the bash/zsh/fish variants, which use a plain command substitution and silently continue with an empty value on failure, nushell aborts the whole script when an external command used as an expression value exits non-zero. A missing controlling terminal (e.g. a login shell invoked non-interactively, such as by WSL's generated Windows app launchers) made nu exit immediately, breaking every command run through that login shell. Wrap the call in try/catch so nushell degrades the same way the other shell integrations do. --- modules/services/gpg-agent.nix | 2 +- tests/modules/services/gpg-agent/ssh-support.nix | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/services/gpg-agent.nix b/modules/services/gpg-agent.nix index 2174fdd793..510c25c030 100644 --- a/modules/services/gpg-agent.nix +++ b/modules/services/gpg-agent.nix @@ -44,7 +44,7 @@ let ''; gpgNushellInitStr = '' - $env.GPG_TTY = (tty) + $env.GPG_TTY = (try { tty } catch { "" }) '' + optionalString cfg.enableSshSupport '' ${gpgSshSupportStr} | ignore diff --git a/tests/modules/services/gpg-agent/ssh-support.nix b/tests/modules/services/gpg-agent/ssh-support.nix index 29016cf863..935ad938a6 100644 --- a/tests/modules/services/gpg-agent/ssh-support.nix +++ b/tests/modules/services/gpg-agent/ssh-support.nix @@ -19,6 +19,9 @@ assertFileContains \ home-files/.config/nushell/config.nu \ '$env.SSH_AUTH_SOCK = $"(@gnupg@/bin/gpgconf --list-dirs agent-ssh-socket)"' + assertFileContains \ + home-files/.config/nushell/config.nu \ + '$env.GPG_TTY = (try { tty } catch { "" })' assertFileContains \ home-files/.zshenv \ 'export SSH_AUTH_SOCK="$(@gnupg@/bin/gpgconf --list-dirs agent-ssh-socket)"'