# Interactive shell: zsh as on the admin's workstation (asxpi/nixOS, # modules/shell.nix), minus what only makes sense there. # # Every account logs in with zsh, including ones added later, except # those that run other programs' commands through their login shell: # deploy (the app CI's SSH scripts are bash) and git (Forgejo). # root gets the same zsh with a red prompt ending in #. # # Interactive SSH logins show fastfetch and a short security summary; # scp, CI and `ssh host ` stay quiet. { config, lib, pkgs, ... }: let summary = pkgs.writeShellApplication { name = "login-summary"; # Read-only reporting: an empty grep or a missing file must not end it bashOptions = [ "nounset" ]; runtimeInputs = with pkgs; [ coreutils gawk gnugrep gnused config.systemd.package ]; text = builtins.readFile ./login-summary.sh; }; in { programs.zsh = { enable = true; enableCompletion = true; autosuggestions.enable = true; syntaxHighlighting.enable = true; histSize = 10000; histFile = "$HOME/.zsh_history"; shellAliases = { ls = "ls --color=auto"; grep = "grep --color=auto"; }; # Blue for everyone: [HH:MM:SS] [user@host path] $ # Red for root: [HH:MM:SS] [root@host path] # promptInit = '' if [[ $EUID -eq 0 ]]; then PROMPT='%B%F{#ff2020}[%b%f%D{%H:%M:%S}%B%F{#ff2020}]%b%f %B%F{#ff2020}[%b%F{#ff2020}%n%f@%m %B%F{#ff2020}%~]%b%f %B%F{#ff2020}#%b%f ' else PROMPT='%B%F{#0055ff}[%b%f%D{%H:%M:%S}%B%F{#0055ff}]%b%f %B%F{#0055ff}[%b%f%n@%m %B%F{#0055ff}%~]%b%f %B%F{#0055ff}$%b%f ' fi ''; # Fresh homes have no ~/.zshrc: never offer the new-user wizard shellInit = '' zsh-newuser-install() { :; } ''; interactiveShellInit = '' setopt SHARE_HISTORY setopt HIST_IGNORE_DUPS setopt HIST_IGNORE_ALL_DUPS bindkey -e zstyle ':completion:*' menu select zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' zstyle ':completion:*' list-colors "''${(s.:.)LS_COLORS}" zstyle ':completion:*' rehash true bindkey "^[[H" beginning-of-line # Home bindkey "^[[F" end-of-line # End bindkey "^[[3~" delete-char # Delete bindkey "^[[1;5C" forward-word # Ctrl+Right bindkey "^[[1;5D" backward-word # Ctrl+Left bindkey '^R' history-incremental-search-backward ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' ''; }; users.defaultUserShell = pkgs.zsh; users.users.root.shell = pkgs.zsh; users.users.deploy.shell = pkgs.bashInteractive; environment.systemPackages = with pkgs; [ fastfetch bat eza summary ]; environment.loginShellInit = '' if [ -n "''${SSH_TTY:-}" ] && [ -t 1 ]; then ${lib.getExe pkgs.fastfetch} 2>/dev/null ${lib.getExe summary} 2>/dev/null fi ''; }