summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Reuße <seb@schattenkopie.de>2022-10-24 13:36:22 +0200
committerSebastian Reuße <seb@schattenkopie.de>2022-10-24 14:22:50 +0200
commit7d84dbdf5b91439f798363559310d86b21bfa86c (patch)
treecb8489280a37ad2ef92fb666bc623b4a2c6532e3
parentbc4ce318bf6aa52031ad891675c573ce31308c8d (diff)
downloadnixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar.gz
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar.bz2
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar.lz
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar.xz
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.tar.zst
nixpkgs-7d84dbdf5b91439f798363559310d86b21bfa86c.zip
nixos/zsh: don’t be noisy when scripts are run with -u
When a script specifies the shell option “nounset” as part of the shebang (e.g.,
via “#!/usr/bin/env -S zsh -u”), our initialization scripts would produce error
messages of the form:

    __ETC_FOO_SOURCED: parameter not set

These messages could probably be confusing to users when running such scripts.
By providing a fall-back in the parameter expansion, we can avoid them.

This patch does not address interactive shell start-up, where such messages may
(or may not) be less problematic.
-rw-r--r--nixos/modules/programs/zsh/zsh.nix6
1 files changed, 3 insertions, 3 deletions
diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix
index 0c59d20fee4..8f40af7ad54 100644
--- a/nixos/modules/programs/zsh/zsh.nix
+++ b/nixos/modules/programs/zsh/zsh.nix
@@ -173,10 +173,10 @@ in
         # This file is read for all shells.
 
         # Only execute this file once per shell.
-        if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
+        if [ -n "''${__ETC_ZSHENV_SOURCED-}" ]; then return; fi
         __ETC_ZSHENV_SOURCED=1
 
-        if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
+        if [ -z "''${__NIXOS_SET_ENVIRONMENT_DONE-}" ]; then
             . ${config.system.build.setEnvironment}
         fi
 
@@ -206,7 +206,7 @@ in
         ${zshStartupNotes}
 
         # Only execute this file once per shell.
-        if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi
+        if [ -n "''${__ETC_ZPROFILE_SOURCED-}" ]; then return; fi
         __ETC_ZPROFILE_SOURCED=1
 
         # Setup custom login shell init stuff.