zsh: consider zsh.{profile,login,logout,env}Extra in prezto

Right now the `zsh.prezto` module ignores the contents of the
`zsh.{profile,login,logout,env}Extra` options, so it means that if you
try to set, e.g., `zsh.profileExtra = "something";` this option will be
(silently) ignored.

This commit fixes another issue: since the main `zsh` module sets
`home.file."${relToDotDir".zshenv"}".text` while `zsh.prezto` set the
same file using `.source`, `zsh.prezto` would have priority so the
environment variables from Home-Manager would not be loaded in non-NixOS
systems. Now that we are using `.text` for both, the issue is fixed.
This commit is contained in:
Thiago Kenji Okada
2025-05-13 23:20:40 +01:00
committed by Austin Horstman
parent b44c39cf46
commit 5f36563a5c
2 changed files with 46 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ let
;
cfg = config.programs.zsh.prezto;
cfgZsh = config.programs.zsh;
relToDotDir =
file:
@@ -423,12 +424,30 @@ in
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
home.file."${relToDotDir ".zprofile"}".source = "${cfg.package}/share/zsh-prezto/runcoms/zprofile";
home.file."${relToDotDir ".zlogin"}".source = "${cfg.package}/share/zsh-prezto/runcoms/zlogin";
home.file."${relToDotDir ".zlogout"}".source = "${cfg.package}/share/zsh-prezto/runcoms/zlogout";
home.packages = [ cfg.package ];
home.file."${relToDotDir ".zshenv"}".source = "${cfg.package}/share/zsh-prezto/runcoms/zshenv";
home.file."${relToDotDir ".zprofile"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zprofile
${cfgZsh.profileExtra}
'';
home.file."${relToDotDir ".zlogin"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zlogin
${cfgZsh.loginExtra}
'';
home.file."${relToDotDir ".zlogout"}".text = ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zlogout
${cfgZsh.logoutExtra}
'';
# Using mkAfter to make sure we load Home-Manager's environment
# variables first (see modules/prgrams/zsh.nix)
home.file."${relToDotDir ".zshenv"}".text = lib.mkAfter ''
# Generated by Nix
source ${cfg.package}/share/zsh-prezto/runcoms/zshenv
${cfgZsh.envExtra}
'';
home.file."${relToDotDir ".zpreztorc"}".text = ''
# Generated by Nix
${optionalString (cfg.caseSensitive != null) ''

View File

@@ -1,5 +1,16 @@
{
programs.zsh.prezto.enable = true;
programs.zsh = {
enable = true;
envExtra = "envExtra";
profileExtra = "profileExtra";
loginExtra = "loginExtra";
logoutExtra = "logoutExtra";
sessionVariables.FOO = "bar";
prezto = {
enable = true;
extraConfig = "configExtra";
};
};
test.stubs = {
zsh-prezto = {
@@ -10,11 +21,21 @@
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 = ''
assertFileExists home-files/.zpreztorc
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 home-files/.zshenv \
'. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"'
assertFileContains home-files/.zshenv \
'export FOO="bar"'
'';
}