2013-09-18 04:35:58 +01:00
|
|
|
# This module defines global configuration for the zshell.
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfge = config.environment;
|
|
|
|
|
|
|
|
cfg = config.programs.zsh;
|
|
|
|
|
|
|
|
zshAliases = concatStringsSep "\n" (
|
|
|
|
mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.zsh = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2016-09-04 15:30:07 +01:00
|
|
|
Whether to configure zsh as an interactive shell. To enable zsh for
|
|
|
|
a particular user, use the <option>users.users.<name?>.shell</option>
|
|
|
|
option for that user. To enable zsh system-wide use the
|
|
|
|
<option>users.defaultUserShell</option> option.
|
2013-09-18 04:35:58 +01:00
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
shellAliases = mkOption {
|
|
|
|
default = config.environment.shellAliases;
|
|
|
|
description = ''
|
|
|
|
Set of aliases for zsh shell. See <option>environment.shellAliases</option>
|
|
|
|
for an option format description.
|
|
|
|
'';
|
|
|
|
type = types.attrs; # types.attrsOf types.stringOrPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
shellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during zsh shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
loginShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during zsh login shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during interactive zsh shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
promptInit = mkOption {
|
|
|
|
default = ''
|
|
|
|
autoload -U promptinit && promptinit && prompt walters
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the zsh prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2015-11-24 23:04:17 +00:00
|
|
|
enableCompletion = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable zsh completion for all interactive zsh shells.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2016-10-02 23:07:23 +01:00
|
|
|
enableSyntaxHighlighting = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable zsh-syntax-highlighting
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2017-01-11 06:00:48 +00:00
|
|
|
|
|
|
|
enableAutosuggestions = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable zsh-autosuggestions
|
|
|
|
'';
|
|
|
|
};
|
2016-10-02 23:07:23 +01:00
|
|
|
|
2017-04-23 12:58:07 +01:00
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
programs.zsh = {
|
|
|
|
|
|
|
|
shellInit = ''
|
2013-09-24 09:58:01 +01:00
|
|
|
. ${config.system.build.setEnvironment}
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
${cfge.shellInit}
|
|
|
|
'';
|
|
|
|
|
|
|
|
loginShellInit = cfge.loginShellInit;
|
|
|
|
|
|
|
|
interactiveShellInit = ''
|
2016-01-12 07:38:03 +00:00
|
|
|
# history defaults
|
2016-09-27 20:18:29 +01:00
|
|
|
SAVEHIST=2000
|
|
|
|
HISTSIZE=2000
|
|
|
|
HISTFILE=$HOME/.zsh_history
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2015-01-07 10:53:38 +00:00
|
|
|
setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK
|
2015-11-24 23:04:17 +00:00
|
|
|
|
|
|
|
# Tell zsh how to find installed completions
|
|
|
|
for p in ''${(z)NIX_PROFILES}; do
|
|
|
|
fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions)
|
|
|
|
done
|
|
|
|
|
|
|
|
${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""}
|
2016-07-29 11:36:06 +01:00
|
|
|
|
2016-10-02 23:07:23 +01:00
|
|
|
${optionalString (cfg.enableSyntaxHighlighting)
|
|
|
|
"source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
|
|
|
}
|
|
|
|
|
2017-01-11 06:00:48 +00:00
|
|
|
${optionalString (cfg.enableAutosuggestions)
|
|
|
|
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
|
|
|
}
|
|
|
|
|
2017-01-11 20:05:27 +00:00
|
|
|
${zshAliases}
|
|
|
|
${cfg.promptInit}
|
|
|
|
|
|
|
|
${cfge.interactiveShellInit}
|
|
|
|
|
2016-07-29 11:36:06 +01:00
|
|
|
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
|
2013-09-18 04:35:58 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."zshenv".text =
|
|
|
|
''
|
|
|
|
# /etc/zshenv: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for all shells.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
2014-01-31 22:53:28 +00:00
|
|
|
# But don't clobber the environment of interactive non-login children!
|
2013-09-18 04:35:58 +01:00
|
|
|
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
|
2014-01-31 22:53:28 +00:00
|
|
|
export __ETC_ZSHENV_SOURCED=1
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
${cfg.shellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshenv.local; then
|
|
|
|
. /etc/zshenv.local
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.etc."zprofile".text =
|
|
|
|
''
|
|
|
|
# /etc/zprofile: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for login shells.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi
|
|
|
|
__ETC_ZPROFILE_SOURCED=1
|
|
|
|
|
|
|
|
${cfg.loginShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zprofile.local; then
|
|
|
|
. /etc/zprofile.local
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.etc."zshrc".text =
|
|
|
|
''
|
|
|
|
# /etc/zshrc: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for interactive shells.
|
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi
|
|
|
|
__ETC_ZSHRC_SOURCED=1
|
|
|
|
|
|
|
|
. /etc/zinputrc
|
|
|
|
|
|
|
|
${cfg.interactiveShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshrc.local; then
|
|
|
|
. /etc/zshrc.local
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.etc."zinputrc".source = ./zinputrc;
|
|
|
|
|
2015-11-24 23:04:17 +00:00
|
|
|
environment.systemPackages = [ pkgs.zsh ]
|
2016-10-02 23:07:23 +01:00
|
|
|
++ optional cfg.enableCompletion pkgs.nix-zsh-completions
|
|
|
|
++ optional cfg.enableSyntaxHighlighting pkgs.zsh-syntax-highlighting;
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2015-11-26 00:49:10 +00:00
|
|
|
environment.pathsToLink = optional cfg.enableCompletion "/share/zsh";
|
|
|
|
|
2014-04-29 17:57:04 +01:00
|
|
|
#users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh";
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
environment.shells =
|
|
|
|
[ "/run/current-system/sw/bin/zsh"
|
|
|
|
"/var/run/current-system/sw/bin/zsh"
|
|
|
|
"${pkgs.zsh}/bin/zsh"
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|