From 9e0453a9b0c8ef22de0355b731d712707daa6308 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 10 Sep 2025 19:08:48 +0100 Subject: [PATCH] zsh: source session variable file directly Right now we load `hm-session-vars.sh` from `config.home.profileDirectory`, generally resulting in the following code being generated in `zshenv`: ``` . "/etc/profiles/per-user//etc/profile.d/hm-session-vars.sh" ``` This is problematic in a few situations. For example, when entering a `distrobox` environment I got the following error: ``` /home//.zshenv:.:2: no such file or directory: /etc/profiles/per-user//etc/profile.d/hm-session-vars.sh ``` Instead, let's point to the path directly to the `/nix/store` by using `config.home.sessionVariablesPackage` instead. This is more robust and it is more consistent with other things we source in ZSH. --- modules/programs/zsh/default.nix | 2 +- tests/modules/programs/zsh/prezto.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index ecc8f3ef..e3a03c03 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -437,7 +437,7 @@ in { home.file."${dotDirRel}/.zshenv".text = '' # Environment variables - . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" + . "${config.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh" # Only source this once if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then diff --git a/tests/modules/programs/zsh/prezto.nix b/tests/modules/programs/zsh/prezto.nix index 9a22f6f6..c9a43b05 100644 --- a/tests/modules/programs/zsh/prezto.nix +++ b/tests/modules/programs/zsh/prezto.nix @@ -33,8 +33,8 @@ assertFileContains home-files/.zlogout 'logoutExtra' assertFileContains home-files/.zshenv 'envExtra' # make sure we are loading the environment variables - assertFileContains home-files/.zshenv \ - '. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"' + assertFileContains $(normalizeStorePaths home-files/.zshenv) \ + '/nix/store/00000000000000000000000000000000-hm-session-vars.sh/etc/profile.d/hm-session-vars.sh' assertFileContains home-files/.zshenv \ 'export FOO="bar"' '';