at 16.09-beta 4.9 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. 29 ''; 30 type = types.bool; 31 }; 32 33 shellAliases = mkOption { 34 default = config.environment.shellAliases; 35 description = '' 36 Set of aliases for zsh shell. See <option>environment.shellAliases</option> 37 for an option format description. 38 ''; 39 type = types.attrs; # types.attrsOf types.stringOrPath; 40 }; 41 42 shellInit = mkOption { 43 default = ""; 44 description = '' 45 Shell script code called during zsh shell initialisation. 46 ''; 47 type = types.lines; 48 }; 49 50 loginShellInit = mkOption { 51 default = ""; 52 description = '' 53 Shell script code called during zsh login shell initialisation. 54 ''; 55 type = types.lines; 56 }; 57 58 interactiveShellInit = mkOption { 59 default = ""; 60 description = '' 61 Shell script code called during interactive zsh shell initialisation. 62 ''; 63 type = types.lines; 64 }; 65 66 promptInit = mkOption { 67 default = '' 68 autoload -U promptinit && promptinit && prompt walters 69 ''; 70 description = '' 71 Shell script code used to initialise the zsh prompt. 72 ''; 73 type = types.lines; 74 }; 75 76 enableCompletion = mkOption { 77 default = true; 78 description = '' 79 Enable zsh completion for all interactive zsh shells. 80 ''; 81 type = types.bool; 82 }; 83 84 }; 85 86 }; 87 88 config = mkIf cfg.enable { 89 90 programs.zsh = { 91 92 shellInit = '' 93 . ${config.system.build.setEnvironment} 94 95 ${cfge.shellInit} 96 ''; 97 98 loginShellInit = cfge.loginShellInit; 99 100 interactiveShellInit = '' 101 # history defaults 102 export SAVEHIST=2000 103 export HISTSIZE=2000 104 export HISTFILE=$HOME/.zsh_history 105 106 setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK 107 108 ${cfge.interactiveShellInit} 109 110 ${cfg.promptInit} 111 ${zshAliases} 112 113 # Tell zsh how to find installed completions 114 for p in ''${(z)NIX_PROFILES}; do 115 fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions) 116 done 117 118 ${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""} 119 120 HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" 121 ''; 122 123 }; 124 125 environment.etc."zshenv".text = 126 '' 127 # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. 128 # This file is read for all shells. 129 130 # Only execute this file once per shell. 131 # But don't clobber the environment of interactive non-login children! 132 if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi 133 export __ETC_ZSHENV_SOURCED=1 134 135 ${cfg.shellInit} 136 137 # Read system-wide modifications. 138 if test -f /etc/zshenv.local; then 139 . /etc/zshenv.local 140 fi 141 ''; 142 143 environment.etc."zprofile".text = 144 '' 145 # /etc/zprofile: DO NOT EDIT -- this file has been generated automatically. 146 # This file is read for login shells. 147 148 # Only execute this file once per shell. 149 if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi 150 __ETC_ZPROFILE_SOURCED=1 151 152 ${cfg.loginShellInit} 153 154 # Read system-wide modifications. 155 if test -f /etc/zprofile.local; then 156 . /etc/zprofile.local 157 fi 158 ''; 159 160 environment.etc."zshrc".text = 161 '' 162 # /etc/zshrc: DO NOT EDIT -- this file has been generated automatically. 163 # This file is read for interactive shells. 164 165 # Only execute this file once per shell. 166 if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi 167 __ETC_ZSHRC_SOURCED=1 168 169 . /etc/zinputrc 170 171 ${cfg.interactiveShellInit} 172 173 # Read system-wide modifications. 174 if test -f /etc/zshrc.local; then 175 . /etc/zshrc.local 176 fi 177 ''; 178 179 environment.etc."zinputrc".source = ./zinputrc; 180 181 environment.systemPackages = [ pkgs.zsh ] 182 ++ optional cfg.enableCompletion pkgs.nix-zsh-completions; 183 184 environment.pathsToLink = optional cfg.enableCompletion "/share/zsh"; 185 186 #users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh"; 187 188 environment.shells = 189 [ "/run/current-system/sw/bin/zsh" 190 "/var/run/current-system/sw/bin/zsh" 191 "${pkgs.zsh}/bin/zsh" 192 ]; 193 194 }; 195 196}