catalog/repos/ahmedelgabri--dotfiles.md

127 lines
4.4 KiB
Markdown
Raw Permalink Normal View History

2026-04-07 11:44:56 +08:00
# Nix驱动的dotfiles配置
`dotfiles` `nix` `macOS` `NixOS` `开发环境`
# ~ 🍭 ~
[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org)
用于在任意 Unix 机器Darwin/Linux上搭建开发环境。该配置官方支持 macOS 与 NixOS由 [nix][nix] 统一管理。
![screenshot](./screenshot.png)
> _字体为 [Pragmata Pro](https://fsd.it/shop/fonts/pragmatapro/),主题是基于 [vim-colors-plain](https://github.com/andreypopp/vim-colors-plain) 的[个人定制版本](./config/nvim/colors/plain.lua),终端为 [Ghostty][Ghostty]_
## 包含哪些内容?
以下是主要配置项:
- [nix][nix]管理大多数依赖的安装macOS 上的 GUI 应用仍通过 [`nix-darwin`](https://github.com/LnL7/nix-darwin/blob/5c3146b75d5d478f0693d0ea6c83f1da8382ff56/modules/homebrew.nix) 中的 homebrew 模块,借助 [Homebrew cask](https://github.com/caskroom/homebrew-cask) 安装
- [aerc][aerc]:邮件阅读客户端
- [tmux][tmux] 2.3 或更高版本
- [Neovim][neovim]
- [Zsh][zsh]
- [Git][git]
- [Ghostty][Ghostty]:终端模拟器
- [hammerspoon][hammerspoon]macOS 自动化工具,用于窗口管理等
## 官方支持的操作系统
- ARM macOS Sequoia
- [实验性] NixOS已在 22.11 上测试)
## 安装步骤
1. 安装 `nix`
> [!NOTE]
>
> 请务必查阅 [`quirks`](https://github.com/NixOS/nix-installer/blob/main/docs/quirks.md) 部分的说明
```bash
curl --proto '=https' --tlsv1.2 -sSfL https://artifacts.nixos.org/nix-installer | sh -s -- install
```
2. 进行配置
> [!NOTE]
>
> flake 属性通常为主机名,若未传入则默认使用 `$(hostname -s)`
在线方式:
```bash
nix --experimental-features 'nix-command flakes' run "github:ahmedelgabri/dotfiles" -- <flake 属性>
```
首次运行时,引导程序会使用启动时内置的 flake 源,随后将仓库克隆到 `~/.dotfiles` 以供后续重建使用。
### Homebrew
我主要仍用 Homebrew 安装 GUI 应用,因为 Nix 和/或 Home-manager 对 GUI 应用的支持在符号链接到 `Applications/` 文件夹时存在问题。Homebrew 完全由 `nix` 管理,通过 [`nix-homebrew`](https://github.com/zhaofengli/nix-homebrew) 进行安装和运行。
### 注意事项
- zsh将以下内容添加到 `${XDG_DATA_HOME}/$(hostname)/zshrc`
```zsh
export HOMEBREW_GITHUB_API_TOKEN =
export GITHUB_TOKEN =
```
- Git将 GPG 密钥信息添加到 `${XDG_DATA_HOME}/$(hostname)/gitconfig`
```
[user]
signingkey =
```
别忘了将公钥上传到 [GitHub](https://github.com/blog/2144-gpg-signature-verification)
> 注意GitHub 显示提交为"已验证"需要三处邮箱一致提交邮箱、GitHub 邮箱以及公钥关联邮箱。
关于如何创建 GPG 密钥并为提交签名,请参阅[此文档](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work)。
#### 邮件
邮件通过 [isync][isync] 在远程服务器与本机之间同步,使用 [aerc][aerc] 阅读,搜索索引由 [notmuch][notmuch] 构建。
链接 dotfiles 后,还需完成以下几项配置。
##### 认证
每个账户需分别对 IMAP 服务器和 SMTP 服务器进行认证,密码需存储在 [Pass][Pass] 中。
对于 Fastmail 或启用了双因素认证的 Gmail 账户,请使用应用专用密码。
密码存储中需包含以下条目:
- `service/email/source`_仅 Fastmail 使用_用于访问邮件的 JMAP 密码)
- `service/email/outgoing`_仅 Fastmail 使用_用于发送邮件的 JMAP 密码)
- `service/email/contacts`_仅 Fastmail 使用_用于访问联系人的 JMAP 密码)
- `service/email/password`:应用专用密码,用于 `mbsync` 本地邮件同步及 `msmtp` 发送邮件
## 定期同步
收件箱消息在 `mbsync`(即 isync 的可执行文件名)运行时从远程服务器拉取。
macOS 上使用 [`launchd`][launchd]NixOS 上使用 `systemd`。详见 [`mail.nix`](nix/parts/modules/shared/mail.nix)。
### 作者
[Ahmed El Gabri](https://twitter.com/AhmedElGabri)
[isync]: http://isync.sourceforge.net
[notmuch]: https://notmuchmail.org
[keychain]: https://en.wikipedia.org/wiki/Keychain_(software)
[launchd]: http://launchd.info
[aerc]: https://aerc-mail.org/
[nix]: https://nixos.org/
[tmux]: http://tmux.sourceforge.net/
[neovim]: https://neovim.io
[zsh]: http://www.zsh.org/
[git]: http://git-scm.com/
[kitty]: https://github.com/kovidgoyal/kitty
[hammerspoon]: http://www.hammerspoon.org/
[Ghostty]: https://ghostty.org/
[Pass]: https://www.passwordstore.org/