From 7e6c548eef2372cef1287ef45350e29ca5740159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 11 Sep 2024 13:01:26 +0200 Subject: [PATCH 1/2] zsh: let children shells set their fpath Currently zshenv by default only sets fpath without exporting it. A parent shell would also not set those variables usually as they are shell local. It also sources a file called set-environment but this is protected by an environment variable called __NIX_DARWIN_SET_ENVIRONMENT_DONE. Hence any modification done by the parent shell should persist as long as __NIX_DARWIN_SET_ENVIRONMENT_DONE is not unset. This behavior deviates from what we do in bashrc and breaks common setups such as tmux/mosh or screen. NixOS/nixpkgs@55819e6c861f53450030eea832a76583a6786370 --- modules/programs/zsh/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index 58a3155f..1f36740b 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -124,9 +124,8 @@ in # This file is read for all shells. # Only execute this file once per shell. - # But don't clobber the environment of interactive non-login children! if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi - export __ETC_ZSHENV_SOURCED=1 + __ETC_ZSHENV_SOURCED=1 # Don't execute this file when running in a pure nix-shell. if test -n "$IN_NIX_SHELL"; then return; fi From 6ad463a76421022de6762e6f50128febb970dcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Reu=C3=9Fe?= Date: Wed, 11 Sep 2024 14:03:57 +0200 Subject: [PATCH 2/2] 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. NixOS/nixpkgs@7d84dbdf5b91439f798363559310d86b21bfa86c --- modules/programs/zsh/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index 1f36740b..7574f8e9 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -124,13 +124,13 @@ 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 # Don't execute this file when running in a pure nix-shell. if test -n "$IN_NIX_SHELL"; then return; fi - if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then + if [ -z "''${__NIX_DARWIN_SET_ENVIRONMENT_DONE-}" ]; then . ${config.system.build.setEnvironment} fi @@ -152,7 +152,7 @@ in # This file is read for login shells. # 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 ${concatStringsSep "\n" zshVariables}