2013-09-18 05:35:58 +02:00
|
|
|
# This module defines global configuration for the zshell.
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-09-18 05:35:58 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-09-18 05:35:58 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfge = config.environment;
|
|
|
|
|
|
|
|
cfg = config.programs.zsh;
|
|
|
|
|
|
|
|
zshAliases = concatStringsSep "\n" (
|
2018-10-12 15:58:35 +02:00
|
|
|
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
|
|
|
|
(filterAttrs (k: v: !isNull v) cfg.shellAliases)
|
2013-09-18 05:35:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.zsh = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2016-09-04 16:30:07 +02: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 05:35:58 +02:00
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
shellAliases = mkOption {
|
2018-08-04 05:32:30 +02:00
|
|
|
default = {};
|
2013-09-18 05:35:58 +02:00
|
|
|
description = ''
|
2018-08-04 05:32:30 +02:00
|
|
|
Set of aliases for zsh shell, which overrides <option>environment.shellAliases</option>.
|
2017-09-30 08:08:42 +02:00
|
|
|
See <option>environment.shellAliases</option> for an option format description.
|
2013-09-18 05:35:58 +02:00
|
|
|
'';
|
2018-10-12 15:58:35 +02:00
|
|
|
type = with types; attrsOf (nullOr (either str path));
|
2013-09-18 05:35:58 +02: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 = ''
|
2018-05-31 04:27:24 +02:00
|
|
|
if [ "$TERM" != dumb ]; then
|
2018-08-29 18:05:53 +02:00
|
|
|
autoload -U promptinit && promptinit && prompt walters
|
2018-05-31 04:27:24 +02:00
|
|
|
fi
|
2013-09-18 05:35:58 +02:00
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise the zsh prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2015-11-25 00:04:17 +01:00
|
|
|
enableCompletion = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable zsh completion for all interactive zsh shells.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2018-08-17 12:57:33 +02:00
|
|
|
|
|
|
|
enableGlobalCompInit = mkOption {
|
|
|
|
default = cfg.enableCompletion;
|
|
|
|
description = ''
|
|
|
|
Enable execution of compinit call for all interactive zsh shells.
|
|
|
|
|
2018-08-27 11:43:31 +02:00
|
|
|
This option can be disabled if the user wants to extend its
|
2018-08-17 12:57:33 +02:00
|
|
|
<literal>fpath</literal> and a custom <literal>compinit</literal>
|
|
|
|
call in the local config is required.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2013-09-18 05:35:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-08-04 05:32:30 +02:00
|
|
|
programs.zsh.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
|
|
|
|
|
2013-09-18 05:35:58 +02: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 23:53:28 +01:00
|
|
|
# But don't clobber the environment of interactive non-login children!
|
2013-09-18 05:35:58 +02:00
|
|
|
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
|
2014-01-31 23:53:28 +01:00
|
|
|
export __ETC_ZSHENV_SOURCED=1
|
2013-09-18 05:35:58 +02:00
|
|
|
|
2018-08-29 18:05:48 +02:00
|
|
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
|
|
|
|
. ${config.system.build.setEnvironment}
|
|
|
|
fi
|
2018-05-19 10:14:45 +02:00
|
|
|
|
2017-05-09 17:07:18 +02:00
|
|
|
${cfge.shellInit}
|
|
|
|
|
2013-09-18 05:35:58 +02:00
|
|
|
${cfg.shellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshenv.local; then
|
2018-08-29 18:05:53 +02:00
|
|
|
. /etc/zshenv.local
|
2013-09-18 05:35:58 +02:00
|
|
|
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
|
|
|
|
|
2017-05-09 17:07:18 +02:00
|
|
|
${cfge.loginShellInit}
|
|
|
|
|
2013-09-18 05:35:58 +02:00
|
|
|
${cfg.loginShellInit}
|
|
|
|
|
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zprofile.local; then
|
2018-08-29 18:05:53 +02:00
|
|
|
. /etc/zprofile.local
|
2013-09-18 05:35:58 +02:00
|
|
|
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
|
|
|
|
|
2017-05-09 17:07:18 +02:00
|
|
|
# history defaults
|
|
|
|
SAVEHIST=2000
|
|
|
|
HISTSIZE=2000
|
|
|
|
HISTFILE=$HOME/.zsh_history
|
|
|
|
|
|
|
|
setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK
|
|
|
|
|
|
|
|
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
|
|
|
|
|
2017-08-25 10:34:21 +02:00
|
|
|
# Tell zsh how to find installed completions
|
|
|
|
for p in ''${(z)NIX_PROFILES}; do
|
2018-08-29 18:05:53 +02:00
|
|
|
fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions)
|
2017-08-25 10:34:21 +02:00
|
|
|
done
|
|
|
|
|
2018-08-17 12:57:33 +02:00
|
|
|
${optionalString cfg.enableGlobalCompInit "autoload -U compinit && compinit"}
|
2017-05-09 17:07:18 +02:00
|
|
|
|
|
|
|
${cfge.interactiveShellInit}
|
|
|
|
|
2013-09-18 05:35:58 +02:00
|
|
|
${cfg.interactiveShellInit}
|
|
|
|
|
2017-08-18 21:48:38 +02:00
|
|
|
${zshAliases}
|
|
|
|
|
2017-05-09 17:07:18 +02:00
|
|
|
${cfg.promptInit}
|
|
|
|
|
2013-09-18 05:35:58 +02:00
|
|
|
# Read system-wide modifications.
|
|
|
|
if test -f /etc/zshrc.local; then
|
2018-08-29 18:05:53 +02:00
|
|
|
. /etc/zshrc.local
|
2013-09-18 05:35:58 +02:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.etc."zinputrc".source = ./zinputrc;
|
|
|
|
|
2015-11-25 00:04:17 +01:00
|
|
|
environment.systemPackages = [ pkgs.zsh ]
|
2017-04-23 21:17:31 +02:00
|
|
|
++ optional cfg.enableCompletion pkgs.nix-zsh-completions;
|
2013-09-18 05:35:58 +02:00
|
|
|
|
2015-11-26 01:49:10 +01:00
|
|
|
environment.pathsToLink = optional cfg.enableCompletion "/share/zsh";
|
|
|
|
|
2014-04-29 18:57:04 +02:00
|
|
|
#users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh";
|
2013-09-18 05:35:58 +02:00
|
|
|
|
|
|
|
environment.shells =
|
|
|
|
[ "/run/current-system/sw/bin/zsh"
|
|
|
|
"/var/run/current-system/sw/bin/zsh"
|
|
|
|
"${pkgs.zsh}/bin/zsh"
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|