| name | chezmoi-machine-config |
| description | Manage dotfiles across multiple machines: hostname/OS/distro conditionals, WSL detection, per-machine data with .chezmoidata and config [data], conditional .chezmoiignore, and per-machine file selection patterns. |
Identifying the machine
Key built-in variables for distinguishing machines:
| Variable | Distinguishes |
|---|
.chezmoi.os | Operating system ("linux", "darwin", "windows") |
.chezmoi.arch | Architecture ("amd64", "arm64") |
.chezmoi.hostname | Hostname up to the first . |
.chezmoi.fqdnHostname | Fully-qualified hostname |
.chezmoi.osRelease | /etc/os-release fields, Linux only (e.g., .chezmoi.osRelease.id) |
.chezmoi.kernel.osrelease | Kernel release string, Linux only (used for WSL detection) |
Run chezmoi data to see all values on the current machine.
Template syntax and the full variable list are in the chezmoi-templating skill.
Read OS/distro/WSL/hostname conditional patterns in references/os-patterns.md
Per-machine data
Two places to define machine-varying values:
| Source | Templated? | Use for |
|---|
[data] in the config file (generated by .chezmoi.$FORMAT.tmpl on init) | Yes | Dynamic per-machine values: email, roles, detected facts |
.chezmoidata.$FORMAT / .chezmoidata/ in the source state | No | Static data shared across all machines |
.chezmoidata files cannot be templates because they are read before the template engine starts; anything machine-dependent must go in the config file's [data] section.
Read data source patterns and merge rules in references/per-machine-data.md
Ignoring files per machine
.chezmoiignore is always interpreted as a template, so files can be ignored on machines where they do not apply.
The logic is inverted: chezmoi installs everything by default, so write "ignore unless".
{{- if ne .chezmoi.hostname "work-laptop" }}
.work
{{- end }}
Read ignore patterns and rules in references/conditional-ignore.md
Selecting different file contents per machine
| Pattern | When |
|---|
Inline {{ if eq .chezmoi.os ... }} blocks in one .tmpl | Small differences |
include separate per-machine source files from one .tmpl | Large differences, plain content |
template named fragments from .chezmoitemplates/ | Large differences, templated content |
| Shared fragment + per-OS target paths + conditional ignore | Same content, different target locations |
| Template that renders empty | Removes the target file on that machine entirely |
Read full examples in references/os-patterns.md
Related skills
- Template syntax, variables, prompt functions: chezmoi-templating skill.
- Config file options: chezmoi-configuration skill.
.chezmoidata/.chezmoiignore file mechanics: chezmoi-source-state skill.