-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add entry on declarative package installation
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
assets/chezmoi.io/docs/user-guide/advanced/install-packages-declaratively.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Install packages declaratively | ||
|
||
chezmoi uses a declarative approach for the contents of dotfiles, but package | ||
installation requires running imperative commands. However, you can simulate | ||
declarative package installation with a combination of a `.chezmoidata` file and | ||
a `run_onchange_` script. | ||
|
||
The following example uses [homebrew](https://brew.sh) on macOS, but should be | ||
adaptable to other operating systems and package managers. | ||
|
||
First, create `.chezmoidata/packages.yaml` declaring the packages that you want | ||
installed, for example: | ||
|
||
```yaml title="~/.local/share/chezmoi/.chezmoidata/packages.yaml" | ||
packages: | ||
darwin: | ||
brews: | ||
- 'git' | ||
casks: | ||
- 'google-chrome' | ||
``` | ||
|
||
Second, create a `run_onchange_darwin-install-packages.sh.tmpl` script that uses | ||
the package manager to install those packages, for example: | ||
|
||
``` title="~/.local/share/chezmoi/run_onchange_darwin-install-packages.sh.tmpl" | ||
{{ if eq .chezmoi.os "darwin" -}} | ||
#!/bin/bash | ||
brew bundle --no-lock --file=/dev/stdin <<EOF | ||
{{ range .packages.darwin.brews -}} | ||
brew {{ . | quote }} | ||
{{ end -}} | ||
{{ range .packages.darwin.casks -}} | ||
cask {{ . | quote }} | ||
{{ end -}} | ||
EOF | ||
{{ end -}} | ||
``` | ||
|
||
Now, when you run `chezmoi apply`, chezmoi will execute the | ||
`install-packages.sh` script with when the list of packages defined in | ||
`.chezmoidata/packages.yaml` changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters