at 18.09-beta 5.6 kB view raw
1# This module defines global configuration for the zshell. 2 3{ config, lib, pkgs, ... }: 4 5with lib; 6 7let 8 9 cfge = config.environment; 10 11 cfg = config.programs.zsh; 12 13 zshAliases = concatStringsSep "\n" ( 14 mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases 15 ); 16 17in 18 19{ 20 21 options = { 22 23 programs.zsh = { 24 25 enable = mkOption { 26 default = false; 27 description = '' 28 Whether to configure zsh as an interactive shell. To enable zsh for 29 a particular user, use the <option>users.users.&lt;name?&gt;.shell</option> 30 option for that user. To enable zsh system-wide use the 31 <option>users.defaultUserShell</option> option. 32 ''; 33 type = types.bool; 34 }; 35 36 shellAliases = mkOption { 37 default = config.environment.shellAliases; 38 description = '' 39 Set of aliases for zsh shell. Overrides the default value taken from 40 <option>environment.shellAliases</option>. 41 See <option>environment.shellAliases</option> for an option format description. 42 ''; 43 type = types.attrs; # types.attrsOf types.stringOrPath; 44 }; 45 46 shellInit = mkOption { 47 default = ""; 48 description = '' 49 Shell script code called during zsh shell initialisation. 50 ''; 51 type = types.lines; 52 }; 53 54 loginShellInit = mkOption { 55 default = ""; 56 description = '' 57 Shell script code called during zsh login shell initialisation. 58 ''; 59 type = types.lines; 60 }; 61 62 interactiveShellInit = mkOption { 63 default = ""; 64 description = '' 65 Shell script code called during interactive zsh shell initialisation. 66 ''; 67 type = types.lines; 68 }; 69 70 promptInit = mkOption { 71 default = '' 72 if [ "$TERM" != dumb ]; then 73 autoload -U promptinit && promptinit && prompt walters 74 fi 75 ''; 76 description = '' 77 Shell script code used to initialise the zsh prompt. 78 ''; 79 type = types.lines; 80 }; 81 82 enableCompletion = mkOption { 83 default = true; 84 description = '' 85 Enable zsh completion for all interactive zsh shells. 86 ''; 87 type = types.bool; 88 }; 89 90 91 enableGlobalCompInit = mkOption { 92 default = cfg.enableCompletion; 93 description = '' 94 Enable execution of compinit call for all interactive zsh shells. 95 96 This option can be disabled if the user wants to extend its 97 <literal>fpath</literal> and a custom <literal>compinit</literal> 98 call in the local config is required. 99 ''; 100 type = types.bool; 101 }; 102 103 }; 104 105 }; 106 107 config = mkIf cfg.enable { 108 109 environment.etc."zshenv".text = 110 '' 111 # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. 112 # This file is read for all shells. 113 114 # Only execute this file once per shell. 115 # But don't clobber the environment of interactive non-login children! 116 if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi 117 export __ETC_ZSHENV_SOURCED=1 118 119 ${config.system.build.setEnvironment.text} 120 121 ${cfge.shellInit} 122 123 ${cfg.shellInit} 124 125 # Read system-wide modifications. 126 if test -f /etc/zshenv.local; then 127 . /etc/zshenv.local 128 fi 129 ''; 130 131 environment.etc."zprofile".text = 132 '' 133 # /etc/zprofile: DO NOT EDIT -- this file has been generated automatically. 134 # This file is read for login shells. 135 136 # Only execute this file once per shell. 137 if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi 138 __ETC_ZPROFILE_SOURCED=1 139 140 ${cfge.loginShellInit} 141 142 ${cfg.loginShellInit} 143 144 # Read system-wide modifications. 145 if test -f /etc/zprofile.local; then 146 . /etc/zprofile.local 147 fi 148 ''; 149 150 environment.etc."zshrc".text = 151 '' 152 # /etc/zshrc: DO NOT EDIT -- this file has been generated automatically. 153 # This file is read for interactive shells. 154 155 # Only execute this file once per shell. 156 if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi 157 __ETC_ZSHRC_SOURCED=1 158 159 . /etc/zinputrc 160 161 # history defaults 162 SAVEHIST=2000 163 HISTSIZE=2000 164 HISTFILE=$HOME/.zsh_history 165 166 setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK 167 168 HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" 169 170 # Tell zsh how to find installed completions 171 for p in ''${(z)NIX_PROFILES}; do 172 fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions) 173 done 174 175 ${optionalString cfg.enableGlobalCompInit "autoload -U compinit && compinit"} 176 177 ${cfge.interactiveShellInit} 178 179 ${cfg.interactiveShellInit} 180 181 ${zshAliases} 182 183 ${cfg.promptInit} 184 185 # Read system-wide modifications. 186 if test -f /etc/zshrc.local; then 187 . /etc/zshrc.local 188 fi 189 ''; 190 191 environment.etc."zinputrc".source = ./zinputrc; 192 193 environment.systemPackages = [ pkgs.zsh ] 194 ++ optional cfg.enableCompletion pkgs.nix-zsh-completions; 195 196 environment.pathsToLink = optional cfg.enableCompletion "/share/zsh"; 197 198 #users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh"; 199 200 environment.shells = 201 [ "/run/current-system/sw/bin/zsh" 202 "/var/run/current-system/sw/bin/zsh" 203 "${pkgs.zsh}/bin/zsh" 204 ]; 205 206 }; 207 208}