用 Chezmoi 终结多设备 dotfiles 噩梦
推荐指数 44.0 NO. 016 · 2026.06.19
发布2026/06/18Score52Comments56
为什么值得看
作者从 GNU Stow 迁移到 Chezmoi 管理跨 3 台 Mac 的 dotfiles,解决了符号链接在多设备同步中的维护痛点。对需要统一管理开发环境配置的工程师有直接参考价值,Chezmoi 的模板和加密功能比 Stow 更适合复杂场景。
编辑判断
Stow 的核心问题是它只做符号链接映射,没有设备差异化配置能力,工程师们过去要么维护多个分支,要么写一堆 if 语句绕过去。Chezmoi 的杀手功能是内置模板引擎(基于 text/template),同一配置文件可以根据 hostname、OS 等变量渲染不同内容,一台笔记本上的 .zshrc 和服务器上的可以共用同一个源文件。
另一个被低估的功能是内置的 age 加密,可以直接在仓库里存 API key、SSH 私钥等敏感配置而不怕泄露。如果你现在还在用 Git 子模块或者手撸 shell 脚本来处理多设备 dotfiles,迁移成本大约 2 小时,但后续省下的调试 symlink 断裂的时间远超这个投入。YADM 和 Bare repo 也是常见替代方案,但 Chezmoi 的声明式管理和首次安装体验明显更 polished。
社区反馈
意见分歧 54 条评论
核心争论:Chezmoi 易用性 vs Nix 可复现性,后者更强大但学习曲线陡峭
I must've tried to set up stow five or six times over the years, in between various hand rolled custom setups. I can't put my finger on why but I set up chez moi & it's been my setup since, much longer than any previous solution. Chez moi is definitely not without its rough edges but it seems to hav
I used stow for a long time, then tried Ansible, but eventually settled into good old Make. `make dotfiles` just creates a bunch of symlinks, takes 5 minutes, all good and happy. Everything is modular, declarative, simple. Never looked back.
Same here. I would say chezmoi has almost a bit too many features. If one is into yak shaving there is a lot to explore. It's only a negative for me because I forget half of them everytime I read the docs. But I can hardly blame it for that, it's great!