bundle modules

This commit is contained in:
2026-02-04 08:30:19 +01:00
parent 3ee0c62a2e
commit 2c2f817459
7 changed files with 48 additions and 42 deletions

10
modules/shell/bash.nix Normal file
View File

@@ -0,0 +1,10 @@
{ pkgs, ... }:
{
programs.bash = {
promptInit = ''PS1="$(${pkgs.ncurses}/bin/tput bold)\w \$([[ \$? == 0 ]] && echo \"\[\033[1;32m\]\" || echo \"\[\033[1;31m\]\")\$$(${pkgs.ncurses}/bin/tput sgr0) "'';
interactiveShellInit = ''
set -o vi
'';
completion.enable = true;
};
}

View File

@@ -0,0 +1,8 @@
{
imports = [
./tools.nix
./bash.nix
./zsh.nix
./tmux.nix
];
}

38
modules/shell/tmux.nix Normal file
View File

@@ -0,0 +1,38 @@
{
programs.tmux = {
enable = true;
keyMode = "vi";
clock24 = true;
terminal = "screen-256color";
baseIndex = 1;
aggressiveResize = true;
escapeTime = 50;
historyLimit = 7000;
shortcut = "b";
extraConfig = ''
set -g mouse on
unbind *
bind * list-clients
# naVIgate
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Use C-h and C-l to cycle through panes
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
setw -g monitor-activity on
set -g visual-activity on
set -g status-interval 2
set -g status-left-length 32
set -g status-right-length 150
set -g status-position bottom
'';
};
}

137
modules/shell/tools.nix Normal file
View File

@@ -0,0 +1,137 @@
{ pkgs, lib, ... }:
let
isDarwin = lib.strings.hasSuffix "darwin" pkgs.system;
in
{
environment.systemPackages = [
pkgs.htop
pkgs.btop
pkgs.iftop
pkgs.lsof
pkgs.wget
pkgs.curl
pkgs.zip
pkgs.unzip
pkgs.unrar
pkgs.p7zip
pkgs.fd
pkgs.ripgrep
pkgs.bat
pkgs.findutils
pkgs.coreutils
pkgs.tree
pkgs.rlwrap
pkgs.file
pkgs.progress
pkgs.gdu
pkgs.rmlint
pkgs.binutils # for objdump, strings, etc.
pkgs.gnumake # for make
pkgs.tokei # for code statistics
pkgs.man-pages
pkgs.man-pages-posix
pkgs.dos2unix
pkgs.whois
pkgs.dnsutils
pkgs.aria2
pkgs.jq
pkgs.yq
pkgs.bc
pkgs.vimv
pkgs.pciutils # for lspci
pkgs.tmux
]
++ lib.optionals (!isDarwin) [
pkgs.usbutils # for lsusb
pkgs.lshw
pkgs.iotop
pkgs.psmisc # killall, pstree
];
security.wrappers = {
pmount = {
setuid = true;
owner = "root";
group = "root";
source = "${pkgs.pmount}/bin/pmount";
};
pumount = {
setuid = true;
owner = "root";
group = "root";
source = "${pkgs.pmount}/bin/pumount";
};
};
environment.interactiveShellInit = ''
# Use XDG_RUNTIME_DIR for temporary files if available
if [ -d "$XDG_RUNTIME_DIR" ]; then
export TMPDIR="$XDG_RUNTIME_DIR"
fi
'';
environment.shellAliases =
let
take = pkgs.writers.writeDash "take" ''
mkdir "$1" && cd "$1"
'';
cdt = pkgs.writers.writeDash "cdt" ''
cd $(mktemp -p "$XDG_RUNTIME_DIR" -d "cdt-XXXXXX")
pwd
'';
wcd = pkgs.writers.writeDash "wcd" ''
cd "$(readlink "$(${pkgs.which}/bin/which --skip-alias "$1")" | xargs dirname)/.."
'';
where = pkgs.writers.writeDash "where" ''
readlink "$(${pkgs.which}/bin/which --skip-alias "$1")" | xargs dirname
'';
in
{
nixi = "nix repl nixpkgs";
take = "source ${take}";
wcd = "source ${wcd}";
where = "source ${where}";
# temporary files and directories
cdt = "source ${cdt}";
vit = "$EDITOR $(mktemp)";
# file safety
mv = "${pkgs.coreutils}/bin/mv --interactive";
rm = "${pkgs.coreutils}/bin/rm --interactive --verbose";
cp = "${pkgs.coreutils}/bin/cp --interactive";
# colours
cat = "${pkgs.bat}/bin/bat --theme=ansi --style=plain";
l = "${pkgs.coreutils}/bin/ls --color=auto --time-style=long-iso --almost-all";
ls = "${pkgs.coreutils}/bin/ls --color=auto --time-style=long-iso";
ll = "${pkgs.coreutils}/bin/ls --color=auto --time-style=long-iso -l";
la = "${pkgs.coreutils}/bin/ls --color=auto --time-style=long-iso --almost-all -l";
o = "${pkgs.xdg-utils}/bin/xdg-open";
ns = "nix-shell --run zsh";
}
// (
if isDarwin then
{ }
else
{
"ß" = "${pkgs.util-linux}/bin/setsid";
ip = "${pkgs.iproute2}/bin/ip -c";
# systemd
s = "${pkgs.systemd}/bin/systemctl";
us = "${pkgs.systemd}/bin/systemctl --user";
j = "${pkgs.systemd}/bin/journalctl";
uj = "${pkgs.systemd}/bin/journalctl --user";
}
);
}

111
modules/shell/zsh.nix Normal file
View File

@@ -0,0 +1,111 @@
{ pkgs, lib, ... }:
let
promptColours.success = "cyan";
promptColours.failure = "red";
in
{
programs.fzf = {
fuzzyCompletion = true;
keybindings = true;
};
environment.variables =
let
defaultFzf = "${lib.getExe pkgs.fd}/bin/fd --type f --strip-cwd-prefix --no-ignore-vcs --exclude .git";
in
{
FZF_DEFAULT_COMMAND = defaultFzf;
FZF_DEFAULT_OPTS = "--height 40%";
FZF_CTRL_T_COMMAND = defaultFzf;
FZF_CTRL_T_OPTS = "--preview='head -$LINES {}'";
FZF_ALT_C_COMMAND = "${lib.getExe pkgs.fd}/bin/fd --type d";
};
users.defaultUserShell = pkgs.zsh;
programs.zsh =
let
zsh-completions = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-completions";
rev = "cf565254e26bb7ce03f51889e9a29953b955b1fb";
sha256 = "1yf4rz99acdsiy0y1v3bm65xvs2m0sl92ysz0rnnrlbd5amn283l";
};
in
{
enable = true;
enableCompletion = true;
autosuggestions.enable = true;
syntaxHighlighting.enable = true;
syntaxHighlighting.highlighters = [
"main"
"brackets"
"pattern"
"line"
];
interactiveShellInit = ''
setopt INTERACTIVE_COMMENTS CORRECT
setopt MULTIOS
setopt AUTO_NAME_DIRS
setopt AUTOCD CDABLE_VARS
setopt HIST_IGNORE_ALL_DUPS
setopt VI
setopt AUTO_MENU
setopt COMPLETE_IN_WORD
setopt ALWAYS_TO_END
unsetopt NOMATCH
unsetopt MENU_COMPLETE
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' list-colors \'\'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
export KEYTIMEOUT=1
autoload -U zmv run-help edit-command-line
fpath=(${zsh-completions}/src $fpath)
'';
promptInit = ''
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '%F{green}+%f'
zstyle ':vcs_info:*' unstagedstr '%F{red}~%f'
zstyle ':vcs_info:*' use-prompt-escapes true
zstyle ':vcs_info:*' formats "%c%u%F{cyan}%b%f"
zstyle ':vcs_info:*' actionformats "(%a) %c%u%F{cyan}%b%f"
precmd () {
vcs_info
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] || [ -n "$SSH_CONNECTION" ]; then
RPROMPT="$(hostname)"
else
RPROMPT="$vcs_info_msg_0_"
fi
if [[ -n $IN_NIX_SHELL ]]; then
PROMPT='%B%~%b %(?.%F{${promptColours.success}}.%F{${promptColours.failure}})λ%f '
else
PROMPT='%B%~%b %(?.%F{${promptColours.success}}.%F{${promptColours.failure}})%#%f '
fi
print -Pn "\e]2;%n@%M:%~\a" # title bar prompt
}
zle-keymap-select zle-line-init () {
case $KEYMAP in
vicmd) print -n '\e]12;green\a';;
viins|main) print -n '\e]12;gray\a';;
esac
}
zle -N zle-line-init
zle -N zle-keymap-select
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
'';
};
}