1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-06 09:01:04 +01:00
home-manager/tests/modules/programs/zsh/prezto.nix
Thiago Kenji Okada 9e0453a9b0 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/<username>/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/<username>/.zshenv:.:2: no such file or directory: /etc/profiles/per-user/<username>/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.
2025-09-30 07:50:26 -05:00

41 lines
1.3 KiB
Nix

{
programs.zsh = {
enable = true;
envExtra = "envExtra";
profileExtra = "profileExtra";
loginExtra = "loginExtra";
logoutExtra = "logoutExtra";
sessionVariables.FOO = "bar";
prezto = {
enable = true;
extraConfig = "configExtra";
};
};
test.stubs = {
zsh-prezto = {
outPath = null;
buildScript = ''
mkdir -p $out/share/zsh-prezto/runcoms
echo '# zprofile' > $out/share/zsh-prezto/runcoms/zprofile
echo '# zlogin' > $out/share/zsh-prezto/runcoms/zlogin
echo '# zlogout' > $out/share/zsh-prezto/runcoms/zlogout
echo '# zshenv' > $out/share/zsh-prezto/runcoms/zshenv
echo '# zshrc' > $out/share/zsh-prezto/runcoms/zshrc
'';
};
};
nmt.script = ''
assertFileContains home-files/.zpreztorc 'configExtra'
assertFileContains home-files/.zprofile 'profileExtra'
assertFileContains home-files/.zlogin 'loginExtra'
assertFileContains home-files/.zlogout 'logoutExtra'
assertFileContains home-files/.zshenv 'envExtra'
# make sure we are loading the environment variables
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"'
'';
}