mirror of
https://github.com/nix-community/home-manager
synced 2024-11-16 16:19:44 +01:00
zsh: add sessionVariables option
This commit is contained in:
parent
7e6f3364bc
commit
691eea9b45
2 changed files with 33 additions and 18 deletions
|
@ -317,6 +317,17 @@ in
|
||||||
using NixOS then you do not need to enable this option.
|
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.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,11 @@ let
|
||||||
mapAttrsToList export vars
|
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" (
|
aliasesStr = concatStringsSep "\n" (
|
||||||
mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
||||||
|
@ -36,7 +40,7 @@ let
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = relToDotDir ".zsh_history";
|
default = relToDotDir ".zsh_history";
|
||||||
defaultText = ".zsh_history"; # Manual fails to build without this
|
defaultText = ".zsh_history";
|
||||||
description = "History file location";
|
description = "History file location";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,6 +171,15 @@ in
|
||||||
description = "Options related to commands history configuration.";
|
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 {
|
initExtra = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
|
@ -217,6 +230,9 @@ in
|
||||||
++ 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 = ''
|
||||||
|
${envVarsStr}
|
||||||
|
'';
|
||||||
|
|
||||||
home.file."${relToDotDir ".zshrc"}".text = ''
|
home.file."${relToDotDir ".zshrc"}".text = ''
|
||||||
${export "HISTSIZE" cfg.history.size}
|
${export "HISTSIZE" cfg.history.size}
|
||||||
|
@ -268,27 +284,15 @@ in
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
(mkIf (cfg.dotDir != null) {
|
(mkIf (cfg.dotDir != null) {
|
||||||
home.sessionVariables.ZDOTDIR = zdotdir;
|
programs.zsh.sessionVariables.ZDOTDIR = zdotdir;
|
||||||
})
|
|
||||||
(mkIf (config.home.sessionVariableSetter == "zsh" && cfg.dotDir == null) {
|
# When dotDir is set, only use ~/.zshenv to source ZDOTDIR/.zshenv,
|
||||||
home.file.".zshenv".text = ''
|
# This is so that if ZDOTDIR happens to be
|
||||||
${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
|
|
||||||
# already set correctly (by e.g. spawning a zsh inside a zsh), all env
|
# already set correctly (by e.g. spawning a zsh inside a zsh), all env
|
||||||
# vars still get exported
|
# vars still get exported
|
||||||
home.file.".zshenv".text = ''
|
home.file.".zshenv".text = ''
|
||||||
${export "ZDOTDIR" zdotdir}
|
|
||||||
source ${zdotdir}/.zshenv
|
source ${zdotdir}/.zshenv
|
||||||
'';
|
'';
|
||||||
|
|
||||||
home.file."${relToDotDir ".zshenv"}".text = ''
|
|
||||||
${toEnvVarsStr
|
|
||||||
(builtins.removeAttrs config.home.sessionVariables [ "ZDOTDIR" ])}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
(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,
|
||||||
|
|
Loading…
Reference in a new issue