at v192 4.2 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 Whenever 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 }; 77 78 }; 79 80 config = mkIf cfg.enable { 81 82 programs.zsh = { 83 84 shellInit = '' 85 . ${config.system.build.setEnvironment} 86 87 ${cfge.shellInit} 88 ''; 89 90 loginShellInit = cfge.loginShellInit; 91 92 interactiveShellInit = '' 93 ${cfge.interactiveShellInit} 94 95 ${cfg.promptInit} 96 ${zshAliases} 97 98 # Some sane history defaults 99 export SAVEHIST=2000 100 export HISTSIZE=2000 101 export HISTFILE=$HOME/.zsh_history 102 103 setopt HIST_IGNORE_DUPS SHARE_HISTORY HIST_FCNTL_LOCK 104 ''; 105 106 }; 107 108 environment.etc."zshenv".text = 109 '' 110 # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. 111 # This file is read for all shells. 112 113 # Only execute this file once per shell. 114 # But don't clobber the environment of interactive non-login children! 115 if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi 116 export __ETC_ZSHENV_SOURCED=1 117 118 ${cfg.shellInit} 119 120 # Read system-wide modifications. 121 if test -f /etc/zshenv.local; then 122 . /etc/zshenv.local 123 fi 124 ''; 125 126 environment.etc."zprofile".text = 127 '' 128 # /etc/zprofile: DO NOT EDIT -- this file has been generated automatically. 129 # This file is read for login shells. 130 131 # Only execute this file once per shell. 132 if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi 133 __ETC_ZPROFILE_SOURCED=1 134 135 ${cfg.loginShellInit} 136 137 # Read system-wide modifications. 138 if test -f /etc/zprofile.local; then 139 . /etc/zprofile.local 140 fi 141 ''; 142 143 environment.etc."zshrc".text = 144 '' 145 # /etc/zshrc: DO NOT EDIT -- this file has been generated automatically. 146 # This file is read for interactive shells. 147 148 # Only execute this file once per shell. 149 if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi 150 __ETC_ZSHRC_SOURCED=1 151 152 . /etc/zinputrc 153 154 ${cfg.interactiveShellInit} 155 156 # Read system-wide modifications. 157 if test -f /etc/zshrc.local; then 158 . /etc/zshrc.local 159 fi 160 ''; 161 162 environment.etc."zinputrc".source = ./zinputrc; 163 164 environment.systemPackages = [ pkgs.zsh ]; 165 166 #users.defaultUserShell = mkDefault "/run/current-system/sw/bin/zsh"; 167 168 environment.shells = 169 [ "/run/current-system/sw/bin/zsh" 170 "/var/run/current-system/sw/bin/zsh" 171 "${pkgs.zsh}/bin/zsh" 172 ]; 173 174 }; 175 176}