One dotfiles repo for macOS and a Linux VPS
Everything I work in is configured from one Git repository. It has been going since October 2024, and it now manages 686 files across a Mac and my Linux machines. This post is a tour of how it is put together and the rules that keep it from falling apart.
Why one repo
I work on a MacBook, and I run long jobs on a headless Linux box. For a while those were two setups that slowly drifted apart. A keybinding would exist on one and not the other, and I would only find out mid-task.
One repo fixes that by making drift visible. If the two machines differ, it is because a file says so, not because I forgot.
What is in it
The repo covers the whole working environment, not only shell config.
| Area | Shared | macOS only | Linux only |
|---|---|---|---|
| Shell | zsh, Starship, Atuin | ||
| Editor | Neovim | ||
| Terminal | Rex | Ghostty, Kitty | |
| Files and Git | Yazi, Lazygit, Delta | ||
| Tool versions | mise | nix-darwin, Homebrew | Omarchy on Arch |
| Windows | Rift, JankyBorders, Sketchybar | Hyprland | |
| Keys | skhd, Kanata | ||
| Networking | Tailscale | ||
| Secrets | Bitwarden through rbw |
There are 54 folders under ~/.config alone, and the Neovim config is 58 plugin files.
How chezmoi fits
chezmoi keeps a source directory, and applies it to your home directory.
The source is the repo.
The targets are the real files, such as ~/.config/nvim.
The file names in the source carry instructions:
dot_zshenvbecomes~/.zshenv.executable_marks a script as runnable.private_restricts permissions, which is what the SSH folder uses..tmplmeans the file is a template, rendered per machine.
The one rule that matters: edit the source, never the target.
A change made directly in ~/.config is overwritten by the next chezmoi apply.
Two operating systems, one set of files
Most files are identical on both systems. Where they differ, there are two tools, and I reach for them in this order.
Ignore the file.
A config that only makes sense on one system is listed in .chezmoiignore for the other.
Sketchybar never lands on Linux, and Hyprland never lands on the Mac.
That file is 223 lines long.
Template the difference. A file that is mostly shared stays one file, with a check around the lines that differ. Only 12 files in the whole repo need this.
~/Developer/gnohj-monorepo
{{- if eq .chezmoi.os "darwin" }}
~/Obsidian/second-brain
{{- end }}
~/Developer/agents
That is the list of repos my sync job pushes. The notes vault only exists on the Mac, so it is wrapped in a check, and the rest is shared.
I template the difference and not the file. Two near-identical copies of a config are the drift I was trying to get rid of.
Scripts that run on apply
Some setup is not a file. A background service has to be enabled, a helper has to be compiled, a package list has to be installed.
chezmoi runs scripts during apply, and the name says when:
run_once_runs a single time per machine.run_onchange_runs again whenever its contents change.run_after_runs after the files are in place.
Most of mine are run_onchange_ scripts that enable a service.
Because the script re-runs only when it changes, editing a service definition is enough to reload it, and an ordinary apply does nothing.
Packages and tool versions
Packages are the part that differs most between systems, so each system uses what suits it.
- macOS: nix-darwin manages system settings, and Homebrew installs apps.
- Linux: Omarchy on Arch brings its own base.
- Both: mise pins language and CLI versions, so
nodeandpythonmatch everywhere.
Global tools installed through Bun and Cargo are plain text lists in the repo. A script installs whatever is on the list, so adding a tool is one line.
Secrets
No secret is committed. The repo is public, so this is not optional.
Credentials live in Bitwarden, and rbw reads them at the moment a command needs one.
Anything machine-specific that should not be public, such as a server address, comes from a local file that the repo ignores.
One colorscheme for everything
A scheme is a small file of named colours, and a symlink marks the active one. One command switches it, and regenerates the config for every tool that has colours.
That is 20 outputs today, including the terminals, Neovim, the prompt, Lazygit, Yazi, bat, Delta, btop, window borders and the status bar. The wallpaper changes with it.
Numbered colour slots turned out to be a trap, because one slot ended up serving as both blue and body text. So there are named roles on top: text, muted text, selection and accent. A tool asks for the role it needs.
This site is one of the readers. I wrote about that in This site wears my desktop theme.
Keeping machines in sync
A timer commits and pushes a list of repos, and pulls before it pushes. Notes and agent config move between machines that way, without my thinking about it.
The dotfiles repo itself is deliberately not on that list. Config changes get real commit messages, pushed by hand, because I want to be able to read the history later. There are 3,318 commits so far.
Starting from a new machine
A new machine takes one script per system, mac-setup.sh or linux-vps-setup.sh, followed by a shared user-setup.sh.
They install the package manager and chezmoi, clone the repos I work in, and run the first apply.
A few steps cannot be scripted, such as granting accessibility permissions on macOS. Those are written down in a manual checklist in the repo, so that the next setup does not depend on my memory.
Rules that keep it working
These are the habits that have saved me the most time.
- Edit the source, never the target. Anything else is lost on the next apply.
- Check shared files on both systems before committing. A change that works on the Mac can break a shell that starts under a different init system.
- Prefer ignoring a file to templating it. A template is harder to read than a file that simply is not there.
- Let scripts be re-runnable. An apply should be safe to run twice in a row.
- Write down what cannot be automated. A checklist beats a clever script that works once.
What it costs
It is not free. A setup like this is software, and software needs maintenance. An operating system update can break the status bar, and a tool can change its config format.
I think it is worth it. A new machine is usable in an afternoon, and both machines behave the same way under my hands. The source is at github.com/gnohj/dotfiles.