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:
2026-04-03 19:54:17 +08:00
parent 92c6535945
commit e92c7aee31
31 changed files with 827 additions and 391 deletions
+47 -27
View File
@@ -1,5 +1,5 @@
{ {
description = "NixOS "; description = "Multi-platform Nix configuration NixOS / nix-darwin / standalone Home Manager";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@@ -13,47 +13,67 @@
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
nix-darwin = {
url = "github:nix-darwin/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
catppuccin = {
url = "github:catppuccin/nix";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
{ {
self, self,
nixpkgs, nixpkgs,
nixos-wsl,
home-manager,
... ...
}: }@inputs:
let let
system = "x86_64-linux"; mylib = import ./lib { inherit inputs; };
# 所有主机共享的模块
commonModules = [
./modules/base.nix
./modules/dev.nix
./modules/docker.nix
./modules/locale.nix
./modules/shell.nix
home-manager.nixosModules.home-manager
];
in in
{ {
# ── NixOS hosts ────────────────────────────────────
nixosConfigurations = { nixosConfigurations = {
# WSL 配置 wsl = mylib.mkNixos {
wsl = nixpkgs.lib.nixosSystem { hostname = "nixos-wsl";
inherit system; system = "x86_64-linux";
modules = commonModules ++ [ username = "dev";
nixos-wsl.nixosModules.default extraModules = [
./hosts/wsl/default.nix inputs.nixos-wsl.nixosModules.default
./hosts/wsl
]; ];
}; };
# 裸机配置 bare = mylib.mkNixos {
bare = nixpkgs.lib.nixosSystem { hostname = "nixos";
inherit system; system = "x86_64-linux";
modules = commonModules ++ [ username = "dev";
./hosts/bare/default.nix extraModules = [ ./hosts/bare ];
];
}; };
}; };
# ── macOS hosts (uncomment when ready) ─────────────
# darwinConfigurations = {
# macbook = mylib.mkDarwin {
# hostname = "macbook";
# system = "aarch64-darwin";
# username = "imbytecat";
# extraModules = [ ./hosts/macbook ];
# };
# };
# ── Standalone Home Manager (non-NixOS / non-Darwin) ─
homeConfigurations = {
"dev" = mylib.mkHome {
system = "x86_64-linux";
username = "dev";
};
};
# ── Overlays ───────────────────────────────────────
overlays.default = import ./overlays;
}; };
} }
+49 -9
View File
@@ -1,16 +1,56 @@
{ config, pkgs, ... }: {
inputs,
username,
pkgs,
lib,
...
}:
{ {
imports = [ imports = [
./shell.nix inputs.catppuccin.homeManagerModules.catppuccin
./git.nix ./shell
./dev
./theme.nix
]; ];
home.stateVersion = "24.11"; home = {
username = username;
homeDirectory =
if pkgs.stdenv.isDarwin then "/Users/${username}" else "/home/${username}";
stateVersion = "24.11";
};
# ── mise 配置 ── # ── User-level packages ────────────────────────────
xdg.configFile."mise/config.toml".text = '' home.packages = with pkgs; [
[settings] # Modern CLI replacements
trusted_config_paths = ["/"] dust # du
''; duf # df
procs # ps
sd # sed
xh # curl/httpie
jq # JSON
yq # YAML
# System info
fastfetch
tealdeer # tldr
# File management
trash-cli
# Terminal multiplexer (alternative)
zellij
# Nix tools
nix-output-monitor # nom — better nix build output
nvd # nix version diff
nh # nix helper (nixos-rebuild wrapper)
# Misc
micro # simple editor fallback
];
# XDG directories
xdg.enable = true;
} }
+7
View File
@@ -0,0 +1,7 @@
{
imports = [
./git.nix
./languages.nix
./neovim.nix
];
}
+59
View File
@@ -0,0 +1,59 @@
{ ... }:
{
programs.git = {
enable = true;
# user.name / user.email: set per-user via git config or ~/.zshrc.local
# git config --global user.name "Your Name"
# git config --global user.email "your@email.com"
delta = {
enable = true;
options = {
navigate = true;
side-by-side = true;
line-numbers = true;
hyperlinks = true;
};
};
extraConfig = {
# Internal Git server (skip SSL verification)
http."https://202.127.0.42:32443".sslVerify = false;
credential.helper = "store";
merge.conflictstyle = "zdiff3";
pull.rebase = true;
push.autoSetupRemote = true;
init.defaultBranch = "main";
rerere.enabled = true;
diff.algorithm = "histogram";
core.autocrlf = "input";
};
};
# ── Lazygit ──────────────────────────────────────────
programs.lazygit = {
enable = true;
settings = {
gui = {
nerdFontsVersion = "3";
showBottomLine = false;
};
git.paging = {
pager = "delta --paging=never";
};
update.method = "never";
disableStartupPopups = true;
};
};
# ── GitHub CLI ───────────────────────────────────────
programs.gh = {
enable = true;
settings = {
git_protocol = "ssh";
};
};
}
+41
View File
@@ -0,0 +1,41 @@
{ pkgs, ... }:
{
home.packages = with pkgs; [
# ── Language runtimes ──
nodejs
go
bun
# ── Package management / version management ──
mise
uv
# ── LSP servers ──
bash-language-server
gopls
typescript-language-server
yaml-language-server
vue-language-server
dockerfile-language-server-nodejs
lua-language-server
nil # Nix LSP
# ── Linter / Formatter ──
biome
ruff
shellcheck
shfmt
nixfmt-rfc-style # nix formatter
stylua
# ── Code intelligence ──
ast-grep
];
# ── mise config ──────────────────────────────────────
xdg.configFile."mise/config.toml".text = ''
[settings]
trusted_config_paths = ["/"]
'';
}
+24
View File
@@ -0,0 +1,24 @@
{ pkgs, ... }:
{
programs.neovim = {
enable = true;
defaultEditor = true;
viAlias = true;
vimAlias = true;
withNodeJs = true;
withPython3 = true;
};
# ── Neovim distro configuration ──
# Option A: LazyVim / NvChad / AstroNvim via xdg.configFile
# xdg.configFile."nvim" = {
# source = ./nvim-config;
# recursive = true;
# };
#
# Option B: NixVim (fully declarative)
# Add to flake.nix inputs:
# nixvim.url = "github:nix-community/nixvim";
# Then configure here.
}
-36
View File
@@ -1,36 +0,0 @@
{ config, ... }:
{
programs.git = {
enable = true;
# user.name 和 user.email 需要每人自行设置:
# git config --global user.name "你的名字"
# git config --global user.email "你的邮箱"
delta = {
enable = true;
options = {
navigate = true;
side-by-side = true;
line-numbers = true;
};
};
extraConfig = {
# 内部 Git 服务器(跳过 SSL 验证)
http = {
"https://202.127.0.42:32443" = {
sslVerify = false;
};
};
credential.helper = "store";
merge.conflictstyle = "zdiff3";
pull.rebase = true;
push.autoSetupRemote = true;
init.defaultBranch = "main";
rerere.enabled = true;
};
};
}
-137
View File
@@ -1,137 +0,0 @@
{ config, pkgs, ... }:
{
# ── Zsh ──────────────────────────────────────────────
programs.zsh = {
enable = true;
autocd = true; # setopt AUTO_CD
oh-my-zsh = {
enable = true;
plugins = [
"git" # git 别名 (gst, gco, gp...)
"sudo" # 双击 ESC 自动加 sudo
"extract" # x file.tar.gz 一键解压
"direnv" # direnv hook
];
};
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
shellAliases = {
# 导航
cd = "z";
cdi = "zi";
".." = "cd ..";
"..." = "cd ../..";
# 文件列表
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";
# 工具
cat = "bat --paging=never";
rm = "trash-put";
lg = "lazygit";
vi = "nvim";
# 网络
http = "xh";
};
initExtra = ''
# Shell
setopt INTERACTIVE_COMMENTS
setopt NO_BEEP
# PATH go/bun
export PATH="$HOME/go/bin:$HOME/.bun/bin:$PATH"
# fzf-tab
# : ls $(nix eval --raw nixpkgs#zsh-fzf-tab)/share/
source ${pkgs.zsh-fzf-tab}/share/fzf-tab/fzf-tab.plugin.zsh
# mise
eval "$(mise activate zsh)"
# WSL
if [[ -n "$WSL_DISTRO_NAME" ]]; then
alias pbcopy="clip.exe"
alias pbpaste="powershell.exe -noprofile -c Get-Clipboard"
fi
#
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
'';
};
# ── Starship 提示符 ──────────────────────────────────
programs.starship = {
enable = true;
enableZshIntegration = true;
settings = {
format = "$username$hostname$directory$git_branch$git_status$nodejs$python$go$rust$cmd_duration$line_break$character";
character = {
success_symbol = "[](bold green)";
error_symbol = "[](bold red)";
};
directory = {
truncation_length = 3;
truncation_symbol = "/";
};
git_branch.symbol = " ";
git_status.format = "([\\[$all_status$ahead_behind\\]]($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) ";
};
};
# ── FZF ──────────────────────────────────────────────
programs.fzf = {
enable = true;
enableZshIntegration = true;
};
# ── Atuin(历史搜索,接管 Ctrl+R)──────────────────
programs.atuin = {
enable = true;
enableZshIntegration = true;
};
# ── Zoxide(智能 cd)─────────────────────────────────
programs.zoxide = {
enable = true;
enableZshIntegration = true;
};
# ── Direnv ───────────────────────────────────────────
programs.direnv = {
enable = true;
enableZshIntegration = true;
nix-direnv.enable = true; # 更好的 Nix devShell 集成
};
# ── Bat ──────────────────────────────────────────────
programs.bat.enable = true;
# ── Yazi ─────────────────────────────────────────────
programs.yazi.enable = true;
}
+8
View File
@@ -0,0 +1,8 @@
{
imports = [
./zsh.nix
./starship.nix
./tools.nix
./tmux.nix
];
}
+85
View File
@@ -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) ";
};
};
}
+51
View File
@@ -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
'';
};
}
+92
View File
@@ -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
];
}
+72
View File
@@ -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
'';
};
}
+10
View File
@@ -0,0 +1,10 @@
{ ... }:
{
catppuccin = {
enable = true;
flavor = "mocha";
# Automatically themes all supported programs that are enabled:
# bat, btop, delta, fzf, lazygit, starship, tmux, zsh-syntax-highlighting, etc.
};
}
+6 -30
View File
@@ -1,40 +1,16 @@
{ config, pkgs, ... }: { username, ... }:
let
username = "dev"; # ← 修改此处设置用户名
in
{ {
# ── 引导 ───────────────────────────────────────────── # ── Boot ─────────────────────────────────────────────
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
# ── 网络 ───────────────────────────────────────────── # ── Network ──────────────────────────────────────────
networking.hostName = "nixos";
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
users.users.${username}.extraGroups = [ "networkmanager" ];
# ── 用户 ───────────────────────────────────────────── # ── Hardware ─────────────────────────────────────────
users.users.${username} = { # After first install, generate and uncomment:
isNormalUser = true;
extraGroups = [
"wheel"
"docker"
"networkmanager"
];
shell = pkgs.zsh;
};
# ── Home Manager ─────────────────────────────────────
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.${username} = import ../../home;
};
# ── sudo ─────────────────────────────────────────────
security.sudo.wheelNeedsPassword = false;
# ── 硬件 ─────────────────────────────────────────────
# 首次安装后生成硬件配置并取消注释:
# sudo nixos-generate-config --show-hardware-config > hosts/bare/hardware-configuration.nix # sudo nixos-generate-config --show-hardware-config > hosts/bare/hardware-configuration.nix
# imports = [ ./hardware-configuration.nix ]; # imports = [ ./hardware-configuration.nix ];
+11
View File
@@ -0,0 +1,11 @@
{ username, ... }:
{
# ── macOS host-specific configuration ────────────────
# Uncomment and configure when macOS machine is available.
# Touch ID for sudo
# security.pam.services.sudo_local.touchIdAuth = true;
# system.stateVersion = 5;
}
+1 -26
View File
@@ -1,8 +1,5 @@
{ config, pkgs, ... }: { username, ... }:
let
username = "dev"; # ← 修改此处设置用户名
in
{ {
# ── WSL ────────────────────────────────────────────── # ── WSL ──────────────────────────────────────────────
wsl = { wsl = {
@@ -10,27 +7,5 @@ in
defaultUser = username; defaultUser = username;
}; };
networking.hostName = "nixos-wsl";
# ── 用户 ─────────────────────────────────────────────
users.users.${username} = {
isNormalUser = true;
extraGroups = [
"wheel"
"docker"
];
shell = pkgs.zsh;
};
# ── Home Manager ─────────────────────────────────────
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.${username} = import ../../home;
};
# ── sudo ─────────────────────────────────────────────
security.sudo.wheelNeedsPassword = false;
system.stateVersion = "24.11"; system.stateVersion = "24.11";
} }
+86
View File
@@ -0,0 +1,86 @@
{ inputs }:
let
inherit (inputs.nixpkgs) lib;
# Shared home-manager configuration block
homeManagerConfig = username: {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit inputs username;
};
users.${username} = import ../home;
};
};
in
{
# ── NixOS host builder ──────────────────────────────
mkNixos =
{
hostname,
system,
username,
extraModules ? [ ],
}:
lib.nixosSystem {
inherit system;
specialArgs = {
inherit inputs hostname username;
};
modules =
[
../modules/shared
../modules/nixos
inputs.home-manager.nixosModules.home-manager
inputs.catppuccin.nixosModules.catppuccin
(homeManagerConfig username)
{ networking.hostName = hostname; }
]
++ extraModules;
};
# ── nix-darwin host builder ─────────────────────────
mkDarwin =
{
hostname,
system,
username,
extraModules ? [ ],
}:
inputs.nix-darwin.lib.darwinSystem {
inherit system;
specialArgs = {
inherit inputs hostname username;
};
modules =
[
../modules/shared
../modules/darwin
inputs.home-manager.darwinModules.home-manager
inputs.catppuccin.nixosModules.catppuccin
(homeManagerConfig username)
{ networking.hostName = hostname; }
]
++ extraModules;
};
# ── Standalone Home Manager (no NixOS / no Darwin) ──
mkHome =
{
system,
username,
}:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
extraSpecialArgs = {
inherit inputs username;
hostname = "standalone";
};
modules = [ ../home ];
};
}
-49
View File
@@ -1,49 +0,0 @@
{ config, pkgs, ... }:
{
environment.systemPackages = with pkgs; [
# ── 核心工具 ──
curl
git
micro
vim
wget
# ── 现代 CLI 替代 ──
bat # cat
btop # top
duf # df
dust # du
eza # ls
fd # find
jq # JSON
procs # ps
ripgrep # grep
sd # sed
xh # curl/httpie
yq # YAML
# ── 文件管理 ──
trash-cli
yazi
# ── 系统信息 ──
fastfetch
tealdeer # tldr
];
# ── Nix 设置 ──
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
];
# 国内镜像(按需取消注释)
# substituters = [
# "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
# "https://cache.nixos.org"
# ];
};
nixpkgs.config.allowUnfree = true;
}
+46
View File
@@ -0,0 +1,46 @@
{ pkgs, username, ... }:
{
# ── Shell ──────────────────────────────────────────
programs.zsh.enable = true;
# ── User ───────────────────────────────────────────
users.users.${username} = {
home = "/Users/${username}";
shell = pkgs.zsh;
};
# ── Fonts ──────────────────────────────────────────
fonts.packages = with pkgs; [
maple-mono.NF-CN-unhinted
nerd-fonts.symbols-only
];
# ── macOS system preferences ───────────────────────
system.defaults = {
dock = {
autohide = true;
show-recents = false;
mru-spaces = false;
};
finder = {
AppleShowAllExtensions = true;
FXPreferredViewStyle = "clmv";
};
NSGlobalDomain = {
AppleShowAllExtensions = true;
InitialKeyRepeat = 15;
KeyRepeat = 2;
};
};
# ── Homebrew (GUI apps not in nixpkgs) ─────────────
# homebrew = {
# enable = true;
# casks = [
# "raycast"
# "arc"
# ];
# onActivation.cleanup = "zap";
# };
}
-54
View File
@@ -1,54 +0,0 @@
{ config, pkgs, ... }:
{
environment.systemPackages = with pkgs; [
# ── 语言运行时 ──
bun
go
nodejs
# ── 包管理 / 版本管理 ──
mise
uv
# ── 编辑器 ──
neovim
# ── 终端复用 ──
tmux
zellij
# ── Git 增强 ──
delta # Arch 包名: git-delta
gh # Arch 包名: github-cli
lazygit
# ── Linter / Formatter ──
biome
ruff
shellcheck
shfmt
# ── LSP 服务器 ──
ast-grep
bash-language-server
gopls
typescript-language-server # 若报错尝试 nodePackages.typescript-language-server
yaml-language-server # 若报错尝试 nodePackages.yaml-language-server
vue-language-server # 替代原 bun -g @vue/language-server
dockerfile-language-server-nodejs # 替代原 bun -g dockerfile-language-server
# ── 原 bun/go 全局安装的工具 ──
# 以下工具如果在 nixpkgs 中不存在,需要自定义打包:
#
# opencode-ai:
# buildNpmPackage { pname = "opencode-ai"; ... }
#
# go-claude-code-comment-checker:
# buildGoModule {
# pname = "comment-checker";
# src = fetchFromGitHub { owner = "code-yeongyu"; repo = "..."; ... };
# vendorHash = "sha256-...";
# }
];
}
+18
View File
@@ -0,0 +1,18 @@
{ pkgs, ... }:
{
# ── System-essential packages ──────────────────────
# User-level tools live in home-manager (home/)
environment.systemPackages = with pkgs; [
curl
git
vim
wget
];
# ── Fonts ──────────────────────────────────────────
fonts.packages = with pkgs; [
maple-mono.NF-CN-unhinted
nerd-fonts.symbols-only
];
}
+22
View File
@@ -0,0 +1,22 @@
{ pkgs, username, ... }:
{
imports = [
./base.nix
./docker.nix
./locale.nix
];
# ── Default shell ──────────────────────────────────
programs.zsh.enable = true;
# ── Default user ───────────────────────────────────
users.users.${username} = {
isNormalUser = true;
shell = pkgs.zsh;
extraGroups = [ "wheel" ];
};
# ── sudo ───────────────────────────────────────────
security.sudo.wheelNeedsPassword = false;
}
@@ -1,16 +1,14 @@
{ config, pkgs, ... }: { pkgs, username, ... }:
{ {
virtualisation.docker = { virtualisation.docker.enable = true;
enable = true;
}; users.users.${username}.extraGroups = [ "docker" ];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
docker-compose docker-compose
]; ];
# 注:用户 docker 组权限在 hosts/*/default.nix 中配置
#
# WSL 环境下如使用 Docker Desktop,可改为: # WSL 环境下如使用 Docker Desktop,可改为:
# wsl.docker-desktop.enable = true; # wsl.docker-desktop.enable = true;
# 并将上面的 virtualisation.docker.enable 设为 false # 并将上面的 virtualisation.docker.enable 设为 false
@@ -1,8 +1,10 @@
{ config, ... }: { ... }:
{ {
i18n = { i18n = {
defaultLocale = "en_US.UTF-8"; defaultLocale = "en_US.UTF-8";
supportedLocales = [ "en_US.UTF-8/UTF-8" ]; supportedLocales = [ "en_US.UTF-8/UTF-8" ];
}; };
time.timeZone = "Asia/Shanghai";
} }
+3
View File
@@ -0,0 +1,3 @@
{
imports = [ ./nix.nix ];
}
+18
View File
@@ -0,0 +1,18 @@
{ lib, ... }:
{
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
];
warn-dirty = false;
# 国内镜像(按需取消注释)
# substituters = [
# "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
# "https://cache.nixos.org"
# ];
};
nixpkgs.config.allowUnfree = true;
}
-6
View File
@@ -1,6 +0,0 @@
{ config, pkgs, ... }:
{
# 系统级启用 Zsh(用户级配置在 home/shell.nix
programs.zsh.enable = true;
}
+7
View File
@@ -0,0 +1,7 @@
final: prev: {
# ── Custom overlays ──────────────────────────────────
# Override or extend nixpkgs packages here.
#
# Example:
# my-tool = final.callPackage ../pkgs/my-tool { };
}
+21
View File
@@ -0,0 +1,21 @@
{ pkgs }:
{
# ── Custom packages ──────────────────────────────────
# Packages not in nixpkgs. Build with callPackage.
#
# Example:
# opencode-ai = pkgs.callPackage ./opencode-ai { };
#
# go-comment-checker = pkgs.buildGoModule {
# pname = "comment-checker";
# version = "0.1.0";
# src = pkgs.fetchFromGitHub {
# owner = "code-yeongyu";
# repo = "go-claude-code-comment-checker";
# rev = "...";
# hash = "sha256-...";
# };
# vendorHash = "sha256-...";
# };
}
+31 -5
View File
@@ -1,11 +1,10 @@
#!/bin/bash #!/bin/bash
# NixOS 配置安装脚本 # NixOS / standalone Home Manager 安装脚本
# 在 NixOS-WSL 或裸机 NixOS 中运行
set -euo pipefail set -euo pipefail
REPO_URL="https://git.furtherverse.com/imbytecat/nix-config.git" REPO_URL="https://git.furtherverse.com/imbytecat/nix-config.git"
CONFIG_DIR="$HOME/.config/nix-config" CONFIG_DIR="$HOME/.config/nix-config"
FLAKE_TARGET="${1:-wsl}" # 默认 wsl,裸机传入 bare FLAKE_TARGET="${1:-wsl}" # wsl (default), bare, or home
echo "📥 获取配置仓库..." echo "📥 获取配置仓库..."
if [[ -d "$CONFIG_DIR/.git" ]]; then if [[ -d "$CONFIG_DIR/.git" ]]; then
@@ -15,11 +14,38 @@ else
git clone "$REPO_URL" "$CONFIG_DIR" git clone "$REPO_URL" "$CONFIG_DIR"
fi fi
echo "⚙️ 应用系统配置(目标: $FLAKE_TARGET..." echo "⚙️ 应用配置(目标: $FLAKE_TARGET..."
sudo nixos-rebuild switch --flake "$CONFIG_DIR#$FLAKE_TARGET"
case "$FLAKE_TARGET" in
wsl|bare)
sudo nixos-rebuild switch --flake "$CONFIG_DIR#$FLAKE_TARGET"
echo "" echo ""
echo "🎉 安装完成!请重新登录以使用 zsh。" echo "🎉 安装完成!请重新登录以使用 zsh。"
echo "" echo ""
echo "后续更新:" echo "后续更新:"
echo " cd $CONFIG_DIR && git pull && sudo nixos-rebuild switch --flake .#$FLAKE_TARGET" echo " cd $CONFIG_DIR && git pull && sudo nixos-rebuild switch --flake .#$FLAKE_TARGET"
;;
home)
# Standalone home-manager(非 NixOS 系统:Ubuntu、Fedora、macOS 等)
HM_USER="$(whoami)"
if ! command -v home-manager &>/dev/null; then
echo "📦 首次运行 home-manager..."
nix run home-manager/master -- switch --flake "$CONFIG_DIR#$HM_USER"
else
home-manager switch --flake "$CONFIG_DIR#$HM_USER"
fi
echo ""
echo "🎉 Home Manager 配置已应用!"
echo ""
echo "后续更新:"
echo " cd $CONFIG_DIR && git pull && home-manager switch --flake .#$HM_USER"
;;
*)
echo "❌ 未知目标: $FLAKE_TARGET"
echo "用法: $0 [wsl|bare|home]"
echo " wsl — NixOS on WSL (默认)"
echo " bare — NixOS 裸机"
echo " home — 独立 Home Manager (非 NixOS)"
exit 1
;;
esac