zsh: move session variables export to zshrc
Unlike .zshenv, .zshrc file is sourced only by interactive shells.
This commit is contained in:
parent
91a98f919d
commit
fa6f697dbb
|
@ -171,10 +171,8 @@ in
|
||||||
sessionVariables = mkOption {
|
sessionVariables = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
example = { ZSH_CACHE_DIR = "$HOME/.cache/zsh"; };
|
example = { MAILCHECK = 30; };
|
||||||
description = ''
|
description = "Environment variables that will be set for zsh session.";
|
||||||
Environment variables that will be set for zsh session.
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
initExtra = mkOption {
|
initExtra = mkOption {
|
||||||
|
@ -240,20 +238,46 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
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 ]
|
home.packages = with pkgs; [ zsh ]
|
||||||
++ optional cfg.enableCompletion nix-zsh-completions
|
++ optional cfg.enableCompletion nix-zsh-completions
|
||||||
++ optional cfg.oh-my-zsh.enable oh-my-zsh;
|
++ 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 = ''
|
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/site-functions"
|
||||||
fpath+="$HOME/.nix-profile/share/zsh/$ZSH_VERSION/functions"
|
fpath+="$HOME/.nix-profile/share/zsh/$ZSH_VERSION/functions"
|
||||||
|
|
||||||
|
@ -299,41 +323,17 @@ in
|
||||||
|
|
||||||
${cfg.initExtra}
|
${cfg.initExtra}
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
${optionalString (config.home.sessionVariableSetter != "pam") ''
|
||||||
|
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
||||||
|
''}
|
||||||
|
${envVarsStr}
|
||||||
|
|
||||||
|
# Aliases
|
||||||
${aliasesStr}
|
${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 {
|
(mkIf cfg.oh-my-zsh.enable {
|
||||||
# Oh-My-Zsh calls compinit during initialization,
|
# Oh-My-Zsh calls compinit during initialization,
|
||||||
# calling it twice causes sight start up slowdown
|
# calling it twice causes sight start up slowdown
|
||||||
|
|
Loading…
Reference in a new issue