Today, as alluded in the Organizing my ~/.zshrc file post, I got to revive my chezmoi usage. This was mostly because I finally set up my Arch Linux box with an NVIDIA RTX 3080 GPU that I could ssh into from my Mac, and I wanted to sync my dotfiles between the two machines.

I figured I would learn more about chezmoi while I was at it, so that I could actually, responsibly use it manage my dotfiles.

So first, some concepts in chezmoi, explained in a way that I understand:

  • The destination (directory) is the root folder that all the chezmoi’s paths are relative to. Mine (and presumably the default) is the home directory. This doesn’t mean chezmoi will manage everything in the home folder. You tell what chezmoi manages using the chezmoi add command.
  • The source (directory) is where the tracked/managed dotfiles live. Mine (and default) is ~/.local/share/chezmoi. You can get here by running chezmoi cd. Here are some things I have:
 dot_config     󰡯 dot_ideavimrc   󰂺 README.md
󰡯 dot_condarc    󱁻 dot_tmux.conf   
󰡯 dot_gitconfig   dot_zshrc.tmpl
  • Everything in the chezmoi cd directory is the source state. According to the concepts page , these include templates (like the dot_zshrc.tmpl), regular files (like dot_ideavimrc) and directories (like dot_config).
  • The target is a file, directory, or symlink in the destination directory, which I believe you can see via chezmoi managed.

The Three States

The target has three versions or states.

What it isHow to see
Source Statedot_zshrc.tmplcat "$(chezmoi source-path ~/.zshrc)"
Target StateThe template rendered for this machinechezmoi cat ~/.zshrc
Destination StateActual file on disk right nowcat ~/.zshrc

So the source AND machine data (MacOS or Arch Linux) determine the target, and chezmoi apply creates the actual destination file, if I’m understanding correctly.

The chezmoi diff ~/.zshrc would show me the difference between Target and Destination (right now it is empty because everything is synced). I believe the “correct” way to edit dotfiles that are managed by chezmoi is by chezmoi edit FILE, and then chezmoi apply would apply that to destination file.

If I do accidentally edit like nvim ~/.zshrc, then I should see the difference via chezmoi status or chezmoi diff. Apparently to “check this into” chezmoi, I should use chezmoi re-add FILE (for plain files) or chezmoi merge ~/.zshrc for templates. In the Arch Linux box, I can use chezmoi update to get the latest configs.

Overall, chezmoi has very much a git-like feeling for me, and if that is indication of anything, using it more would help me actually understand better. Will come back with more TIL if I have any better insights on chezmoi. :)