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).
File roles:
| File / convention | Role |
|---|---|
| profile directory | decides machine scope; not an inline {{ if }} inside a partial |
brews/_assemble.brewfile | index of category banners and includeTemplate calls |
home/readonly_dot_Brewfile.tmpl | renders the 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:
Step Detail Create partial reuse the NN-<category>ordinal+slug of the matchingshared/siblingWire assembler add {{ includeTemplate "brews/<profile>/NN-<category>.brewfile" . }}tobrews/_assemble.brewfileWork profile place work entries 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 --no-upgrade, 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