Template Variables
chezmoi provides the following automatically-populated variables accessible in templates via the.chezmoi namespace.
System Information
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.arch | string | Architecture as returned by runtime.GOARCH | amd64, arm64, arm |
.chezmoi.os | string | Operating system as returned by runtime.GOOS | darwin, linux, windows |
.chezmoi.osRelease | object | Contents of /etc/os-release (Linux only) | See below |
.chezmoi.kernel | object | Information from /proc/sys/kernel (Linux only) | See below |
.chezmoi.windowsVersion | object | Windows version information (Windows only) | See below |
Examples
Host Information
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.hostname | string | Hostname up to the first . | workstation |
.chezmoi.fqdnHostname | string | Fully-qualified domain name hostname | workstation.example.com |
Examples
User Information
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.username | string | Username of the user running chezmoi | john |
.chezmoi.uid | string | User ID | 1000 |
.chezmoi.gid | string | Primary group ID | 1000 |
.chezmoi.group | string | Group name of the user | users |
Examples
Directory Paths
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.homeDir | string | Home directory | /home/john |
.chezmoi.sourceDir | string | Source directory | /home/john/.local/share/chezmoi |
.chezmoi.destDir | string | Destination directory | /home/john |
.chezmoi.cacheDir | string | Cache directory | /home/john/.cache/chezmoi |
.chezmoi.workingTree | string | Git working tree | /home/john/.local/share/chezmoi |
Examples
Template File Information
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.sourceFile | string | Path of template relative to source directory | dot_bashrc.tmpl |
.chezmoi.targetFile | string | Absolute path of the target file | /home/john/.bashrc |
Examples
chezmoi Information
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.executable | string | Path to chezmoi executable | /usr/local/bin/chezmoi |
.chezmoi.args | []string | Arguments passed to chezmoi | ["chezmoi", "apply"] |
.chezmoi.version.version | string | chezmoi version | 2.40.0 |
.chezmoi.version.commit | string | Git commit of build | abc123... |
.chezmoi.version.date | string | Build timestamp | 2024-01-15T10:30:00Z |
.chezmoi.version.builtBy | string | Builder name | goreleaser |
Examples
Configuration
| Variable | Type | Description |
|---|---|---|
.chezmoi.config | object | Configuration file contents |
.chezmoi.configFile | string | Path to configuration file |
Examples
Path Separators
| Variable | Type | Description | Example |
|---|---|---|---|
.chezmoi.pathSeparator | string | OS path separator | / (Unix), \ (Windows) |
.chezmoi.pathListSeparator | string | OS path list separator | : (Unix), ; (Windows) |
Examples
OS-Specific Variables
.chezmoi.osRelease (Linux)
Contains information from /etc/os-release:
Example
.chezmoi.kernel (Linux)
Contains information from /proc/sys/kernel:
.chezmoi.windowsVersion (Windows)
Contains Windows version information from the registry:
| Key | Type | Description |
|---|---|---|
currentBuild | string | Build number |
currentMajorVersionNumber | integer | Major version |
currentMinorVersionNumber | integer | Minor version |
currentVersion | string | Version string |
displayVersion | string | Display version |
editionID | string | Edition (e.g., “Professional”) |
productName | string | Product name |
Example
Custom Data Variables
Additional variables can be defined in the config file’sdata section or in .chezmoidata.$FORMAT files:
~/.config/chezmoi/chezmoi.toml
~/.local/share/chezmoi/.chezmoidata.yaml
Testing Variables
To see all available template data:Practical Examples
Multi-OS Configuration
dot_bashrc.tmpl
Machine-Specific Configuration
dot_gitconfig.tmpl
Distribution-Specific Configuration
run_once_install-packages.sh.tmpl
Related Pages
- Template Overview - Template system overview
- Template Functions - Available functions
- Configuration File - Configuration options
chezmoi data- View template data