diff --git a/nixos/flake.nix b/nixos/flake.nix index 1b49b34..fac3e85 100644 --- a/nixos/flake.nix +++ b/nixos/flake.nix @@ -28,6 +28,7 @@ sops-nix.nixosModules.sops ./modules/hetzner.nix ./modules/base.nix + ./modules/shell.nix ./modules/podman.nix ./modules/wireguard.nix ./modules/alert.nix diff --git a/nixos/modules/shell.nix b/nixos/modules/shell.nix new file mode 100644 index 0000000..4f2da94 --- /dev/null +++ b/nixos/modules/shell.nix @@ -0,0 +1,70 @@ +# Interactive shell for the admins: zsh as on the admin's workstation +# (asxpi/nixOS, modules/shell.nix), minus what only makes sense there. +# +# deploy keeps bash: the app CI runs its SSH scripts through deploy's +# login shell, and they are bash. root keeps bash too, for scripts and +# `ssh root@host ''`. +{ lib, pkgs, ... }: +{ + 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: [HH:MM:SS] [user@host path] $ + promptInit = '' + 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 ' + ''; + + # 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.users.asxpi.shell = pkgs.zsh; + + environment.systemPackages = with pkgs; [ + fastfetch + bat + eza + ]; + + # System summary on interactive SSH logins only: scp, CI and + # `ssh host ` stay quiet + environment.loginShellInit = '' + if [ -n "''${SSH_TTY:-}" ] && [ -t 1 ]; then + ${lib.getExe pkgs.fastfetch} 2>/dev/null + fi + ''; +}