aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorNikita Uvarov <uv.nikita@gmail.com>2017-10-12 13:20:23 +0200
committerNikita Uvarov <uv.nikita@gmail.com>2017-10-12 14:14:06 +0200
commit691eea9b4507778334cfb48913964c659d3560de (patch)
treeb64480bf8ca8ea161cea207ac9332fb553c06b3c /modules
parent7e6f3364bcf0a0ec838aa4853f550a9a7b5ed027 (diff)
zsh: add sessionVariables option
Diffstat (limited to 'modules')
-rw-r--r--modules/misc/news.nix11
-rw-r--r--modules/programs/zsh.nix40
2 files changed, 33 insertions, 18 deletions
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index f0a41d7c143..18c7f9a8f57 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -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.
+ '';
+ }
];
};
}
diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix
index c7ad7702311..aed6fd40180 100644
--- a/modules/programs/zsh.nix
+++ b/modules/programs/zsh.nix
@@ -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,