at 18.03-beta 5.4 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 autoload -U promptinit && promptinit && prompt walters 73 ''; 74 description = '' 75 Shell script code used to initialise the zsh prompt. 76 ''; 77 type = types.lines; 78 }; 79 80 enableCompletion = mkOption { 81 default = true; 82 description = '' 83 Enable zsh completion for all interactive zsh shells. 84 ''; 85 type = types.bool; 86 }; 87 88 enableAutosuggestions = mkOption { 89 default = false; 90 description = '' 91 Enable zsh-autosuggestions 92 ''; 93 type = types.bool; 94 }; 95 }; 96 97 }; 98 99 config = mkIf cfg.enable { 100 101 environment.etc."zshenv".text = 102 '' 103 # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. 104 # This file is read for all shells. 105 106 # Only execute this file once per shell. 107 # But don't clobber the environment of interactive non-login children! 108 if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi 109 export __ETC_ZSHENV_SOURCED=1 110 111 . ${config.system.build.setEnvironment} 112 113 ${cfge.shellInit} 114 115 ${cfg.shellInit} 116 117 # Read system-wide modifications. 118 if test -f /etc/zshenv.local; then 119 . /etc/zshenv.local 120 fi 121 ''; 122 123 environment.etc."zprofile".text = 124 '' 125 # /etc/zprofile: DO NOT EDIT -- this file has been generated automatically. 126 # This file is read for login shells. 127 128 # Only execute this file once per shell. 129 if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi 130 __ETC_ZPROFILE_SOURCED=1 131 132 ${cfge.loginShellInit} 133 134 ${cfg.loginShellInit} 135 136 # Read system-wide modifications. 137 if test -f /etc/zprofile.local; then 138 . /etc/zprofile.local 139 fi 140 ''; 141 142 environment.etc."zshrc".text = 143 '' 144 # /etc/zshrc: DO NOT EDIT -- this file has been generated automatically. 145 # This file is read for interactive shells. 146 147 # Only execute this file once per shell. 148 if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi 149 __ETC_ZSHRC_SOURCED=1 150 151 . /etc/zinputrc 152 153 # history defaults 154 SAVEHIST=2000 155 HISTSIZE=2000 156 HISTFILE=$HOME/.zsh_history 157 158 setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK 159 160 HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" 161 162 # Tell zsh how to find installed completions 163 for p in ''${(z)NIX_PROFILES}; do 164 fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions) 165 done 166 167 ${optionalString cfg.enableCompletion "autoload -U compinit && compinit"} 168 169 ${optionalString (cfg.enableAutosuggestions) 170 "source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" 171 } 172 173 ${cfge.interactiveShellInit} 174 175 ${cfg.interactiveShellInit} 176 177 ${zshAliases} 178 179 ${cfg.promptInit} 180 181 # Read system-wide modifications. 182 if test -f /etc/zshrc.local; then 183 . /etc/zshrc.local 184 fi 185 ''; 186 187 environment.etc."zinputrc".source = ./zinputrc; 188 189 environment.systemPackages = [ pkgs.zsh ] 190 ++ optional cfg.enableCompletion pkgs.nix-zsh-completions; 191 192 environment.pathsToLink = optional cfg.enableCompletion "/share/zsh"; 193 194 #users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh"; 195 196 environment.shells = 197 [ "/run/current-system/sw/bin/zsh" 198 "/var/run/current-system/sw/bin/zsh" 199 "${pkgs.zsh}/bin/zsh" 200 ]; 201 202 }; 203 204}