Compare commits

..

11 Commits

Author SHA1 Message Date
luochen570
575529f159 modified: README.md
modified:   modules/server/README.md
	new file:   modules/server/lxc-ssh.nix
	modified:   profiles/lxc.nix
2026-05-27 07:02:37 +08:00
luochen570
a2bd672cf7 refactor: move sudo to core, lxc SSH to profile, clean up old lxc config
- sudo (wheelNeedsPassword) → modules/core/core.nix (全局)
- LXC SSH override (PermitRootLogin, PasswordAuth) → profiles/lxc.nix
- modules/server/ssh.nix: use mkDefault so profiles can override
- Delete modules/optional/lxc.nix
- Clean up hosts/nixos-lxc/configuration.nix: remove redundant SSH/sudo/users
  (now handled by core + server + profile chain)
- Update modules/optional/README.md
2026-05-27 06:47:50 +08:00
luochen570
d9b2204f19 refactor: move optional modules to modules/optional/
- Move virtualbox-guest.nix and vscode-server.nix from modules/server/ to modules/optional/
- Create modules/optional/README.md with usage docs
- Update profiles/virtualbox.nix and profiles/wsl.nix import paths
- Update modules/server/README.md to reflect removal
- Update root README.md directory tree with optional/ entry
2026-05-26 13:15:58 +08:00
luochen570
e3644993ec fix: pass inputs as specialArg to wsl config 2026-05-26 13:03:04 +08:00
luochen570
e279b207f8 fix: add username param to wsl configuration.nix 2026-05-26 13:02:47 +08:00
luochen570
88414eb346 fix: replace invalid 'options' attr with setopt in initExtra
home-manager's programs.zsh has no 'options' attribute.
Use 'setopt correct' and 'setopt interactive_comments' inside initExtra instead.
2026-05-26 12:50:23 +08:00
luochen570
14e57c9096 fix: add missing packages for zsh aliases and plugins
- home/pkg.nix: add eza, bat, ack, fzf
- modules/core/pkg.nix: add kubectl (for OMZ kubectl plugin)
2026-05-26 12:46:55 +08:00
luochen570
4349da57ea sync: align home-manager zsh.nix with actual .zshrc
- Add envExtra: PATH, XDG_CONFIG_HOME, POWERLEVEL9K_INSTANT_PROMPT, .hermes/node/bin
- Add shell options: correct, interactive_comments
- Add initExtra: p10k instant prompt, y() function, proxy-on/off aliases
- Add missing aliases: cd -# (1-9), _ (sudo), rd, grep variants, afind, globurl
- Add missing OMZ plugins: command-not-found, colored-man-pages, kubectl
2026-05-26 12:45:07 +08:00
luochen570
e6f99590c5 docs: update README to match current structure
- Add README.md paths in directory tree (hosts/, profiles/, home/)
- Add category descriptions to profiles
- Mark nixos-lxc as s0.sermc.net
- Add note about per-host README.md
2026-05-26 12:42:42 +08:00
luochen570
33c7f0b6fd sync: merge s0.sermc.net LXC configuration
- Add users.luochen570 user config
- Add nix substituters (Tsinghua mirror)
- Add nix experimental-features (nix-command, flakes)
- Set system.stateVersion to 25.05
2026-05-26 12:40:25 +08:00
luochen570
c92c904e76 chore: clean up and optimize nixos configuration
- fix: nvidia.nix missing semicolon (build error)
- remove: ranger, vim from core/pkg.nix (yazi + neovim covers)
- remove: htop duplicate in home/pkg.nix (keep in system)
- replace: neofetch with fastfetch in home/pkg.nix
- remove: nixd LSP, keep nil only in nvchad.nix
- remove: empty server/pkg.nix and no-op server/firewall.nix
- remove: redundant services.pulseaudio.enable = false default
- add: comprehensive README.md documenting architecture
2026-05-24 10:36:23 +08:00
22 changed files with 296 additions and 145 deletions

129
README.md
View File

@@ -1,32 +1,113 @@
# 📦 nixos 配置仓库 # NixOS Configuration
基于 Flake 的 NixOS 多主机配置 洛尘luochen570的 NixOS 配置仓库,采用 Flakes + home-manager + sops-nix 架构
## 🌲 目录树 ## 架构
```text
📦 nixos ```
├─ 🏠 home/ # Home Manager 用户配置default.nix 聚合) nixos/
├─ 🖥️ hosts/ # 主机入口 ├── flake.nix # Flake 入口
├─ 🧩 lib/ # 公共函数mkHost ├─ lib/
├─ 🧱 modules/ # 系统模块core/server/wsl │ ├── mkHost.nix # 主机生成函数
├─ 🎨 overlays/ # 包覆盖 │ └── hosts.nix # 主机定义
├─ 📚 profiles/ # 场景组合desktop/server/wsl/virtualbox/lxc ├─ profiles/ # 角色配置组合
└─ 🔐 secrets/ # sops 密钥模板与密文 │ ├── README.md
│ ├── desktop.nix # 桌面机
│ ├── server.nix # 服务器
│ ├── wsl.nix # WSL (Debian/Windows)
│ ├── virtualbox.nix # VirtualBox 虚拟机
│ └── lxc.nix # Proxmox LXC 容器
├── modules/ # 模块化配置
│ ├── core/ # 所有机器共享的基础配置
│ │ ├── default.nix
│ │ ├── core.nix # Nix 设置、时区、语言、GC
│ │ ├── pkg.nix # 基础系统包
│ │ ├── users.nix # 用户与 Shell
│ │ └── sops.nix # 密钥管理
│ ├── server/ # 服务器模块(默认启用)
│ │ ├── default.nix
│ │ ├── docker.nix
│ │ └── ssh.nix
│ ├── optional/ # 选装模块(按需引用)
│ │ ├── README.md
│ │ ├── virtualbox-guest.nix # VirtualBox Guest 增强
│ │ └── vscode-server.nix # VS Code Server
│ ├── desktop/ # 桌面模块
│ │ ├── default.nix
│ │ ├── pkg.nix # 桌面应用包
│ │ ├── apps.nix # MIME 与默认应用
│ │ ├── fcitx5.nix # 中文输入法
│ │ └── de/
│ │ ├── default.nix
│ │ └── kde.nix # KDE Plasma 6 + SDDM
│ └── drivers/
│ ├── nvidia.nix # NVIDIA 独显
│ └── amdgpu.nix # AMD 核显RDNA2
├── home/ # home-manager 用户配置
│ ├── README.md
│ ├── default.nix
│ ├── pkg.nix # 用户级包
│ ├── git.nix
│ ├── ssh.nix # SSH 密钥sops 挂载)
│ ├── zsh.nix # ZSH + Powerlevel10k
│ └── nvchad.nix # Neovim (NvChad)
├── hosts/ # 主机专属配置
│ ├── README.md
│ ├── desktop/ # 桌面机AMD + NVIDIA
│ ├── server/ # 服务器
│ ├── wsl/ # WSL (NixOS-WSL)
│ ├── virtualbox/ # VirtualBox 虚拟机
│ └── nixos-lxc/ # Proxmox LXC 容器
└── secrets/ # sops-nix 加密密钥(不公开)
└── users/luochen570.enc.yaml
``` ```
## 🔗 引用关系 ## 主机列表
`flake.nix` -> `lib/hosts.nix` + `lib/mkHost.nix` -> `hosts/*` + `profiles/*` -> `modules/*/default.nix` -> 子模块
`networking.hostName``lib/mkHost.nix` 统一设置,具体值在 `lib/hosts.nix` 每台主机条目里定义。 | 主机 | 角色 | 架构 | 说明 |
|------|------|------|------|
| `desktop` | desktop | x86_64-linux | 桌面机NVIDIA + AMD 双显卡 |
| `server` | server | x86_64-linux | 服务器 |
| `nixos-wsl` | wsl | x86_64-linux | WSL |
| `virtualbox` | virtualbox | x86_64-linux | VirtualBox 虚拟机 |
| `nixos-lxc` | lxc | x86_64-linux | Proxmox LXC 容器 |
## 🌐 Nix 模块引入文件树 ## 使用
```text
flake.nix ```bash
├─ lib/hosts.nix # 构建/切换
├─ lib/mkHost.nix sudo nixos-rebuild switch --flake .#desktop
│ ├─ hosts/<hostname>/default.nix -> configuration.nix
│ ├─ profiles/<profile>.nix -> modules/* # 仅构建不切换
│ └─ home/default.nix -> home/*.nix sudo nixos-rebuild build --flake .#server
└─ modules/core/sops.nix -> secrets/users/*.enc.yaml
# 更新 flake lock
nix flake update
# 垃圾回收
sudo nix-collect-garbage --delete-older-than 14d
``` ```
## 关键特性
- **Flakes** — 可复现的 NixOS 配置
- **home-manager** — 用户级包与配置管理
- **sops-nix** — 加密存储 SSH 密钥、密码哈希等敏感信息
- **NixOS-WSL** — WSL 集成
- **KDE Plasma 6** — 桌面环境SDDM 显示管理器)
- **fcitx5 + Rime** — 中文输入法
- **Docker** — 容器运行时,自动每周清理
- **PipeWire** — 音频系统
- **Nix4NvChad** — Neovim (NvChad) 配置即代码
## 镜像源
使用 TUNA清华和 SJTU上交镜像加速 Nix 包下载,适合国内网络环境。
## 注意事项
- NVIDIA 模块的 PRIME双显卡切换方案已注释启用前需通过 `lspci` 确认 PCIe Bus ID
- LXC 容器使用 Proxmox LXC 模块,关闭了 systemd 挂载报错的服务
- `secrets/` 目录经过 sops 加密,需有对应 age key 才能解密
- 各主机目录下有各自的 `README.md`,含该主机的硬件信息与应用列表
- `modules/optional/` 下的模块为非默认启用,按需在 profile 中引用

View File

@@ -8,11 +8,10 @@
programs.nvchad = { programs.nvchad = {
enable = true; enable = true;
# 可选:添加你需要的语言服务器和工具 # NvChad 需要的额外包
extraPackages = with pkgs; [ extraPackages = with pkgs; [
# LSP 服务器 # LSP 服务器
nil # Nix LSP nil # Nix LSP
nixd # Nix 语言服务器(另一种选择)
marksman # Markdown LSP marksman # Markdown LSP
# 格式化工具 # 格式化工具

View File

@@ -1,10 +1,16 @@
{ pkgs, ... }: { pkgs, ... }:
{ {
home.packages = with pkgs;[ home.packages = with pkgs; [
# 文件/磁盘工具
duf duf
ncdu ncdu
yazi yazi
htop fastfetch
neofetch
# Shell 工具zsh aliases 依赖)
eza # ls/eza aliases
bat # cat alias (bat -pp)
ack # afind alias
fzf # fzf-tab 依赖
]; ];
} }

View File

@@ -1,10 +1,52 @@
{ config, pkgs, inputs, system, ... }: { config, pkgs, inputs, system, ... }:
{ programs.zsh = { {
programs.zsh = {
enable = true; enable = true;
enableCompletion = true; enableCompletion = true;
autosuggestion.enable = true; autosuggestion.enable = true;
syntaxHighlighting.enable = true; syntaxHighlighting.enable = true;
# initContent = "source ~/.p10k.zsh";
# 环境变量 - 对应 .zshrc 开头的环境设置
envExtra = ''
path=(~/.local/bin $path)
export XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}"
export POWERLEVEL9K_INSTANT_PROMPT=quiet
export PATH="$HOME/.hermes/node/bin:$PATH"
'';
# Shell 选项 - 对应 .zshrc 的 setoptNixOS 中需写在 initExtra 里)
# options 属性在 home-manager 中不存在,用 setopt 命令代替
# 初始化 - 对应 .zshrc 中的 Powerlevel10k instant prompt 和函数定义
initExtra = ''
# Shell options
setopt correct
setopt interactive_comments
# Powerlevel10k instant prompt
if [[ -r "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh" ]]; then
source "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh"
fi
# Powerlevel10k config
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# yazi: open and jump to last cwd
function y() {
local tmp cwd
tmp="$(mktemp -t yazi-cwd.XXXXXX)"
yazi "$@" --cwd-file="$tmp"
cwd="$(cat -- "$tmp")"
if [[ -n "$cwd" && "$cwd" != "$PWD" ]]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
#
alias proxy-on='export http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890'
alias proxy-off='unset http_proxy https_proxy'
'';
plugins = [ plugins = [
{ {
name = "powerlevel10k"; name = "powerlevel10k";
@@ -15,25 +57,41 @@
name = "fzf-tab"; name = "fzf-tab";
src = "${pkgs.zsh-fzf-tab}/share/fzf-tab"; src = "${pkgs.zsh-fzf-tab}/share/fzf-tab";
} }
# {
# name = "powerlevel10k-config";
# src = "/home/luochen570/nixos-config/modules/home/p10k/";
# file = "p10k.zsh";
# }
]; ];
# 设置alias
shellAliases = {
# Git相关
gc1 = "git clone --recursive --depth=1";
# 目录操作 # 设置 alias - 对应 .zshrc 中的 aliases 部分
md = "mkdir -p"; shellAliases = {
# 目录导航
"..." = "../.."; "..." = "../..";
"...." = "../../.."; "...." = "../../..";
"....." = "../../../.."; "....." = "../../../..";
"......" = "../../../../.."; "......" = "../../../../..";
"1" = "cd -";
"2" = "cd -2";
"3" = "cd -3";
"4" = "cd -4";
"5" = "cd -5";
"6" = "cd -6";
"7" = "cd -7";
"8" = "cd -8";
"9" = "cd -9";
# eza/ls替代 # 快捷操作
"_" = "sudo ";
gc1 = "git clone --recursive --depth=1";
# 目录操作
md = "mkdir -p";
rd = "rmdir";
# grep
grep = "grep --color=auto";
egrep = "egrep --color=auto";
fgrep = "fgrep --color=auto";
afind = "ack -il";
globurl = "noglob urlglobber ";
# eza/ls 替代
ls = "eza --color=auto"; ls = "eza --color=auto";
l = "eza -lbah --icons=auto"; l = "eza -lbah --icons=auto";
la = "eza -labgh --icons=auto"; la = "eza -labgh --icons=auto";
@@ -42,7 +100,7 @@
lsa = "eza -lbagR --icons=auto"; lsa = "eza -lbagR --icons=auto";
lst = "eza -lTabgh --icons=auto"; lst = "eza -lTabgh --icons=auto";
# bat/cat替代 # bat/cat 替代
cat = "bat -pp"; cat = "bat -pp";
ccat = "cat"; ccat = "cat";
}; };
@@ -54,8 +112,10 @@
"z" "z"
"extract" "extract"
"git" "git"
# "fzf-tab" "command-not-found"
"colored-man-pages"
"kubectl"
]; ];
}; };
}; };
} }

View File

@@ -6,25 +6,17 @@
../../modules/drivers/nvidia.nix ../../modules/drivers/nvidia.nix
../../modules/drivers/amdgpu.nix ../../modules/drivers/amdgpu.nix
]; ];
# Bootloader. # Bootloader.
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
# Enable CUPS to print documents.
# services.printing.enable = true;
# Enable sound with pipewire. # Enable sound with pipewire.
services.pulseaudio.enable = false;
security.rtkit.enable = true; security.rtkit.enable = true;
services.pipewire = { services.pipewire = {
enable = true; enable = true;
alsa.enable = true; alsa.enable = true;
alsa.support32Bit = true; alsa.support32Bit = true;
pulse.enable = true; pulse.enable = true;
# If you want to use JACK applications, uncomment this
#jack.enable = true;
}; };
} }

View File

@@ -21,22 +21,10 @@
# 由宿主机处理 fstrim # 由宿主机处理 fstrim
services.fstrim.enable = false; services.fstrim.enable = false;
services.openssh = {
enable = true;
openFirewall = true;
settings = {
PermitRootLogin = "yes";
PasswordAuthentication = true;
};
};
security.sudo.wheelNeedsPassword = false;
services.resolved = { services.resolved = {
extraConfig = '' extraConfig = ''
Cache=true Cache=true
CacheFromLocalhost=true CacheFromLocalhost=true
''; '';
}; };
} }

View File

@@ -1,4 +1,4 @@
{ ... }: { username, inputs, ... }:
{ {
imports = [ imports = [
inputs.nixos-wsl.nixosModules.default inputs.nixos-wsl.nixosModules.default

View File

@@ -24,4 +24,7 @@
time.timeZone = lib.mkDefault "Asia/Shanghai"; time.timeZone = lib.mkDefault "Asia/Shanghai";
i18n.defaultLocale = lib.mkDefault "zh_CN.UTF-8"; i18n.defaultLocale = lib.mkDefault "zh_CN.UTF-8";
# 允许 wheel 组免密 sudo
security.sudo.wheelNeedsPassword = false;
} }

View File

@@ -4,8 +4,9 @@
curl curl
git git
htop htop
ranger
vim
wget wget
# 系统级工具(多个 host 共用)
kubectl # oh-my-zsh kubectl plugin
]; ];
} }

View File

@@ -8,7 +8,7 @@
open = true; open = true;
nvidiaSettings = true; nvidiaSettings = true;
powerManagement.enable = false; powerManagement.enable = false;
powerManagement.finegrained = false powerManagement.finegrained = false;
package = config.boot.kernelPackages.nvidiaPackages.latest; package = config.boot.kernelPackages.nvidiaPackages.latest;
}; };

View File

@@ -0,0 +1,22 @@
# 📦 modules/optional
选装模块目录——非默认启用,按需在 profile 中引用。
## 🌲 目录树
```text
📦 modules/optional
├─ 📦 virtualbox-guest.nix # VirtualBox Guest 增强(加入 wheel 组、拖拽支持)
├─ 🧠 vscode-server.nix # VS Code Server + direnv + nix-ld
└─ 📝 README.md
```
## 用法
在对应 profile 或 host 配置中添加 import
```nix
imports = [
../modules/optional/virtualbox-guest.nix
../modules/optional/vscode-server.nix
];
```

View File

@@ -1,16 +1,19 @@
# 🗄️ modules/server # 🗄️ modules/server
服务器专用模块 服务器专用核心模块(所有服务器主机默认启用)
## 🌲 目录树 ## 🌲 目录树
```text ```text
🗄️ modules/server 🗄️ modules/server
├─ 📦 default.nix # 聚合入口 ├─ 📦 default.nix # 聚合入口
├─ 📦 pkg.nix # 服务器常用软件包
├─ 🔥 firewall.nix # 防火墙默认策略
├─ 🔐 ssh.nix # OpenSSH 参数 ├─ 🔐 ssh.nix # OpenSSH 参数
├─ 🔐 lxc-ssh.nix # LXC OpenSSH 覆盖参数
├─ 🐳 docker.nix # Docker 与清理策略 ├─ 🐳 docker.nix # Docker 与清理策略
📦 virtualbox-guest.nix # VirtualBox Guest 增强配置 📝 README.md
└─ 🧠 vscode-server.nix # VS Code Server 模块
``` ```
## 可选模块
选装模块已移至 `modules/optional/`
- `virtualbox-guest.nix` — VirtualBox Guest 增强配置(用于 virtualbox profile
- `vscode-server.nix` — VS Code Server + direnv + nix-ld用于 wsl/virtualbox profile

View File

@@ -1,8 +1,6 @@
{ ... }: { ... }:
{ {
imports = [ imports = [
./pkg.nix
./firewall.nix
./docker.nix ./docker.nix
./ssh.nix ./ssh.nix
]; ];

View File

@@ -1,4 +0,0 @@
{ lib, ... }:
{
networking.firewall.enable = lib.mkDefault true;
}

View File

@@ -0,0 +1,8 @@
{
# LXC 容器需要密码登录
services.openssh.settings = {
PermitRootLogin = "prohibit-password";
PasswordAuthentication = true;
KbdInteractiveAuthentication = true;
};
}

View File

@@ -1,6 +0,0 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
];
}

View File

@@ -1,14 +1,13 @@
{ ... }: { lib, ... }:
{ {
services.openssh = { services.openssh = {
enable = true; enable = true;
openFirewall = true; openFirewall = true;
settings = { settings = {
PasswordAuthentication = false; PasswordAuthentication = lib.mkDefault false;
KbdInteractiveAuthentication = false; KbdInteractiveAuthentication = lib.mkDefault false;
PermitRootLogin = "no"; PermitRootLogin = lib.mkDefault "no";
X11Forwarding = false; X11Forwarding = lib.mkDefault false;
}; };
}; };
} }

View File

@@ -1,6 +1,7 @@
{ ... }:
{ {
imports = [ imports = [
../modules/core ../modules/core
../modules/server
../modules/server/lxc-ssh.nix
]; ];
} }

View File

@@ -4,7 +4,7 @@
../modules/core ../modules/core
../modules/desktop ../modules/desktop
../modules/server/ssh.nix ../modules/server/ssh.nix
../modules/server/virtualbox-guest.nix ../modules/optional/virtualbox-guest.nix
../modules/server/vscode-server.nix ../modules/optional/vscode-server.nix
]; ];
} }

View File

@@ -3,7 +3,7 @@
imports = [ imports = [
../modules/core ../modules/core
../modules/server/ssh.nix ../modules/server/ssh.nix
../modules/server/vscode-server.nix ../modules/optional/vscode-server.nix
]; ];
} }