From ff5dd74cbf54b78859f6ca064b6db7a82fd8e7d6 Mon Sep 17 00:00:00 2001 From: Josh Heinrichs Date: Sat, 29 Nov 2025 20:00:31 -0600 Subject: [PATCH] Fix `try-fwd-env` setting unset variables If an environment variable is unset, `try-fwd-env` will set it to an empty string. This can cause issues for programs that treat unset and empty environment variables differently. For instance, when jailing Spotify with the `pulse` combinator, `$PULSE_SERVER` gets set to an empty string, Spotify tries to use it as-is, fails, and then falls back to using ALSA. Ideally I would've liked to wire this into the existing env logic somehow but it's a bit tricky to do since `--setenv` needs to be provided to Bubblewrap conditionally based on a value that isn't known until the script is executed. Bubblewrap appears to handle `--setenv` being specified multiple times for the same variable okay, so not using the existing env logic doesn't break the ability to override environment variables. --- lib/combinators/try-fwd-env.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/combinators/try-fwd-env.nix b/lib/combinators/try-fwd-env.nix index eba6250..c592ac1 100644 --- a/lib/combinators/try-fwd-env.nix +++ b/lib/combinators/try-fwd-env.nix @@ -1,11 +1,19 @@ -{ combinators, helpers, ... }: +{ + combinators, + helpers, + pkgs, + ... +}: let - inherit (combinators) set-env; + inherit (combinators) unsafe-add-raw-args; in { sig = "String -> Permission"; doc = '' Forwards the specified environment variable to the underlying process (if set). ''; - impl = name: set-env name (helpers.noescape "\"\${${name}-}\""); + impl = + name: + assert pkgs.lib.isValidPosixName name; + unsafe-add-raw-args "\${${name}+--setenv ${name} \"\${${name}}\"}"; }