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" (
|
2018-10-12 14:58:35 +01:00
|
|
|
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
|
2019-04-24 04:48:22 +01:00
|
|
|
(filterAttrs (k: v: v != null) cfg.shellAliases)
|
2013-09-18 04:35:58 +01:00
|
|
|
);
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
zshStartupNotes = ''
|
|
|
|
# Note that generated /etc/zprofile and /etc/zshrc files do a lot of
|
|
|
|
# non-standard setup to make zsh usable with no configuration by default.
|
|
|
|
#
|
|
|
|
# Which means that unless you explicitly meticulously override everything
|
|
|
|
# generated, interactions between your ~/.zshrc and these files are likely
|
|
|
|
# to be rather surprising.
|
|
|
|
#
|
|
|
|
# Note however, that you can disable loading of the generated /etc/zprofile
|
|
|
|
# and /etc/zshrc (you can't disable loading of /etc/zshenv, but it is
|
|
|
|
# designed to not set anything surprising) by setting `no_global_rcs` option
|
|
|
|
# in ~/.zshenv:
|
|
|
|
#
|
|
|
|
# echo setopt no_global_rcs >> ~/.zshenv
|
|
|
|
#
|
|
|
|
# See "STARTUP/SHUTDOWN FILES" section of zsh(1) for more info.
|
|
|
|
'';
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
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 {
|
2018-08-04 04:32:30 +01:00
|
|
|
default = {};
|
2013-09-18 04:35:58 +01:00
|
|
|
description = ''
|
2018-08-04 04:32:30 +01:00
|
|
|
Set of aliases for zsh shell, which overrides <option>environment.shellAliases</option>.
|
2017-09-30 07:08:42 +01:00
|
|
|
See <option>environment.shellAliases</option> for an option format description.
|
2013-09-18 04:35:58 +01:00
|
|
|
'';
|
2018-10-12 14:58:35 +01:00
|
|
|
type = with types; attrsOf (nullOr (either str path));
|
2013-09-18 04:35:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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 = ''
|
2019-08-24 06:48:57 +01:00
|
|
|
# Note that to manually override this in ~/.zshrc you should run `prompt off`
|
|
|
|
# before setting your PS1 and etc. Otherwise this will likely to interact with
|
|
|
|
# your ~/.zshrc configuration in unexpected ways as the default prompt sets
|
|
|
|
# a lot of different prompt variables.
|
2019-08-22 01:46:20 +01:00
|
|
|
autoload -U promptinit && promptinit && prompt walters && setopt prompt_sp
|
2013-09-18 04:35:58 +01:00
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the zsh prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2019-03-18 14:07:25 +00:00
|
|
|
histSize = mkOption {
|
|
|
|
default = 2000;
|
|
|
|
description = ''
|
|
|
|
Change history size.
|
|
|
|
'';
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
histFile = mkOption {
|
|
|
|
default = "$HOME/.zsh_history";
|
|
|
|
description = ''
|
|
|
|
Change history file.
|
|
|
|
'';
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
setOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [
|
|
|
|
"HIST_IGNORE_DUPS" "SHARE_HISTORY" "HIST_FCNTL_LOCK"
|
|
|
|
];
|
|
|
|
example = [ "EXTENDED_HISTORY" "RM_STAR_WAIT" ];
|
|
|
|
description = ''
|
2019-08-24 06:48:57 +01:00
|
|
|
Configure zsh options. See
|
|
|
|
<citerefentry><refentrytitle>zshoptions</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
|
2019-03-18 14:07:25 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-24 23:04:17 +00:00
|
|
|
enableCompletion = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable zsh completion for all interactive zsh shells.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2018-08-17 11:57:33 +01:00
|
|
|
|
|
|
|
enableGlobalCompInit = mkOption {
|
|
|
|
default = cfg.enableCompletion;
|
|
|
|
description = ''
|
|
|
|
Enable execution of compinit call for all interactive zsh shells.
|
|
|
|
|
2018-08-27 10:43:31 +01:00
|
|
|
This option can be disabled if the user wants to extend its
|
2018-08-17 11:57:33 +01:00
|
|
|
<literal>fpath</literal> and a custom <literal>compinit</literal>
|
|
|
|
call in the local config is required.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-08-04 04:32:30 +01:00
|
|
|
programs.zsh.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.zshenv.text =
|
2013-09-18 04:35:58 +01:00
|
|
|
''
|
|
|
|
# /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.
|
|
|
|
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
|
2020-02-18 13:30:02 +00:00
|
|
|
__ETC_ZSHENV_SOURCED=1
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2018-08-29 17:05:48 +01:00
|
|
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
|
|
|
|
. ${config.system.build.setEnvironment}
|
|
|
|
fi
|
2018-05-19 09:14:45 +01:00
|
|
|
|
2019-08-24 06:36:02 +01:00
|
|
|
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Tell zsh how to find installed completions.
|
2019-08-24 06:36:02 +01:00
|
|
|
for p in ''${(z)NIX_PROFILES}; do
|
|
|
|
fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions)
|
|
|
|
done
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup custom shell init stuff.
|
2017-05-09 16:07:18 +01:00
|
|
|
${cfge.shellInit}
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
${cfg.shellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshenv.local; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/zshenv.local
|
2013-09-18 04:35:58 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.zprofile.text =
|
2013-09-18 04:35:58 +01:00
|
|
|
''
|
|
|
|
# /etc/zprofile: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for login shells.
|
2019-08-24 06:48:57 +01:00
|
|
|
#
|
|
|
|
${zshStartupNotes}
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi
|
|
|
|
__ETC_ZPROFILE_SOURCED=1
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup custom login shell init stuff.
|
2017-05-09 16:07:18 +01:00
|
|
|
${cfge.loginShellInit}
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
${cfg.loginShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zprofile.local; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/zprofile.local
|
2013-09-18 04:35:58 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.zshrc.text =
|
2013-09-18 04:35:58 +01:00
|
|
|
''
|
|
|
|
# /etc/zshrc: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
# This file is read for interactive shells.
|
2019-08-24 06:48:57 +01:00
|
|
|
#
|
|
|
|
${zshStartupNotes}
|
2013-09-18 04:35:58 +01:00
|
|
|
|
|
|
|
# Only execute this file once per shell.
|
|
|
|
if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi
|
|
|
|
__ETC_ZSHRC_SOURCED=1
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
${optionalString (cfg.setOptions != []) ''
|
|
|
|
# Set zsh options.
|
|
|
|
setopt ${concatStringsSep " " cfg.setOptions}
|
|
|
|
''}
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup command line history.
|
|
|
|
# Don't export these, otherwise other shells (bash) will try to use same HISTFILE.
|
2019-03-21 15:24:20 +00:00
|
|
|
SAVEHIST=${toString cfg.histSize}
|
|
|
|
HISTSIZE=${toString cfg.histSize}
|
|
|
|
HISTFILE=${cfg.histFile}
|
2017-05-09 16:07:18 +01:00
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Configure sane keyboard defaults.
|
|
|
|
. /etc/zinputrc
|
2017-08-25 09:34:21 +01:00
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
${optionalString cfg.enableGlobalCompInit ''
|
|
|
|
# Enable autocompletion.
|
|
|
|
autoload -U compinit && compinit
|
|
|
|
''}
|
2017-05-09 16:07:18 +01:00
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup custom interactive shell init stuff.
|
2017-05-09 16:07:18 +01:00
|
|
|
${cfge.interactiveShellInit}
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
${cfg.interactiveShellInit}
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup aliases.
|
2017-08-18 20:48:38 +01:00
|
|
|
${zshAliases}
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Setup prompt.
|
2017-05-09 16:07:18 +01:00
|
|
|
${cfg.promptInit}
|
|
|
|
|
2019-08-24 06:48:57 +01:00
|
|
|
# Disable some features to support TRAMP.
|
2019-08-22 01:46:20 +01:00
|
|
|
if [ "$TERM" = dumb ]; then
|
|
|
|
unsetopt zle prompt_cr prompt_subst
|
|
|
|
unset RPS1 RPROMPT
|
|
|
|
PS1='$ '
|
|
|
|
PROMPT='$ '
|
|
|
|
fi
|
|
|
|
|
2013-09-18 04:35:58 +01:00
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshrc.local; then
|
2018-08-29 17:05:53 +01:00
|
|
|
. /etc/zshrc.local
|
2013-09-18 04:35:58 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
environment.etc.zinputrc.source = ./zinputrc;
|
2013-09-18 04:35:58 +01:00
|
|
|
|
2015-11-24 23:04:17 +00:00
|
|
|
environment.systemPackages = [ pkgs.zsh ]
|
2017-04-23 20:17:31 +01:00
|
|
|
++ optional cfg.enableCompletion pkgs.nix-zsh-completions;
|
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"
|
|
|
|
"${pkgs.zsh}/bin/zsh"
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|