2017-08-15 11:54:33 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.zsh;
|
|
|
|
|
2017-09-12 18:01:02 +00:00
|
|
|
relToDotDir = file: (optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
|
|
|
|
|
|
|
|
pluginsDir = if cfg.dotDir != null then
|
|
|
|
relToDotDir "plugins" else ".zsh/plugins";
|
|
|
|
|
2018-12-13 14:23:27 +00:00
|
|
|
envVarsStr = config.lib.zsh.exportAll cfg.sessionVariables;
|
2018-12-13 14:25:09 +00:00
|
|
|
localVarsStr = config.lib.zsh.defineAll cfg.localVariables;
|
2017-09-17 22:26:42 +00:00
|
|
|
|
|
|
|
aliasesStr = concatStringsSep "\n" (
|
2019-02-28 10:29:16 +00:00
|
|
|
mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}") cfg.shellAliases
|
2017-09-17 22:26:42 +00:00
|
|
|
);
|
|
|
|
|
2020-07-20 17:54:30 +00:00
|
|
|
globalAliasesStr = concatStringsSep "\n" (
|
|
|
|
mapAttrsToList (k: v: "alias -g ${k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases
|
|
|
|
);
|
|
|
|
|
2020-10-27 11:46:26 +00:00
|
|
|
dirHashesStr = concatStringsSep "\n" (
|
|
|
|
mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes
|
|
|
|
);
|
|
|
|
|
2017-09-17 22:26:42 +00:00
|
|
|
zdotdir = "$HOME/" + cfg.dotDir;
|
2017-09-12 18:01:02 +00:00
|
|
|
|
2018-12-16 14:23:08 +00:00
|
|
|
bindkeyCommands = {
|
|
|
|
emacs = "bindkey -e";
|
|
|
|
viins = "bindkey -v";
|
|
|
|
vicmd = "bindkey -a";
|
|
|
|
};
|
|
|
|
|
2019-10-28 10:11:44 +00:00
|
|
|
stateVersion = config.home.stateVersion;
|
|
|
|
|
2018-01-12 16:23:58 +00:00
|
|
|
historyModule = types.submodule ({ config, ... }: {
|
2017-08-23 10:51:54 +00:00
|
|
|
options = {
|
|
|
|
size = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10000;
|
|
|
|
description = "Number of history lines to keep.";
|
|
|
|
};
|
|
|
|
|
2018-01-12 16:23:58 +00:00
|
|
|
save = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
defaultText = 10000;
|
|
|
|
default = config.size;
|
|
|
|
description = "Number of history lines to save.";
|
|
|
|
};
|
|
|
|
|
2017-08-23 10:51:54 +00:00
|
|
|
path = mkOption {
|
|
|
|
type = types.str;
|
2019-10-28 10:11:44 +00:00
|
|
|
default = if versionAtLeast stateVersion "20.03"
|
|
|
|
then "$HOME/.zsh_history"
|
|
|
|
else relToDotDir ".zsh_history";
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression ''
|
2021-05-05 21:19:12 +00:00
|
|
|
"$HOME/.zsh_history" if state version ≥ 20.03,
|
|
|
|
"$ZDOTDIR/.zsh_history" otherwise
|
|
|
|
'';
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''"''${config.xdg.dataHome}/zsh/zsh_history"'';
|
2017-08-23 10:51:54 +00:00
|
|
|
description = "History file location";
|
|
|
|
};
|
|
|
|
|
2021-05-01 20:33:45 +00:00
|
|
|
ignorePatterns = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''[ "rm *" "pkill *" ]'';
|
2021-05-01 20:33:45 +00:00
|
|
|
description = ''
|
|
|
|
Do not enter command lines into the history list
|
|
|
|
if they match any one of the given shell patterns.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-23 10:51:54 +00:00
|
|
|
ignoreDups = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Do not enter command lines into the history list
|
|
|
|
if they are duplicates of the previous event.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-01-22 19:08:21 +00:00
|
|
|
ignoreSpace = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Do not enter command lines into the history list
|
|
|
|
if the first character is a space.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-06-06 20:32:46 +00:00
|
|
|
expireDuplicatesFirst = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2018-06-09 08:29:02 +00:00
|
|
|
description = "Expire duplicates first.";
|
2018-06-06 20:32:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extended = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2018-06-09 08:29:02 +00:00
|
|
|
description = "Save timestamp into the history file.";
|
2018-06-06 20:32:46 +00:00
|
|
|
};
|
|
|
|
|
2017-08-23 10:51:54 +00:00
|
|
|
share = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Share command history between zsh sessions.";
|
|
|
|
};
|
|
|
|
};
|
2018-01-12 16:23:58 +00:00
|
|
|
});
|
2017-08-23 10:51:54 +00:00
|
|
|
|
2017-09-04 14:39:14 +00:00
|
|
|
pluginModule = types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
src = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Path to the plugin folder.
|
|
|
|
|
|
|
|
Will be added to <envar>fpath</envar> and <envar>PATH</envar>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the plugin.
|
|
|
|
|
|
|
|
Don't forget to add <option>file</option>
|
|
|
|
if the script name does not follow convention.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
file = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The plugin script to source.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.file = mkDefault "${config.name}.plugin.zsh";
|
|
|
|
});
|
|
|
|
|
2017-09-07 21:57:13 +00:00
|
|
|
ohMyZshModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
enable = mkEnableOption "oh-my-zsh";
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [ "git" "sudo" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
List of oh-my-zsh plugins
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
custom = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.str;
|
|
|
|
example = "$HOME/my_customizations";
|
|
|
|
description = ''
|
2017-09-30 10:10:52 +00:00
|
|
|
Path to a custom oh-my-zsh package to override config of
|
|
|
|
oh-my-zsh. See <link xlink:href="https://github.com/robbyrussell/oh-my-zsh/wiki/Customization"/>
|
|
|
|
for more information.
|
2017-09-07 21:57:13 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
theme = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = "robbyrussell";
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Name of the theme to be used by oh-my-zsh.
|
|
|
|
'';
|
|
|
|
};
|
2020-03-25 14:40:42 +00:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra settings for plugins.
|
|
|
|
'';
|
|
|
|
};
|
2017-09-07 21:57:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.zsh = {
|
|
|
|
enable = mkEnableOption "Z shell (Zsh)";
|
|
|
|
|
2019-05-10 19:38:36 +00:00
|
|
|
autocd = mkOption {
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Automatically enter into a directory if typed directly into shell.
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
};
|
|
|
|
|
2020-08-14 20:36:23 +00:00
|
|
|
cdpath = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
List of paths to autocomplete calls to `cd`.
|
|
|
|
'';
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
2017-09-12 18:01:02 +00:00
|
|
|
dotDir = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = ".config/zsh";
|
|
|
|
description = ''
|
|
|
|
Directory where the zsh configuration and more should be located,
|
|
|
|
relative to the users home directory. The default is the home
|
|
|
|
directory.
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
shellAliases = mkOption {
|
|
|
|
default = {};
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-02-26 21:44:54 +00:00
|
|
|
{
|
|
|
|
ll = "ls -l";
|
|
|
|
".." = "cd ..";
|
|
|
|
}
|
|
|
|
'';
|
2017-08-15 11:54:33 +00:00
|
|
|
description = ''
|
|
|
|
An attribute set that maps aliases (the top level attribute names in
|
|
|
|
this option) to command strings or directly to build outputs.
|
|
|
|
'';
|
2019-03-31 11:22:27 +00:00
|
|
|
type = types.attrsOf types.str;
|
2017-08-15 11:54:33 +00:00
|
|
|
};
|
|
|
|
|
2020-07-20 17:54:30 +00:00
|
|
|
shellGlobalAliases = mkOption {
|
|
|
|
default = {};
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-07-20 17:54:30 +00:00
|
|
|
{
|
|
|
|
UUID = "$(uuidgen | tr -d \\n)";
|
|
|
|
G = "| grep";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
2022-08-25 22:07:08 +00:00
|
|
|
Similar to <xref linkend="opt-programs.zsh.shellAliases"/>,
|
2020-07-20 23:10:54 +00:00
|
|
|
but are substituted anywhere on a line.
|
2020-07-20 17:54:30 +00:00
|
|
|
'';
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
};
|
|
|
|
|
2020-10-27 11:46:26 +00:00
|
|
|
dirHashes = mkOption {
|
|
|
|
default = {};
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-10-27 11:46:26 +00:00
|
|
|
{
|
|
|
|
docs = "$HOME/Documents";
|
|
|
|
vids = "$HOME/Videos";
|
|
|
|
dl = "$HOME/Downloads";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
An attribute set that adds to named directory hash table.
|
|
|
|
'';
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
};
|
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
enableCompletion = mkOption {
|
|
|
|
default = true;
|
2018-01-29 10:30:26 +00:00
|
|
|
description = ''
|
|
|
|
Enable zsh completion. Don't forget to add
|
2019-02-24 19:40:45 +00:00
|
|
|
<programlisting language="nix">
|
2018-01-29 10:30:26 +00:00
|
|
|
environment.pathsToLink = [ "/share/zsh" ];
|
|
|
|
</programlisting>
|
|
|
|
to your system configuration to get completion for system packages (e.g. systemd).
|
|
|
|
'';
|
2017-08-15 11:54:33 +00:00
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2021-06-09 15:15:10 +00:00
|
|
|
completionInit = mkOption {
|
|
|
|
default = "autoload -U compinit && compinit";
|
|
|
|
description = "Initialization commands to run when completion is enabled.";
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
enableAutosuggestions = mkOption {
|
|
|
|
default = false;
|
2017-08-23 10:51:54 +00:00
|
|
|
description = "Enable zsh autosuggestions";
|
|
|
|
};
|
|
|
|
|
2021-06-28 06:04:38 +00:00
|
|
|
enableSyntaxHighlighting = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Enable zsh syntax highlighting";
|
|
|
|
};
|
|
|
|
|
2017-08-23 10:51:54 +00:00
|
|
|
history = mkOption {
|
|
|
|
type = historyModule;
|
|
|
|
default = {};
|
|
|
|
description = "Options related to commands history configuration.";
|
2017-08-15 11:54:33 +00:00
|
|
|
};
|
|
|
|
|
2018-12-16 14:23:08 +00:00
|
|
|
defaultKeymap = mkOption {
|
2018-12-23 10:53:01 +00:00
|
|
|
type = types.nullOr (types.enum (attrNames bindkeyCommands));
|
2018-12-16 14:23:08 +00:00
|
|
|
default = null;
|
|
|
|
example = "emacs";
|
2018-12-23 10:53:01 +00:00
|
|
|
description = "The default base keymap to use.";
|
2018-12-16 14:23:08 +00:00
|
|
|
};
|
|
|
|
|
2017-10-12 11:20:23 +00:00
|
|
|
sessionVariables = mkOption {
|
|
|
|
default = {};
|
2019-04-26 22:21:18 +00:00
|
|
|
type = types.attrs;
|
2018-01-25 13:13:44 +00:00
|
|
|
example = { MAILCHECK = 30; };
|
|
|
|
description = "Environment variables that will be set for zsh session.";
|
2017-10-12 11:20:23 +00:00
|
|
|
};
|
|
|
|
|
2019-07-23 19:40:41 +00:00
|
|
|
initExtraBeforeCompInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra commands that should be added to <filename>.zshrc</filename> before compinit.";
|
|
|
|
};
|
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
initExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2017-09-04 14:39:14 +00:00
|
|
|
description = "Extra commands that should be added to <filename>.zshrc</filename>.";
|
|
|
|
};
|
|
|
|
|
2020-08-17 01:50:29 +00:00
|
|
|
initExtraFirst = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Commands that should be added to top of <filename>.zshrc</filename>.";
|
|
|
|
};
|
|
|
|
|
2019-07-23 19:58:06 +00:00
|
|
|
envExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra commands that should be added to <filename>.zshenv</filename>.";
|
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:46 +00:00
|
|
|
profileExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra commands that should be added to <filename>.zprofile</filename>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
loginExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra commands that should be added to <filename>.zlogin</filename>.";
|
|
|
|
};
|
|
|
|
|
|
|
|
logoutExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra commands that should be added to <filename>.zlogout</filename>.";
|
|
|
|
};
|
|
|
|
|
2017-09-04 14:39:14 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf pluginModule;
|
|
|
|
default = [];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2017-09-04 14:39:14 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
# will source zsh-autosuggestions.plugin.zsh
|
|
|
|
name = "zsh-autosuggestions";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "zsh-users";
|
|
|
|
repo = "zsh-autosuggestions";
|
|
|
|
rev = "v0.4.0";
|
|
|
|
sha256 = "0z6i9wjjklb4lvr7zjhbphibsyx51psv50gm07mbb0kj9058j6kc";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "enhancd";
|
|
|
|
file = "init.sh";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "b4b4r07";
|
|
|
|
repo = "enhancd";
|
|
|
|
rev = "v2.2.1";
|
|
|
|
sha256 = "0iqa9j09fwm6nj5rpip87x3hnvbbz9w9ajgm6wkrd5fls8fn8i5g";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = "Plugins to source in <filename>.zshrc</filename>.";
|
2017-08-15 11:54:33 +00:00
|
|
|
};
|
2017-09-07 21:57:13 +00:00
|
|
|
|
|
|
|
oh-my-zsh = mkOption {
|
|
|
|
type = ohMyZshModule;
|
|
|
|
default = {};
|
|
|
|
description = "Options to configure oh-my-zsh.";
|
|
|
|
};
|
2018-12-13 14:25:09 +00:00
|
|
|
|
|
|
|
localVariables = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
example = { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=["dir" "vcs"]; };
|
|
|
|
description = ''
|
|
|
|
Extra local variables defined at the top of <filename>.zshrc</filename>.
|
|
|
|
'';
|
|
|
|
};
|
2017-08-15 11:54:33 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-09-17 22:26:42 +00:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2019-07-23 19:58:06 +00:00
|
|
|
(mkIf (cfg.envExtra != "") {
|
|
|
|
home.file."${relToDotDir ".zshenv"}".text = cfg.envExtra;
|
|
|
|
})
|
|
|
|
|
2018-01-25 13:13:44 +00:00
|
|
|
(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";
|
2019-08-08 13:24:23 +00:00
|
|
|
ZSH_CACHE_DIR="${config.xdg.cacheHome}/oh-my-zsh";
|
2018-01-25 13:13:44 +00:00
|
|
|
'';
|
|
|
|
})
|
|
|
|
|
|
|
|
(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
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
|
zsh: move sessionVariables from .zshrc to .zshenv (#2708)
This patch moves both home.sessionVariables and
programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally,
these two kinds of session variables will not be sourced more than
once to allow user-customized ones to take effect.
Before, session variables are in .zshrc, which causes non-interactive
shells to not be able to get those variables. For example, running a
command through SSH is in a non-interactive and non-login shell, which
suffers from this. With this patch, all kinds of shells can get
session variables.
The reason why these session variables are not moved to .zprofile is
that programs started by systemd user instances are not able to get
variables defined in that file. For example, GNOME
Terminal (gnome-terminal-server.service) is one of these programs and
doesn't get variables defined in .zprofile. As a result, the shells it
starts, which are interactive and non-login, do not get those
variables.
Fixes #2445
Related NixOS/nixpkgs#33219
Related NixOS/nixpkgs#45784
This file is not formatted before and is excluded by ./format, so I don't format it.
2022-02-17 09:20:56 +00:00
|
|
|
{
|
|
|
|
home.file."${relToDotDir ".zshenv"}".text = ''
|
|
|
|
# Environment variables
|
|
|
|
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
|
|
|
# Only source this once
|
|
|
|
if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then
|
|
|
|
export __HM_ZSH_SESS_VARS_SOURCED=1
|
|
|
|
${envVarsStr}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:26:42 +00:00
|
|
|
{
|
2017-09-07 21:57:13 +00:00
|
|
|
home.packages = with pkgs; [ zsh ]
|
|
|
|
++ optional cfg.enableCompletion nix-zsh-completions
|
|
|
|
++ optional cfg.oh-my-zsh.enable oh-my-zsh;
|
2017-08-15 11:54:33 +00:00
|
|
|
|
2017-09-12 18:01:02 +00:00
|
|
|
home.file."${relToDotDir ".zshrc"}".text = ''
|
2020-08-17 01:50:29 +00:00
|
|
|
${cfg.initExtraFirst}
|
|
|
|
|
2018-01-25 13:13:44 +00:00
|
|
|
typeset -U path cdpath fpath manpath
|
2018-01-29 10:30:26 +00:00
|
|
|
|
2020-08-14 20:36:23 +00:00
|
|
|
${optionalString (cfg.cdpath != []) ''
|
|
|
|
cdpath+=(${concatStringsSep " " cfg.cdpath})
|
|
|
|
''}
|
|
|
|
|
2018-01-29 10:30:26 +00:00
|
|
|
for profile in ''${(z)NIX_PROFILES}; do
|
|
|
|
fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions)
|
|
|
|
done
|
2017-09-05 12:21:57 +00:00
|
|
|
|
2017-08-23 11:06:19 +00:00
|
|
|
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
|
|
|
|
|
2018-12-23 10:53:01 +00:00
|
|
|
${optionalString (cfg.defaultKeymap != null) ''
|
|
|
|
# Use ${cfg.defaultKeymap} keymap as the default.
|
|
|
|
${getAttr cfg.defaultKeymap bindkeyCommands}
|
|
|
|
''}
|
2018-12-16 14:23:08 +00:00
|
|
|
|
2018-12-13 14:25:09 +00:00
|
|
|
${localVarsStr}
|
|
|
|
|
2019-07-23 19:40:41 +00:00
|
|
|
${cfg.initExtraBeforeCompInit}
|
|
|
|
|
2017-09-04 14:39:14 +00:00
|
|
|
${concatStrings (map (plugin: ''
|
2017-09-12 18:01:02 +00:00
|
|
|
path+="$HOME/${pluginsDir}/${plugin.name}"
|
|
|
|
fpath+="$HOME/${pluginsDir}/${plugin.name}"
|
2017-09-04 14:39:14 +00:00
|
|
|
'') cfg.plugins)}
|
|
|
|
|
2020-10-12 00:27:44 +00:00
|
|
|
# Oh-My-Zsh/Prezto calls compinit during initialization,
|
2021-02-09 02:11:56 +00:00
|
|
|
# calling it twice causes slight start up slowdown
|
2019-08-08 12:57:53 +00:00
|
|
|
# as all $fpath entries will be traversed again.
|
2020-10-12 00:27:44 +00:00
|
|
|
${optionalString (cfg.enableCompletion && !cfg.oh-my-zsh.enable && !cfg.prezto.enable)
|
2021-06-09 15:15:10 +00:00
|
|
|
cfg.completionInit
|
2019-08-08 12:57:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 18:01:02 +00:00
|
|
|
${optionalString cfg.enableAutosuggestions
|
2017-08-15 11:54:33 +00:00
|
|
|
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
|
|
|
}
|
|
|
|
|
2017-09-07 21:57:13 +00:00
|
|
|
${optionalString cfg.oh-my-zsh.enable ''
|
2020-03-25 14:40:42 +00:00
|
|
|
# oh-my-zsh extra settings for plugins
|
|
|
|
${cfg.oh-my-zsh.extraConfig}
|
2017-09-07 21:57:13 +00:00
|
|
|
# oh-my-zsh configuration generated by NixOS
|
|
|
|
${optionalString (cfg.oh-my-zsh.plugins != [])
|
|
|
|
"plugins=(${concatStringsSep " " cfg.oh-my-zsh.plugins})"
|
|
|
|
}
|
|
|
|
${optionalString (cfg.oh-my-zsh.custom != "")
|
|
|
|
"ZSH_CUSTOM=\"${cfg.oh-my-zsh.custom}\""
|
|
|
|
}
|
|
|
|
${optionalString (cfg.oh-my-zsh.theme != "")
|
|
|
|
"ZSH_THEME=\"${cfg.oh-my-zsh.theme}\""
|
|
|
|
}
|
|
|
|
source $ZSH/oh-my-zsh.sh
|
|
|
|
''}
|
|
|
|
|
2020-10-12 00:27:44 +00:00
|
|
|
${optionalString cfg.prezto.enable
|
2021-02-09 02:11:56 +00:00
|
|
|
(builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zshrc")}
|
2020-10-12 00:27:44 +00:00
|
|
|
|
2017-09-04 14:39:14 +00:00
|
|
|
${concatStrings (map (plugin: ''
|
2021-06-09 15:15:10 +00:00
|
|
|
if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then
|
2018-04-16 20:12:53 +00:00
|
|
|
source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"
|
|
|
|
fi
|
2017-09-04 14:39:14 +00:00
|
|
|
'') cfg.plugins)}
|
|
|
|
|
2018-01-12 16:23:58 +00:00
|
|
|
# History options should be set in .zshrc and after oh-my-zsh sourcing.
|
2020-10-19 19:20:37 +00:00
|
|
|
# See https://github.com/nix-community/home-manager/issues/177.
|
2018-01-12 10:24:08 +00:00
|
|
|
HISTSIZE="${toString cfg.history.size}"
|
2018-01-12 16:23:58 +00:00
|
|
|
SAVEHIST="${toString cfg.history.save}"
|
2021-05-01 20:33:45 +00:00
|
|
|
${optionalString (cfg.history.ignorePatterns != []) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
|
2019-10-28 10:11:44 +00:00
|
|
|
${if versionAtLeast config.home.stateVersion "20.03"
|
|
|
|
then ''HISTFILE="${cfg.history.path}"''
|
|
|
|
else ''HISTFILE="$HOME/${cfg.history.path}"''}
|
|
|
|
mkdir -p "$(dirname "$HISTFILE")"
|
2018-01-12 16:23:58 +00:00
|
|
|
|
|
|
|
setopt HIST_FCNTL_LOCK
|
|
|
|
${if cfg.history.ignoreDups then "setopt" else "unsetopt"} HIST_IGNORE_DUPS
|
2020-01-22 19:08:21 +00:00
|
|
|
${if cfg.history.ignoreSpace then "setopt" else "unsetopt"} HIST_IGNORE_SPACE
|
2018-06-06 20:32:46 +00:00
|
|
|
${if cfg.history.expireDuplicatesFirst then "setopt" else "unsetopt"} HIST_EXPIRE_DUPS_FIRST
|
2018-01-12 16:23:58 +00:00
|
|
|
${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY
|
2018-06-06 20:32:46 +00:00
|
|
|
${if cfg.history.extended then "setopt" else "unsetopt"} EXTENDED_HISTORY
|
2019-05-10 19:38:36 +00:00
|
|
|
${if cfg.autocd != null then "${if cfg.autocd then "setopt" else "unsetopt"} autocd" else ""}
|
2018-01-12 10:24:08 +00:00
|
|
|
|
2017-08-15 11:54:33 +00:00
|
|
|
${cfg.initExtra}
|
2017-09-07 20:21:00 +00:00
|
|
|
|
2018-01-25 13:13:44 +00:00
|
|
|
# Aliases
|
2017-09-07 20:21:00 +00:00
|
|
|
${aliasesStr}
|
2020-07-20 17:54:30 +00:00
|
|
|
|
|
|
|
# Global Aliases
|
|
|
|
${globalAliasesStr}
|
2020-10-27 11:46:26 +00:00
|
|
|
|
|
|
|
# Named Directory Hashes
|
|
|
|
${dirHashesStr}
|
2022-07-08 00:57:27 +00:00
|
|
|
|
|
|
|
${optionalString cfg.enableSyntaxHighlighting
|
|
|
|
# Load zsh-syntax-highlighting last, after all custom widgets have been created
|
|
|
|
# https://github.com/zsh-users/zsh-syntax-highlighting#faq
|
|
|
|
"source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
|
|
|
}
|
2017-08-15 11:54:33 +00:00
|
|
|
'';
|
2017-09-17 22:26:42 +00:00
|
|
|
}
|
2017-10-13 14:34:02 +00:00
|
|
|
|
2017-09-07 21:57:13 +00:00
|
|
|
(mkIf cfg.oh-my-zsh.enable {
|
2019-08-08 13:24:23 +00:00
|
|
|
# Make sure we create a cache directory since some plugins expect it to exist
|
2020-10-19 19:20:37 +00:00
|
|
|
# See: https://github.com/nix-community/home-manager/issues/761
|
2019-08-08 13:24:23 +00:00
|
|
|
home.file."${config.xdg.cacheHome}/oh-my-zsh/.keep".text = "";
|
2017-09-07 21:57:13 +00:00
|
|
|
})
|
2017-10-13 14:34:02 +00:00
|
|
|
|
2017-09-04 14:39:14 +00:00
|
|
|
(mkIf (cfg.plugins != []) {
|
|
|
|
# Many plugins require compinit to be called
|
|
|
|
# but allow the user to opt out.
|
|
|
|
programs.zsh.enableCompletion = mkDefault true;
|
|
|
|
|
2020-01-11 18:49:15 +00:00
|
|
|
home.file =
|
|
|
|
foldl' (a: b: a // b) {}
|
|
|
|
(map (plugin: { "${pluginsDir}/${plugin.name}".source = plugin.src; })
|
|
|
|
cfg.plugins);
|
2017-09-04 14:39:14 +00:00
|
|
|
})
|
2017-09-17 22:26:42 +00:00
|
|
|
]);
|
2017-08-15 11:54:33 +00:00
|
|
|
}
|