refactor: KISS cleanup — deduplicate shared config, merge thin files

- Extract fonts, fish.enable, openssh.enable to modules/shared/
- Centralize sshKeys in lib/ via specialArgs
- Merge nixos/base.nix + locale.nix into nixos/default.nix
- Merge home/theme.nix into home/default.nix
- Simplify homeManagerConfig, flake packages output
- Remove redundant vim/wget from NixOS system packages
- Update AGENTS.md to reflect new structure
This commit is contained in:
2026-04-13 22:25:55 +08:00
parent d7e0aaf798
commit be247ff3b9
12 changed files with 121 additions and 134 deletions
+8 -6
View File
@@ -13,11 +13,11 @@ flake.nix
└── nixosConfigurations.wsl (x86_64-linux) └── nixosConfigurations.wsl (x86_64-linux)
``` ```
- `lib/default.nix` — builders: `mkDarwin`, `mkNixos`. All hosts get shared modules + home-manager + lazyvim-nix (as HM sharedModule). NixOS also gets `catppuccin.nixosModules.catppuccin`; home-manager imports `catppuccin.homeModules.catppuccin` directly in `home/default.nix`. - `lib/default.nix` — builders `mkDarwin`/`mkNixos`, shared `sshKeys` constant (passed via `specialArgs`), `homeManagerConfig` helper. NixOS also gets `catppuccin.nixosModules.catppuccin`.
- `modules/shared/` — both platforms: nixpkgs config, overlays, nix settings, Lix - `modules/shared/` — both platforms: nix/nixpkgs settings (Lix, overlays), fonts, `programs.fish.enable`, `services.openssh.enable`
- `modules/darwin/` — macOS: system preferences, homebrew (casks/brews/masApps), fonts, fish shell, user - `modules/darwin/` — macOS: system preferences, homebrew (casks/brews/masApps), 1Password CLI, user
- `modules/nixos/` — NixOS: base packages, docker, locale, user - `modules/nixos/` — NixOS: system packages, locale/timezone, docker, user
- `home/` — home-manager (shared across all hosts via `useGlobalPkgs`) - `home/` — home-manager (shared across all hosts via `useGlobalPkgs`), catppuccin theme
- `hosts/*/` — per-host overrides (mac-mini: 24/7 server with sleep disabled; macbook-air: portable) - `hosts/*/` — per-host overrides (mac-mini: 24/7 server with sleep disabled; macbook-air: portable)
- `overlays/` + `pkgs/` — custom packages (comment-checker) - `overlays/` + `pkgs/` — custom packages (comment-checker)
@@ -59,7 +59,9 @@ cd ~/nix-config && sudo nixos-rebuild switch --flake .#wsl
## Critical gotchas ## Critical gotchas
- **Neovim uses lazyvim-nix**: `programs.lazyvim` in `home/dev/neovim.nix` manages neovim via the `lazyvim-nix` flake input. Catppuccin nvim integration is explicitly disabled (`catppuccin.nvim.enable = false`) because LazyVim manages its own colorscheme. Don't try to use `catppuccin.enable` for nvim or the old `programs.neovim.plugins` approach. - **Shared settings live in `modules/shared/`**: Fish, openssh, fonts, nix settings are enabled once in shared — don't re-declare in platform modules.
- **SSH keys are centralized**: Defined as `sshKeys` in `lib/default.nix`, passed via `specialArgs`. Don't hardcode keys in platform modules.
- **Neovim uses lazyvim-nix**: `programs.lazyvim` in `home/dev/neovim.nix` manages neovim via the `lazyvim-nix` flake input. Catppuccin nvim integration is explicitly disabled (`catppuccin.nvim.enable = false`) because LazyVim manages its own colorscheme. Don't use `catppuccin.enable` for nvim or the old `programs.neovim.plugins` approach.
- **catppuccin module name**: Home-manager uses `catppuccin.homeModules.catppuccin` (imported in `home/default.nix`). NixOS uses `catppuccin.nixosModules.catppuccin` (in `lib/default.nix`). Don't use the old `homeManagerModules` name. - **catppuccin module name**: Home-manager uses `catppuccin.homeModules.catppuccin` (imported in `home/default.nix`). NixOS uses `catppuccin.nixosModules.catppuccin` (in `lib/default.nix`). Don't use the old `homeManagerModules` name.
- **Homebrew tap casks**: Casks from taps need full path (e.g. `"goooler/repo/fl-clash"`), not just the short name. - **Homebrew tap casks**: Casks from taps need full path (e.g. `"goooler/repo/fl-clash"`), not just the short name.
- **`onActivation.cleanup = "zap"`**: Any brew formula/cask NOT declared in `modules/darwin/default.nix` WILL be removed on rebuild. Be comprehensive. - **`onActivation.cleanup = "zap"`**: Any brew formula/cask NOT declared in `modules/darwin/default.nix` WILL be removed on rebuild. Be comprehensive.
+10 -5
View File
@@ -68,13 +68,18 @@
}; };
# ── Packages ──────────────────────────────────────── # ── Packages ────────────────────────────────────────
packages = nixpkgs.lib.genAttrs [ "aarch64-darwin" "x86_64-linux" ] (system: { packages = nixpkgs.lib.genAttrs [ "aarch64-darwin" "x86_64-linux" ] (
comment-checker = system:
(import nixpkgs { let
pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ self.overlays.default ]; overlays = [ self.overlays.default ];
}).comment-checker; };
}); in
{
inherit (pkgs) comment-checker;
}
);
# ── Overlays ─────────────────────────────────────── # ── Overlays ───────────────────────────────────────
overlays.default = import ./overlays; overlays.default = import ./overlays;
+31 -32
View File
@@ -10,9 +10,13 @@
inputs.catppuccin.homeModules.catppuccin inputs.catppuccin.homeModules.catppuccin
./shell ./shell
./dev ./dev
./theme.nix
]; ];
catppuccin = {
enable = true;
flavor = "mocha";
};
home = { home = {
username = username; username = username;
homeDirectory = if pkgs.stdenv.isDarwin then "/Users/${username}" else "/home/${username}"; homeDirectory = if pkgs.stdenv.isDarwin then "/Users/${username}" else "/home/${username}";
@@ -20,42 +24,37 @@
}; };
# ── User-level packages ──────────────────────────── # ── User-level packages ────────────────────────────
home.packages = home.packages = with pkgs; [
with pkgs; # Modern CLI replacements
[ dust # du
# Modern CLI replacements duf # df
dust # du procs # ps
duf # df sd # sed
procs # ps jq # JSON
sd # sed yq # YAML
jq # JSON wget
yq # YAML
wget
# System info # System info
fastfetch fastfetch
tealdeer # tldr tealdeer # tldr
# File management # File management
gomi gomi
# Nix tools # Nix tools
nix-output-monitor # nom nix-output-monitor # nom
nvd # nix version diff nvd # nix version diff
nh # nix helper nh # nix helper
just just
# Secrets management (WSL uses Windows op.exe via interop) # AI coding agent
] opencode
++ (with pkgs; [ comment-checker
# AI coding agent
opencode
comment-checker
# Misc # Misc
ffmpeg ffmpeg
pandoc pandoc
]); ];
# XDG directories # XDG directories
xdg.enable = true; xdg.enable = true;
-8
View File
@@ -1,8 +0,0 @@
{ ... }:
{
catppuccin = {
enable = true;
flavor = "mocha";
};
}
+30 -22
View File
@@ -3,27 +3,25 @@
let let
inherit (inputs.nixpkgs) lib; inherit (inputs.nixpkgs) lib;
sshKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDRTOo48gzzRGT+bF9dzJCFJu61YgsQVONFtxU9kTPIg"
];
# Shared home-manager configuration block # Shared home-manager configuration block
homeManagerConfig = homeManagerConfig = username: {
{ home-manager = {
username, useGlobalPkgs = true;
sharedModules ? [ ], useUserPackages = true;
}: backupFileExtension = "bak";
{ sharedModules = [
home-manager = { inputs.lazyvim.homeManagerModules.default
useGlobalPkgs = true; ];
useUserPackages = true; extraSpecialArgs = {
backupFileExtension = "bak"; inherit inputs username;
sharedModules = [
inputs.lazyvim.homeManagerModules.default
]
++ sharedModules;
extraSpecialArgs = {
inherit inputs username;
};
users.${username} = import ../home;
}; };
users.${username} = import ../home;
}; };
};
in in
{ {
# ── NixOS host builder ────────────────────────────── # ── NixOS host builder ──────────────────────────────
@@ -37,14 +35,19 @@ in
lib.nixosSystem { lib.nixosSystem {
inherit system; inherit system;
specialArgs = { specialArgs = {
inherit inputs hostname username; inherit
inputs
hostname
username
sshKeys
;
}; };
modules = [ modules = [
../modules/shared ../modules/shared
../modules/nixos ../modules/nixos
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
inputs.catppuccin.nixosModules.catppuccin inputs.catppuccin.nixosModules.catppuccin
(homeManagerConfig { inherit username; }) (homeManagerConfig username)
{ networking.hostName = hostname; } { networking.hostName = hostname; }
] ]
++ extraModules; ++ extraModules;
@@ -61,13 +64,18 @@ in
inputs.nix-darwin.lib.darwinSystem { inputs.nix-darwin.lib.darwinSystem {
inherit system; inherit system;
specialArgs = { specialArgs = {
inherit inputs hostname username; inherit
inputs
hostname
username
sshKeys
;
}; };
modules = [ modules = [
../modules/shared ../modules/shared
../modules/darwin ../modules/darwin
inputs.home-manager.darwinModules.home-manager inputs.home-manager.darwinModules.home-manager
(homeManagerConfig { inherit username; }) (homeManagerConfig username)
{ networking.hostName = hostname; } { networking.hostName = hostname; }
] ]
++ extraModules; ++ extraModules;
+8 -17
View File
@@ -1,35 +1,26 @@
{ pkgs, username, ... }: {
pkgs,
username,
sshKeys,
...
}:
{ {
# ── Primary user (required by nix-darwin) ────────── # ── Primary user (required by nix-darwin) ──────────
system.primaryUser = username; system.primaryUser = username;
# ── Shell ──────────────────────────────────────────
programs.fish.enable = true;
# ── 1Password CLI ─────────────────────────────────── # ── 1Password CLI ───────────────────────────────────
programs._1password.enable = true; programs._1password.enable = true;
# ── SSH ───────────────────────────────────────────
services.openssh.enable = true;
# ── User ─────────────────────────────────────────── # ── User ───────────────────────────────────────────
users.knownUsers = [ username ]; users.knownUsers = [ username ];
users.users.${username} = { users.users.${username} = {
home = "/Users/${username}"; home = "/Users/${username}";
shell = pkgs.fish; shell = pkgs.fish;
uid = 501; uid = 501;
openssh.authorizedKeys.keys = [ openssh.authorizedKeys.keys = sshKeys;
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDRTOo48gzzRGT+bF9dzJCFJu61YgsQVONFtxU9kTPIg"
];
}; };
# ── Fonts ──────────────────────────────────────────
fonts.packages = with pkgs; [
maple-mono.NF-CN-unhinted
nerd-fonts.symbols-only
];
# ── macOS system preferences ─────────────────────── # ── macOS system preferences ───────────────────────
system.defaults = { system.defaults = {
LaunchServices.LSQuarantine = false; LaunchServices.LSQuarantine = false;
@@ -65,7 +56,7 @@
]; ];
brews = [ brews = [
"mole" # broken in nixpkgs "mole"
]; ];
# GUI apps # GUI apps
-19
View File
@@ -1,19 +0,0 @@
{ pkgs, ... }:
{
# ── System-essential packages ──────────────────────
# User-level tools live in home-manager (home/)
environment.systemPackages = with pkgs; [
curl
git
ghostty.terminfo
vim
wget
];
# ── Fonts ──────────────────────────────────────────
fonts.packages = with pkgs; [
maple-mono.NF-CN-unhinted
nerd-fonts.symbols-only
];
}
+19 -10
View File
@@ -1,26 +1,35 @@
{ pkgs, username, ... }: {
pkgs,
username,
sshKeys,
...
}:
{ {
imports = [ imports = [
./base.nix
./docker.nix ./docker.nix
./locale.nix
]; ];
# ── Default shell ────────────────────────────────── # ── System-essential packages ──────────────────────
programs.fish.enable = true; environment.systemPackages = with pkgs; [
curl
git
ghostty.terminfo
];
# ── SSH ────────────────────────────────────────── # ── Locale / Timezone ──────────────────────────────
services.openssh.enable = true; i18n = {
defaultLocale = "en_US.UTF-8";
supportedLocales = [ "en_US.UTF-8/UTF-8" ];
};
time.timeZone = "Asia/Shanghai";
# ── Default user ─────────────────────────────────── # ── Default user ───────────────────────────────────
users.users.${username} = { users.users.${username} = {
isNormalUser = true; isNormalUser = true;
shell = pkgs.fish; shell = pkgs.fish;
extraGroups = [ "wheel" ]; extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [ openssh.authorizedKeys.keys = sshKeys;
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDRTOo48gzzRGT+bF9dzJCFJu61YgsQVONFtxU9kTPIg"
];
}; };
# ── sudo ─────────────────────────────────────────── # ── sudo ───────────────────────────────────────────
-4
View File
@@ -8,8 +8,4 @@
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
docker-compose docker-compose
]; ];
# WSL 环境下如使用 Docker Desktop,可改为:
# wsl.docker-desktop.enable = true;
# 并将上面的 virtualisation.docker.enable 设为 false
} }
-10
View File
@@ -1,10 +0,0 @@
{ ... }:
{
i18n = {
defaultLocale = "en_US.UTF-8";
supportedLocales = [ "en_US.UTF-8/UTF-8" ];
};
time.timeZone = "Asia/Shanghai";
}
+7 -1
View File
@@ -1,3 +1,9 @@
{ {
imports = [ ./nix.nix ]; imports = [
./fonts.nix
./nix.nix
];
programs.fish.enable = true;
services.openssh.enable = true;
} }
+8
View File
@@ -0,0 +1,8 @@
{ pkgs, ... }:
{
fonts.packages = with pkgs; [
maple-mono.NF-CN-unhinted
nerd-fonts.symbols-only
];
}