nix-config

odysseus0 的头像作者 odysseus0

通过 Nix 的声明式 macOS 环境。管理 CLI 包、GUI 应用程序 (Homebrew/MAS)、系统设置、程序配置、点文件和服务。在以下情况下使用:(1) 添加软件包、工具或应用程序,(2) 配置程序(Git、SSH、shell 等),(3) 修改点文件或系统设置,(4) 配置文件权限被拒绝(表示 Nix 管理),(5) 重建系统。

📖 中文导读:通过 Nix 的声明式 macOS 环境。管理 CLI 包、GUI 应用程序 (Homebrew/MAS)、系统设置、程序配置、点文件和服务。在以下情况下使用:(1) 添加软件包、工具或应用程序,(2) 配置程序(Git、SSH、shell 等),(3) 修改点文件或系统设置,(4) 配置文件权限被拒绝(表示 Nix 管理),(5) 重建系统。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: nix-config description: "Declarative macOS config via Nix (packages, apps, dotfiles, system settings). Use when: (1) Permission denied or root-owned on config/dotfiles (indicates Nix-managed), (2) Adding packages or apps, (3) Configuring programs, (4) Rebuilding system (make switch)."

Nix Config

Declarative macOS environment at ~/nix-config. See the repo's CLAUDE.md for full architecture.

Adding Packages

CLI tools → users/tengjizhang/home/packages.nix

home.packages = with pkgs; [
  ripgrep
  jq
  # ...
];

GUI apps → users/tengjizhang/darwin.nix

homebrew.casks = [ "raycast" "obsidian" ];

Third-party taps → Use full tap/cask path:

homebrew.casks = [ "steipete/tap/codexbar" ];

Mac App Store → users/tengjizhang/darwin.nix

homebrew.masApps = { "Things" = 904280696; };

npm Package Pattern

For latest npm packages, use pnpm dlx wrapper:

(writeShellScriptBin "toolname" ''
  exec ${pnpm}/bin/pnpm dlx @scope/package@latest "$@"
'')

Examples in packages.nix: claude, codex, gemini, gccli

Rebuild

cd ~/nix-config && make switch > /tmp/nix-switch.log 2>&1 && echo "✓ Switch succeeded" || echo "✗ Switch failed (see /tmp/nix-switch.log)"

Workflow

  1. Edit the appropriate .nix file
  2. Commit changes (keeps git clean before rebuild)
  3. make switch to rebuild and activate
  4. Push changes

Key Files

  • flake.nix - Inputs/outputs, system definition
  • users/tengjizhang/home/packages.nix - CLI packages
  • users/tengjizhang/home/programs.nix - Program configs (git, neovim, etc.)
  • users/tengjizhang/darwin.nix - Homebrew, macOS settings