Migrating from stow to chezmoi

In a previous post I described my dotfiles setup via stow(Reorganizing my dotfiles). Today I read a blogpost with the title "Migrating from GNU stow to chezmoi" and while reading it I found I had the same problems the author had. My setup had grown over time and got more and more complex due to added hosts and varying dotfile configurations between the hosts.

The result was an order dependent, complex installation script.

With this in mind I though I would throw Claude Opus at the problem and try to let the agent migrate my existing stow configuration to one managed via chezmoi.

It nailed it almost instantly. The result is a much easier to understand and cleaned up dotfiles repository. Host specifics are setup through a custom hosts.yaml in .chezmoidata:

mbp-dvk:
    identity: personal
    git_ssh_sign_program: "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"

mbp-work:
	identity: work
...

Other differences are resolved through the use of the templates chezmoi comes with, f.e.:

# dot_config/git/config.tmpl
{{- if $host.git_ssh_sign_program }}
[gpg "ssh"]
    program = "{{ $host.git_ssh_sign_program }}"
{{- end }}

Trough .chezmoiignore I can exclude whole files based on the OS or identity:

{{- $host := index .hosts (lower .chezmoi.hostname) -}}

{{ if ne .chezmoi.os "darwin" -}}
.config/infat
{{- end }}

{{- /* Work-only files */}}
{{ if ne $host.identity "work" -}}
.config/zsh/.zshrc.d/99-work.zsh
{{- end }}

{{- /* Personal-only files */}}
{{ if ne $host.identity "personal" -}}
.config/zsh/.zshrc.d/99-personal.zsh
{{- end }}

Last but not least installation of the dotfiles is a simple chezmoi init REPO --apply. To check for differences of the source and the target files: chezmoi diff.

Posted in automation