1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19:45 +01:00

zsh: add sessionVariables option

This commit is contained in:
Nikita Uvarov 2017-10-12 13:20:23 +02:00
parent 7e6f3364bc
commit 691eea9b45
No known key found for this signature in database
GPG key ID: F7A5FB3A7C10EF96
2 changed files with 33 additions and 18 deletions

View file

@ -317,6 +317,17 @@ in
using NixOS then you do not need to enable this option.
'';
}
{
time = "2017-10-12T11:21:45+00:00";
condition = config.programs.zsh.enable;
message = ''
A new option in zsh module is available: 'programs.zsh.sessionVariables'.
This option can be used to set zsh specific session variables which
will be set only on zsh launch.
'';
}
];
};
}

View file

@ -17,7 +17,11 @@ let
mapAttrsToList export vars
);
envVarsStr = toEnvVarsStr config.home.sessionVariables;
envVars = cfg.sessionVariables // (
if config.home.sessionVariableSetter == "zsh" then config.home.sessionVariables else {}
);
envVarsStr = toEnvVarsStr envVars;
aliasesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
@ -36,7 +40,7 @@ let
path = mkOption {
type = types.str;
default = relToDotDir ".zsh_history";
defaultText = ".zsh_history"; # Manual fails to build without this
defaultText = ".zsh_history";
description = "History file location";
};
@ -167,6 +171,15 @@ in
description = "Options related to commands history configuration.";
};
sessionVariables = mkOption {
default = {};
type = types.attrs;
example = { ZSH_CACHE_DIR = "$HOME/.cache/zsh"; };
description = ''
Environment variables that will be set for zsh session.
'';
};
initExtra = mkOption {
default = "";
type = types.lines;
@ -217,6 +230,9 @@ in
++ optional cfg.enableCompletion nix-zsh-completions
++ optional cfg.oh-my-zsh.enable oh-my-zsh;
home.file."${relToDotDir ".zshenv"}".text = ''
${envVarsStr}
'';
home.file."${relToDotDir ".zshrc"}".text = ''
${export "HISTSIZE" cfg.history.size}
@ -268,27 +284,15 @@ in
'';
}
(mkIf (cfg.dotDir != null) {
home.sessionVariables.ZDOTDIR = zdotdir;
})
(mkIf (config.home.sessionVariableSetter == "zsh" && cfg.dotDir == null) {
home.file.".zshenv".text = ''
${envVarsStr}
'';
})
(mkIf (config.home.sessionVariableSetter == "zsh" && cfg.dotDir != null) {
# When dotDir is set, only use ~/.zshenv to export ZDOTDIR,
# $ZDOTDIR/.zshenv for the rest. This is so that if ZDOTDIR happens to be
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 = ''
${export "ZDOTDIR" zdotdir}
source ${zdotdir}/.zshenv
'';
home.file."${relToDotDir ".zshenv"}".text = ''
${toEnvVarsStr
(builtins.removeAttrs config.home.sessionVariables [ "ZDOTDIR" ])}
'';
})
(mkIf cfg.oh-my-zsh.enable {
# Oh-My-Zsh calls compinit during initialization,