diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 6cd880309..2d81698b6 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -442,6 +442,19 @@ in ''; }) + { + home.file."${relToDotDir ".zshenv"}".text = '' + # Environment variables + . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" + + # Only source this once + if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then + export __HM_ZSH_SESS_VARS_SOURCED=1 + ${envVarsStr} + fi + ''; + } + { home.packages = with pkgs; [ zsh ] ++ optional cfg.enableCompletion nix-zsh-completions @@ -491,10 +504,6 @@ in "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" } - # Environment variables - . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" - ${envVarsStr} - ${optionalString cfg.oh-my-zsh.enable '' # oh-my-zsh extra settings for plugins ${cfg.oh-my-zsh.extraConfig} diff --git a/tests/modules/programs/zsh/session-variables.nix b/tests/modules/programs/zsh/session-variables.nix index 638b41c9f..f6f795f79 100644 --- a/tests/modules/programs/zsh/session-variables.nix +++ b/tests/modules/programs/zsh/session-variables.nix @@ -16,9 +16,9 @@ with lib; test.stubs.zsh = { }; nmt.script = '' - assertFileExists home-files/.zshrc - assertFileRegex home-files/.zshrc 'export V1="v1"' - assertFileRegex home-files/.zshrc 'export V2="v2-v1"' + assertFileExists home-files/.zshenv + assertFileRegex home-files/.zshenv 'export V1="v1"' + assertFileRegex home-files/.zshenv 'export V2="v2-v1"' ''; }; }