a4c7f288494aeb580568c7499737f7f0f774a84d
Nix Config
nix-darwin + NixOS-WSL + Home Manager + Flakes 声明式管理三台设备的系统配置。
设备
| 设备 | 平台 | Flake 目标 | 主机名 |
|---|---|---|---|
| Mac Mini | aarch64-darwin | mac-mini |
awesome-mac-mini |
| MacBook Air | aarch64-darwin | macbook-air |
awesome-macbook-air |
| Windows PC (WSL) | x86_64-linux | wsl |
awesome-wsl |
快速开始
macOS
- 安装 Lix:
curl -sSf -L https://install.lix.systems/lix | sh -s -- install
- 安装 Homebrew(nix-darwin 不会自动安装):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 克隆仓库并首次构建:
git clone <repo-url> ~/nix-config
cd ~/nix-config
sudo nix run nix-darwin -- switch --flake .#macbook-air
之后日常重建:just rebuild macbook-air
WSL
- 启用 WSL 并更新内核:
wsl --install --no-distribution
wsl --update
- 安装 NixOS-WSL:
wsl --import NixOS C:\wsl\nixos nixos-wsl.tar.gz
wsl -d NixOS
- 首次构建:
nix shell nixpkgs#git
git clone <repo-url> ~/nix-config
cd ~/nix-config
sudo nixos-rebuild switch --flake .#wsl
之后日常重建:just rebuild wsl
仓库结构
flake.nix # 入口
hosts/ # 主机特定配置
modules/
├── darwin/ # macOS 模块
├── nixos/ # NixOS 模块
└── shared/ # 共享模块
home/ # Home Manager 配置
├── dev/ # 开发工具
└── shell/ # Shell 配置
lib/default.nix # 构建辅助函数
overlays/ + pkgs/ # 自定义包
配置层级:hosts/* → modules/* → home/*
日常使用
just rebuild <host> # 重建系统
just update # 更新所有 flake 输入
just up <input> # 更新单个输入
just check # 检查配置
just clean # 清理旧 generation
just rollback # 回滚(仅 NixOS)
just history # 查看 profile 历史
just show # 显示 flake 输出
Shell
Fish + Starship + Atuin + Zoxide + FZF + Direnv,Catppuccin Mocha 主题。
常用自定义:
- fish abbreviation →
home/shell/fish.nix - 添加包 →
home/default.nix或home/dev/languages.nix - Homebrew cask →
modules/darwin/default.nix
Environment
1Password CLI op inject 获取环境变量,本地缓存后离线可用。
模板文件 ~/.config/op-env/env.tpl 由 home/shell/fish.nix 生成,仅包含 op:// 引用,可安全提交。
Shell 启动时只读取本地缓存(~/.cache/op-env/env.fish),不联网。首次使用或密钥变更后需手动刷新:
op-env-refresh # 从 1Password 获取并缓存(需联网)
op-env-clear # 清除本地缓存
认证需要在 ~/.config/fish/local.fish(gitignored)中设置:
set -gx OP_SERVICE_ACCOUNT_TOKEN "your-service-account-token"
未设置 token 时 op-env-refresh 会提示错误,不影响已有缓存的正常使用。
Description
Languages
Nix
90.6%
Just
9.4%