Chezmoi is a command-line utility designed to help you manage all of your config files from machine to machine or in my case, I am using it as a way to store my config files for a backup.
I wanted to have a way to back up all of my .config files now that I have been spending a good amount of time customizing my Omarchy desktop and CachyOS laptop. I spent a good amount of time with my laptop reading through the config for Hyprland, Noctalia, Neovim, Fish, and Alacritty. I took a deep dive into each of the documentations and looked for ways to customize them to my liking. I was thinking since DHH made Omarchy to be his operating system, I wanted to see how much efficiency I could gain and also add a little bit of my own style.
I used OpenAI Codex to style the couple of changes that I made to Omarchy except for binding the extra buttons on my Logitech MX Master mouse. I had to do that on my own since I needed to figure out what the computer was seeing using wev.
For my CachyOS laptop though, I made all of the configuration changes by hand. There was a couple of times that I used the web version of Claude to help me with Fish syntax, but I wanted to be the one to change my .config files because I didn't want to end up with more code or files than I actually needed. I am confident that Codex or Claude could have got me where I was going but they would have taken a couple of detours along the way and left some artifacts from them.
This is all to say that afterwards I wanted to sync my config to a Git repository. One of the first options I saw when I googled .config files and git was Chezmoi. I had never heard of it before, but I had all of the features that I was looking for and more. It's ability to encrypt files with age meant that I could feel comfortable syncing my ssh keys and config as well.
The setup that I settled on was adding my SSH keys, SSH config file, and my age private key encrypted to the Chezmoi repository. I used a long passphrase for my age private key. I then created a script that asks for the passphrase when i connect a fresh install of Chezmoi to it and decrypts everything onto my computer. I even added a couple of scripts that install packages from Pacman and AUR once when a computer is first being setup.
With this setup, I could wipe my laptop today, and I could very easily get back to a working setup. The only requirement is an SSH key with Chezmoi repository access or to use HTTPS the first time I access it.
Chezmoi also works on Windows, though the only thing I have been using Windows for is to play video games. I might look into setting it up and seeing if I can auto install programs on Windows as well.
The Chezmoi documentation can be found here and their GitHub repository can be found here.
Walkthrough
If anyone wants to tryout my Linux setup, I have detailed the steps below.
Install Chezmoi and Age(for encryption).
sudo pacman -S chezmoi age
Create Git Repository for Chezmoi config. (Forgejo Web UI)
Initialize Chezmoi and Create Age Encryption Key.
chezmoi init
chezmoi cd
chezmoi age-keygen | chezmoi age encrypt --passphrase --output key.txt.age
Enter a passphrase for the private key.
Create Chezmoi Ignore File.
printf '%s\n' \
'key.txt.age' \
'.ssh/known_hosts' \
'.ssh/known_hosts.old' \
>> .chezmoiignore
Create Scripts to run with Chezmoi.
This one asks for the passphrase and then syncs the private key.
run_onchange_before_decrypt-private-key.sh.tmpl
#!/bin/sh
set -eu
KEY="${HOME}/.config/chezmoi/key.txt"
if [ ! -f "${KEY}" ]; then
mkdir -p "${HOME}/.config/chezmoi"
chezmoi age decrypt \
--output "${KEY}" \
--passphrase \
"{{ .chezmoi.sourceDir }}/key.txt.age"
chmod 600 "${KEY}"
fi
Create Scripts to add packages to new computer.
run_once_before_10-install-packages.sh.tmpl
#!/bin/bash
set -e
SOURCE="{{ .chezmoi.sourceDir }}"
if [[ -f "$SOURCE/packages-pacman.txt" ]]; then
sudo pacman -S --needed --noconfirm \
$(grep -vE '^\s*(#|$)' "$SOURCE/packages-pacman.txt")
fi
if command -v paru >/dev/null 2>&1 && [[ -f "$SOURCE/packages-aur.txt" ]]; then
paru -S --needed --noconfirm \
$(grep -vE '^\s*(#|$)' "$SOURCE/packages-aur.txt")
fi
Create Package Manifest Files
printf '%s\n' \
chromium \
ttf-jetbrains-mono-nerd \
tailscale \
fzf \
zoxide \
eza \
fd \
bat \
tmux \
openai-codex \
obsidian \
dua-cli \
yay \
nautilus \
neovim \
git \
ripgrep \
lazygit \
> packages-pacman.txt
printf '%s\n' \
facelock-bin \
> packages-aur.txt
Retrieve Age Public Key and Create Chezmoi Config File.
chezmoi age decrypt --passphrase ./key.txt.age
Copy the Public Key right now so that you can put it in the Chezmoi config file. This .tmpl file will be used to create the chezmoi config file on machines.
Create ~/.config/chezmoi/chezmoi.toml.tmpl
encryption = "age"
[age]
identity = "~/.config/chezmoi/key.txt"
recipient = "age1ks93xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
chezmoi init --apply
Add files to Chezmoi. I would not add the entire .config directory because there are a lot of programs that use it for temporary storage as well.
chezmoi add -r ~/.config/{hypr,noctalia,alacritty,fish,nvim}
chezmoi add --encrypt -r ~/.ssh
Push first commit to repository.
git config --global user.name "$UserName"
git config --global user.email "$EmailAddress"
chezmoi cd;
git add .
git commit -m "First Commit"
git branch -M main
git remote add origin $RepositoryURL
git push -u origin main
exit
Apply Chezmoi Configuration
chezmoi apply -v
To push changes to Chezmoi Repository
chezmoi push
Add new files
chezmoi add $filePath
Apply local changes made to files.
chezmoi re-add
chezmoi push
After Initial Setup
After the initial setup, when you want to clone you repo to another machine, you only need to install chezmoi and age. Then run these commands.
chezmoi init --apply $repository