refactor: 重构为多平台多用户架构,全面提升终端体验
- 新增 lib/ 辅助函数(mkNixos/mkDarwin/mkHome),消除硬编码 - 拆分 modules/ 为 nixos/darwin/shared 三层,支持跨平台共享 - 重构 home/ 为 shell/dev/theme 子模块,工具全部迁入用户级 - 深度配置 Tmux/FZF/Atuin/Bat/Eza/Btop/Lazygit/Starship - 添加 Catppuccin Mocha 统一主题、Nerd Fonts 声明式管理 - 新增 homeConfigurations 输出,支持非 NixOS 系统直装 - 新增 nix-darwin 输入,预留 macOS 扩展路径 - 新增 overlays/ 和 pkgs/ 自定义包基础设施 - 修正 nix-darwin URL(LnL7 → nix-darwin org)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
imports = [
|
||||
./zsh.nix
|
||||
./starship.nix
|
||||
./tools.nix
|
||||
./tmux.nix
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
programs.starship = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
|
||||
settings = {
|
||||
add_newline = false;
|
||||
|
||||
format = lib.concatStrings [
|
||||
"$os"
|
||||
"$username"
|
||||
"$hostname"
|
||||
"$directory"
|
||||
"$git_branch"
|
||||
"$git_status"
|
||||
"$nix_shell"
|
||||
"$nodejs"
|
||||
"$python"
|
||||
"$go"
|
||||
"$rust"
|
||||
"$docker_context"
|
||||
"$cmd_duration"
|
||||
"$line_break"
|
||||
"$character"
|
||||
];
|
||||
|
||||
character = {
|
||||
success_symbol = "[❯](bold green)";
|
||||
error_symbol = "[❯](bold red)";
|
||||
};
|
||||
|
||||
os = {
|
||||
disabled = false;
|
||||
symbols = {
|
||||
NixOS = " ";
|
||||
Linux = " ";
|
||||
Macos = " ";
|
||||
Windows = " ";
|
||||
};
|
||||
};
|
||||
|
||||
directory = {
|
||||
truncation_length = 3;
|
||||
truncation_symbol = "…/";
|
||||
substitutions = {
|
||||
Developer = " ";
|
||||
Documents = " ";
|
||||
Downloads = " ";
|
||||
};
|
||||
};
|
||||
|
||||
git_branch.symbol = " ";
|
||||
|
||||
git_status = {
|
||||
format = "([\\[$all_status$ahead_behind\\]]($style) )";
|
||||
};
|
||||
|
||||
nix_shell = {
|
||||
symbol = " ";
|
||||
format = "[$symbol$state( \\($name\\))]($style) ";
|
||||
};
|
||||
|
||||
docker_context = {
|
||||
symbol = " ";
|
||||
format = "[$symbol$context]($style) ";
|
||||
};
|
||||
|
||||
cmd_duration = {
|
||||
min_time = 2000;
|
||||
format = "[$duration]($style) ";
|
||||
};
|
||||
|
||||
nodejs = {
|
||||
format = "[$symbol($version)]($style) ";
|
||||
detect_extensions = [ ];
|
||||
};
|
||||
|
||||
python.format = "[$symbol($version)]($style) ";
|
||||
go.format = "[$symbol($version)]($style) ";
|
||||
rust.format = "[$symbol($version)]($style) ";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.tmux = {
|
||||
enable = true;
|
||||
baseIndex = 1;
|
||||
escapeTime = 10;
|
||||
historyLimit = 50000;
|
||||
keyMode = "vi";
|
||||
mouse = true;
|
||||
terminal = "tmux-256color";
|
||||
prefix = "C-a";
|
||||
|
||||
plugins = with pkgs.tmuxPlugins; [
|
||||
sensible
|
||||
vim-tmux-navigator
|
||||
yank
|
||||
];
|
||||
|
||||
extraConfig = ''
|
||||
# ── True color support ──
|
||||
set -ag terminal-overrides ",xterm-256color:RGB"
|
||||
|
||||
# ── Split panes ──
|
||||
bind v split-window -h -c "#{pane_current_path}"
|
||||
bind s split-window -v -c "#{pane_current_path}"
|
||||
unbind '"'
|
||||
unbind %
|
||||
|
||||
# ── New window in current path ──
|
||||
bind c new-window -c "#{pane_current_path}"
|
||||
|
||||
# ── Reload config ──
|
||||
bind r source-file ~/.config/tmux/tmux.conf \; display "Config reloaded!"
|
||||
|
||||
# ── Resize panes ──
|
||||
bind -r H resize-pane -L 5
|
||||
bind -r J resize-pane -D 5
|
||||
bind -r K resize-pane -U 5
|
||||
bind -r L resize-pane -R 5
|
||||
|
||||
# ── Status bar ──
|
||||
set -g status-position top
|
||||
set -g renumber-windows on
|
||||
|
||||
# ── Copy mode vim bindings ──
|
||||
bind -T copy-mode-vi v send-keys -X begin-selection
|
||||
bind -T copy-mode-vi y send-keys -X copy-selection-and-cancel
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
# ── FZF ──────────────────────────────────────────────
|
||||
programs.fzf = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
defaultCommand = "fd --type f --hidden --follow --exclude .git";
|
||||
defaultOptions = [
|
||||
"--height=40%"
|
||||
"--layout=reverse"
|
||||
"--border"
|
||||
"--info=inline"
|
||||
];
|
||||
changeDirWidgetCommand = "fd --type d --hidden --follow --exclude .git";
|
||||
fileWidgetCommand = "fd --type f --hidden --follow --exclude .git";
|
||||
fileWidgetOptions = [
|
||||
"--preview 'bat --color=always --style=numbers --line-range=:200 {} 2>/dev/null || eza -la {}'"
|
||||
];
|
||||
};
|
||||
|
||||
# ── Atuin (shell history) ────────────────────────────
|
||||
programs.atuin = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
settings = {
|
||||
enter_accept = true;
|
||||
filter_mode = "host";
|
||||
filter_mode_shell_up_key_binding = "session";
|
||||
style = "compact";
|
||||
inline_height = 20;
|
||||
show_help = false;
|
||||
};
|
||||
};
|
||||
|
||||
# ── Zoxide (smart cd) ───────────────────────────────
|
||||
programs.zoxide = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
};
|
||||
|
||||
# ── Direnv + nix-direnv ─────────────────────────────
|
||||
programs.direnv = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
nix-direnv.enable = true;
|
||||
config.global = {
|
||||
warn_timeout = "120s";
|
||||
};
|
||||
};
|
||||
|
||||
# ── Bat (cat replacement) ───────────────────────────
|
||||
programs.bat = {
|
||||
enable = true;
|
||||
extraPackages = with pkgs.bat-extras; [
|
||||
batgrep
|
||||
batwatch
|
||||
];
|
||||
};
|
||||
|
||||
# ── Eza (ls replacement) ────────────────────────────
|
||||
programs.eza = {
|
||||
enable = true;
|
||||
enableZshIntegration = false; # we use custom aliases in zsh.nix
|
||||
git = true;
|
||||
icons = "auto";
|
||||
extraOptions = [
|
||||
"--color=always"
|
||||
"--group-directories-first"
|
||||
];
|
||||
};
|
||||
|
||||
# ── Yazi (file manager) ─────────────────────────────
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
enableZshIntegration = true;
|
||||
};
|
||||
|
||||
# ── Btop (system monitor) ───────────────────────────
|
||||
programs.btop = {
|
||||
enable = true;
|
||||
settings = {
|
||||
vim_keys = true;
|
||||
};
|
||||
};
|
||||
|
||||
# ── Ripgrep / FD ────────────────────────────────────
|
||||
home.packages = with pkgs; [
|
||||
ripgrep
|
||||
fd
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
autocd = true;
|
||||
|
||||
oh-my-zsh = {
|
||||
enable = true;
|
||||
plugins = [
|
||||
"git" # git aliases (gst, gco, gp...)
|
||||
"sudo" # double ESC → prepend sudo
|
||||
"extract" # x file.tar.gz → auto extract
|
||||
"direnv" # direnv hook
|
||||
];
|
||||
};
|
||||
|
||||
autosuggestion.enable = true;
|
||||
syntaxHighlighting.enable = true;
|
||||
|
||||
shellAliases = {
|
||||
# Navigation
|
||||
cd = "z";
|
||||
cdi = "zi";
|
||||
".." = "cd ..";
|
||||
"..." = "cd ../..";
|
||||
|
||||
# File listing (eza)
|
||||
ls = "eza --icons --group-directories-first";
|
||||
ll = "eza -la --icons --git --group-directories-first";
|
||||
la = "eza -a --icons --group-directories-first";
|
||||
lt = "eza --tree --level=2 --icons";
|
||||
|
||||
# Tools
|
||||
cat = "bat --paging=never";
|
||||
rm = "trash-put";
|
||||
lg = "lazygit";
|
||||
vi = "nvim";
|
||||
|
||||
# Network
|
||||
http = "xh";
|
||||
|
||||
# Nix shortcuts
|
||||
rebuild = "sudo nixos-rebuild switch --flake ~/.config/nix-config";
|
||||
update = "nix flake update --flake ~/.config/nix-config";
|
||||
};
|
||||
|
||||
initExtra = ''
|
||||
# ── Shell options ──
|
||||
setopt INTERACTIVE_COMMENTS
|
||||
setopt NO_BEEP
|
||||
|
||||
# ── PATH (manual go/bun global tools) ──
|
||||
export PATH="$HOME/go/bin:$HOME/.bun/bin:$PATH"
|
||||
|
||||
# ── fzf-tab plugin ──
|
||||
source ${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh
|
||||
|
||||
# ── mise ──
|
||||
eval "$(mise activate zsh)"
|
||||
|
||||
# ── WSL clipboard ──
|
||||
if [[ -n "$WSL_DISTRO_NAME" ]]; then
|
||||
alias pbcopy="clip.exe"
|
||||
alias pbpaste="powershell.exe -noprofile -c Get-Clipboard"
|
||||
fi
|
||||
|
||||
# ── User-local overrides ──
|
||||
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
|
||||
'';
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user