Add A Homebrew Package
Homebrew packages are managed declaratively. The deployed ~/.Brewfile is a single file, but in the chezmoi source it is split into per-category, per-profile partials under home/.chezmoitemplates/brews/ so it stays explorable:
brews/shared/NN-<category>.brewfile— installed on every machine.brews/personal/NN-<category>.brewfile— installed when.isWorkisfalse.brews/work/NN-<category>.brewfile— installed when.isWorkistrue(none exist yet; create as needed).
Profile membership is the directory the file lives in, not an inline {{ if }} branch. brews/_assemble.brewfile is the index: it lists the category banners in order and includeTemplates each partial. home/readonly_dot_Brewfile.tmpl just renders that assembler into ~/.Brewfile.
Preconditions
- You know whether the package is a formula or cask.
- You verified the package name with:
brew info <formula-or-cask>
Steps
-
Pick the category and profile, then edit the matching partial under
home/.chezmoitemplates/brews/:- Every machine:
brews/shared/NN-<category>.brewfile. - Personal-only:
brews/personal/NN-<category>.brewfile. - Work-only:
brews/work/NN-<category>.brewfile.
- Every machine:
-
Add the entry (
brew "<formula>"orcask "<cask>", with its comment/URL) to that file.If the category file does not exist yet for the chosen profile, create it (reuse the
NN-<category>ordinal+slug of itsshared/sibling) and add a matching{{ includeTemplate "brews/<profile>/NN-<category>.brewfile" . }}line inbrews/_assemble.brewfile(work entries go inside a{{ if eq .isWork true }}block). -
Apply:
chezmoi apply
The brew hook is:
It runs brew bundle cleanup --global --force and brew bundle --global, so the assembled Brewfile is the source-of-truth (anything not listed is uninstalled). Its run_onchange hash is computed from the rendered assembler, so editing any partial re-triggers the hook.
Verification
brew bundle check --global
brew list | rg '<formula-or-cask>'
If something unexpected changed:
chezmoi diff
Rollback / Undo
- Remove the package entry from its
home/.chezmoitemplates/brews/<profile>/NN-<category>.brewfilepartial. - Re-apply:
chezmoi apply