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.
This commit is contained in:
Austin Horstman
2026-05-14 20:20:23 -05:00
parent 32b42d71b4
commit d5ece85b6d
4 changed files with 5 additions and 5 deletions

View File

@@ -657,7 +657,7 @@ in
destination = "/etc/profile.d/hm-session-vars.sh"; destination = "/etc/profile.d/hm-session-vars.sh";
text = '' text = ''
# Only source this once. # 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 __HM_SESS_VARS_SOURCED=1
${config.lib.shell.exportAll cfg.sessionVariables} ${config.lib.shell.exportAll cfg.sessionVariables}

View File

@@ -486,7 +486,7 @@ in
. "${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh" . "${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh"
# Only source this once # 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 __HM_ZSH_SESS_VARS_SOURCED=1
${envVarsStr} ${envVarsStr}
fi fi

View File

@@ -6,7 +6,7 @@ let
linuxExpected = '' linuxExpected = ''
# Only source this once. # 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 __HM_SESS_VARS_SOURCED=1
export IS_EMPTY="" export IS_EMPTY=""
@@ -25,7 +25,7 @@ let
darwinExpected = '' darwinExpected = ''
# Only source this once. # 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 __HM_SESS_VARS_SOURCED=1
export IS_EMPTY="" export IS_EMPTY=""

View File

@@ -2,7 +2,7 @@
. "/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh" . "/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh"
# Only source this once # 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 __HM_ZSH_SESS_VARS_SOURCED=1
export IS_EMPTY="" export IS_EMPTY=""
export IS_FALSE=false export IS_FALSE=false