Customize Source Directory Structure
Use a Subdirectory as Source Root
By default, chezmoi uses the root of your dotfiles repository as the source state root. If your repository root contains many files (like README, LICENSE, scripts, etc.), you can keep your home directory cleaner by using a subdirectory. Create a.chezmoiroot file in your source directory:
~/.local/share/chezmoi/.chezmoiroot
home/ subdirectory. Your directory structure becomes:
~/.gitconfigis sourced fromhome/dot_gitconfig(notdot_gitconfig)- Files in the repository root (like README.md) don’t clutter your home directory
- You don’t need to maintain
.chezmoiignorefor repository metadata files
Migration Steps
When migrating an existing chezmoi setup to use.chezmoiroot:
-
Create the subdirectory:
-
Create
.chezmoiroot: -
Move managed files:
-
Update
.chezmoiignore(if you have one): -
Test the changes:
-
Commit:
Use Alternative Version Control Systems
While chezmoi is designed to work with git, you can use other version control systems like Fossil, Pijul, or Mercurial.Where chezmoi Uses Git
chezmoi uses git in only three places:chezmoi init- Usesgit cloneto clone your dotfiles repochezmoi update- Usesgit pullto fetch changes- Auto-commit/push - Uses
git status,git add,git commit, andgit push
Git-Compatible VCS
If your VCS is git-compatible (same CLI), configure it:~/.config/chezmoi/chezmoi.toml
Non-Git VCS Setup
For VCS systems that aren’t git-compatible:1. Manual Clone
Create the source directory manually:.git directory is required for chezmoi to identify the working tree.
2. Configure Updates
Tell chezmoi how to update:~/.config/chezmoi/chezmoi.toml
chezmoi update will use fossil update instead of git pull.
3. Manual Commits
Auto-commit/push features won’t work with non-git VCS. Commit manually:Example: Using Fossil
Complete setup for Fossil:~/.config/chezmoi/chezmoi.toml
Example: Using Pijul
~/.config/chezmoi/chezmoi.toml
Customize Git Behavior
Auto-Commit and Auto-Push
Automatically commit and push changes:~/.config/chezmoi/chezmoi.toml
chezmoi add, chezmoi edit, etc., changes are automatically committed and pushed.
Custom Commit Messages
Template your commit messages:~/.config/chezmoi/chezmoi.toml
Use External Git
Force chezmoi to use external git (not built-in):~/.config/chezmoi/chezmoi.toml
Directory and File Locations
Custom Source Directory
Change where chezmoi stores the source state:~/.config/chezmoi/chezmoi.toml
Custom Destination Directory
Manage files outside your home directory (discouraged for dotfiles):~/.config/chezmoi/chezmoi.toml
Custom Config File Location
Custom Cache Directory
~/.config/chezmoi/chezmoi.toml
Script Behavior
Script Environment Variables
Inject data into scripts via environment variables:~/.config/chezmoi/chezmoi.toml
run_onchange_setup.sh
Custom Script Interpreter
Override interpreters for script extensions:~/.config/chezmoi/chezmoi.toml
Script Temporary Directory
Change where chezmoi writes temporary script files:~/.config/chezmoi/chezmoi.toml
/tmp is mounted with noexec.
Template Customization
Custom Template Delimiters
Avoid conflicts with other templating systems:~/.config/chezmoi/chezmoi.toml
[[ .chezmoi.os ]] instead of {{ .chezmoi.os }}.
Template Functions
Define custom template functions:~/.config/chezmoi/chezmoi.toml
missingkey=error- Error on undefined variables (default: zero value)missingkey=zero- Use zero value for undefined variablesmissingkey=invalid- Template execution stops immediately
File Permissions
Custom Umask
Set a global umask for all managed files:~/.config/chezmoi/chezmoi.toml
Per-File Permissions
Use filename attributes:Encryption
Configure Age Encryption
~/.config/chezmoi/chezmoi.toml
Configure GPG Encryption
~/.config/chezmoi/chezmoi.toml
Transparent Encryption
Keep encrypted files in the source but edit them transparently:Hooks
Run commands before or after chezmoi operations:~/.config/chezmoi/chezmoi.toml
read-source-state.pre/read-source-state.post
Warnings
Disable specific warnings:~/.config/chezmoi/chezmoi.toml
Working with Multiple Machines
Machine-Specific Source Directories
You can use different source directories on different machines by passing--source or --config:
Nested chezmoi
Run a second instance of chezmoi from within a script:run_after_rootmoi.sh
Symlink Mode
Make chezmoi use symlinks where possible:~/.config/chezmoi/chezmoi.toml
- Symlinks cannot be used for encrypted files
- Symlinks cannot be used for executable files
- Symlinks cannot be used for private files
- Symlinks cannot be used for templates
- Symlinks cannot be used for entire directories
Advanced Configuration Examples
Minimal Container Configuration
~/.config/chezmoi/chezmoi.toml.tmpl
Multi-Environment Setup
~/.config/chezmoi/chezmoi.toml.tmpl
Debug Mode Configuration
~/.config/chezmoi/chezmoi.toml
Best Practices
- Use
.chezmoirootfor cleaner repositories - Commit your config file template (
.chezmoi.toml.tmpl) not the generated config - Document your customizations with comments in your config
- Test on all machines before committing major changes
- Use templates for machine-specific paths instead of hardcoding
- Keep auto-commit off until you’re confident in your setup
Troubleshooting
Config File Not Found
Check the config search path:Source Directory Issues
Verify your source directory:Git Integration Problems
Test git commands:VCS Integration
For non-git VCS, ensure:- Empty
.gitdirectory exists in source directory update.commandis configured correctly- You commit changes manually