1
0
mirror of https://github.com/nix-community/home-manager synced 2024-05-31 20:13:34 +02:00

zsh: move session variables export to zshrc

Unlike .zshenv, .zshrc file is sourced only by interactive shells.
This commit is contained in:
Nikita Uvarov 2018-01-25 14:13:44 +01:00
parent 91a98f919d
commit fa6f697dbb
No known key found for this signature in database
GPG Key ID: F7A5FB3A7C10EF96

View File

@ -171,10 +171,8 @@ in
sessionVariables = mkOption {
default = {};
type = types.attrs;
example = { ZSH_CACHE_DIR = "$HOME/.cache/zsh"; };
description = ''
Environment variables that will be set for zsh session.
'';
example = { MAILCHECK = 30; };
description = "Environment variables that will be set for zsh session.";
};
initExtra = mkOption {
@ -240,20 +238,46 @@ in
};
config = mkIf cfg.enable (mkMerge [
(mkIf (cfg.profileExtra != "") {
home.file."${relToDotDir ".zprofile"}".text = cfg.profileExtra;
})
(mkIf (cfg.loginExtra != "") {
home.file."${relToDotDir ".zlogin"}".text = cfg.loginExtra;
})
(mkIf (cfg.logoutExtra != "") {
home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra;
})
(mkIf cfg.oh-my-zsh.enable {
home.file."${relToDotDir ".zshenv"}".text = ''
ZSH="${pkgs.oh-my-zsh}/share/oh-my-zsh";
ZSH_CACHE_DIR="''${XDG_CACHE_HOME:-''$HOME/.cache}/oh-my-zsh";
'';
})
(mkIf (cfg.dotDir != null) {
home.file."${relToDotDir ".zshenv"}".text = ''
ZDOTDIR=${zdotdir}
'';
# When dotDir is set, only use ~/.zshenv to source ZDOTDIR/.zshenv,
# This is so that if ZDOTDIR happens to be
# already set correctly (by e.g. spawning a zsh inside a zsh), all env
# vars still get exported
home.file.".zshenv".text = ''
source ${zdotdir}/.zshenv
'';
})
{
home.packages = with pkgs; [ zsh ]
++ optional cfg.enableCompletion nix-zsh-completions
++ optional cfg.oh-my-zsh.enable oh-my-zsh;
home.file."${relToDotDir ".zshenv"}".text = ''
typeset -U fpath
${optionalString (config.home.sessionVariableSetter != "pam") ''
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
''}
${envVarsStr}
'';
home.file."${relToDotDir ".zshrc"}".text = ''
typeset -U path cdpath fpath manpath
fpath+="$HOME/.nix-profile/share/zsh/site-functions"
fpath+="$HOME/.nix-profile/share/zsh/$ZSH_VERSION/functions"
@ -299,41 +323,17 @@ in
${cfg.initExtra}
# Environment variables
${optionalString (config.home.sessionVariableSetter != "pam") ''
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
''}
${envVarsStr}
# Aliases
${aliasesStr}
'';
}
(mkIf cfg.oh-my-zsh.enable {
programs.zsh.sessionVariables = {
ZSH = "${pkgs.oh-my-zsh}/share/oh-my-zsh";
ZSH_CACHE_DIR = "\${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh";
};
})
(mkIf (cfg.profileExtra != "") {
home.file."${relToDotDir ".zprofile"}".text = cfg.profileExtra;
})
(mkIf (cfg.loginExtra != "") {
home.file."${relToDotDir ".zlogin"}".text = cfg.loginExtra;
})
(mkIf (cfg.logoutExtra != "") {
home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra;
})
(mkIf (cfg.dotDir != null) {
programs.zsh.sessionVariables.ZDOTDIR = zdotdir;
# When dotDir is set, only use ~/.zshenv to source ZDOTDIR/.zshenv,
# This is so that if ZDOTDIR happens to be
# already set correctly (by e.g. spawning a zsh inside a zsh), all env
# vars still get exported
home.file.".zshenv".text = ''
source ${zdotdir}/.zshenv
'';
})
(mkIf cfg.oh-my-zsh.enable {
# Oh-My-Zsh calls compinit during initialization,
# calling it twice causes sight start up slowdown