From d5ece85b6d3d6b5ab5a514b2785fb952b629bfea Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 14 May 2026 20:20:23 -0500 Subject: [PATCH] zsh: guard session variables under nounset Use parameter expansion with a default value when checking Home Manager's session-variable sentinels. Users with zsh NO_UNSET or shell nounset enabled were seeing parameter-not-set errors before the generated session variables had a chance to export the sentinel variables. Update the home session-variable and zsh fixtures to cover the generated guards. --- modules/home-environment.nix | 2 +- modules/programs/zsh/default.nix | 2 +- tests/modules/home-environment/session-variables.nix | 4 ++-- tests/modules/programs/zsh/session-variables.zshenv | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index e073430344..68c572066a 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -657,7 +657,7 @@ in destination = "/etc/profile.d/hm-session-vars.sh"; text = '' # Only source this once. - if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi + if [ -n "''${__HM_SESS_VARS_SOURCED-}" ]; then return; fi export __HM_SESS_VARS_SOURCED=1 ${config.lib.shell.exportAll cfg.sessionVariables} diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index be53a05d21..fed803b069 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -486,7 +486,7 @@ in . "${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh" # Only source this once - if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then + if [[ -z "''${__HM_ZSH_SESS_VARS_SOURCED-}" ]]; then export __HM_ZSH_SESS_VARS_SOURCED=1 ${envVarsStr} fi diff --git a/tests/modules/home-environment/session-variables.nix b/tests/modules/home-environment/session-variables.nix index 9e5c7aa7ff..9a8baed07e 100644 --- a/tests/modules/home-environment/session-variables.nix +++ b/tests/modules/home-environment/session-variables.nix @@ -6,7 +6,7 @@ let linuxExpected = '' # Only source this once. - if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi + if [ -n "''${__HM_SESS_VARS_SOURCED-}" ]; then return; fi export __HM_SESS_VARS_SOURCED=1 export IS_EMPTY="" @@ -25,7 +25,7 @@ let darwinExpected = '' # Only source this once. - if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi + if [ -n "''${__HM_SESS_VARS_SOURCED-}" ]; then return; fi export __HM_SESS_VARS_SOURCED=1 export IS_EMPTY="" diff --git a/tests/modules/programs/zsh/session-variables.zshenv b/tests/modules/programs/zsh/session-variables.zshenv index c132d99d66..cf99c77486 100644 --- a/tests/modules/programs/zsh/session-variables.zshenv +++ b/tests/modules/programs/zsh/session-variables.zshenv @@ -2,7 +2,7 @@ . "/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh" # Only source this once -if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then +if [[ -z "${__HM_ZSH_SESS_VARS_SOURCED-}" ]]; then export __HM_ZSH_SESS_VARS_SOURCED=1 export IS_EMPTY="" export IS_FALSE=false