Migrating from vcsh to chezmoi

I've used vcsh for a long time. However, recently, for a number of reasons I've been meaning to migrate from vcsh to Chezmoi. I didn't find any particularly useful information about how to remove vcsh and leave the files behind, so this post documents what I did to make the move.

I dutifully split my configuration of dotfiles across multiple git repositories and it's worked well for a number of years. However, more recently, I've been pondering a change, and that change is to chezmoi.

My reasons for moving from vcsh to chezmoi are basically:

The secret support is more important. Currently I use a Keybase encrypted git repository for any files with secrets, but this comes with a number of problems:

Chezmoi supports age encryption, which I already use elsewhere, and thus it makes sense to use that to encrypt secrets for dot-files. It means that the secrets can live alongside the other config in a single repository, which just makes day-to-day live easier. Note that the secrets are entire files in chezmoi, but they can be used in templates to obtain the secret and place them into a managed file. Using JSON files, many of the secrets can be stored in the same encrypted file and then, using templates, fed into the other config files as needed.

Migrating from vcsh to chezmoi

So I hunted around around for a guide on how to stop vcsh managing a file. The only vcsh command available is 'delete' but it actually seems to delete the managed files. Looking at the vcsh code:

delete() {
	cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
	use
	info "This operation WILL DESTROY DATA!"
	files=$(@GIT@ ls-files)
	echo "These files will be deleted:

$files

This implies that the files managed (git ls-files) will be deleted. Obviously we don't want to do this as we are migrating these files to a new service and only want to 'un-manage' the file. Note that this isn't what the manpage actually says for vcsh. However, the code does indicate that it will delete the files:

 ...
	[ "x$answer" = 'xYes, do as I say' ] || exit 16
	for file in $files; do
		rm -f "$file" || info "could not delete '$file', continuing with deletion"
	done
	rm -rf "$GIT_DIR" || error "could not delete '$GIT_DIR'"
 ...

So, basically, I don't trust vcsh delete to just delete the repo and not all the managed files as well.

I could use vcsh enter <repo> and then un-manage the files from the git perspective (e.g. git rm --cached <file> for each file in git ls-files) but I decided on a more brutal approach: just remove the git repos.

Basic Approach

So to migrate from chezmoi to vcsh, the basic approach is to:

  1. Ensure that all the vcsh repositories are up to date across all the machines that they are used on.
  2. Use vcsh run <vcsh-repo> git ls-files to find out what files are managed in that repo.
  3. Add those files to chezmoi. Remember, that you can 'bulk' add files by adding the directory, and that's probably better as chezmoi manages the directory, rather than the file (I think).
  4. Then cd into ~/.config/vcsh/repo.d/ and remove the associate <vcsh-repo>.git directory.
  5. Then cd into ~/.gitignore.d/ and remove/move the associated <vcsh-repo. file; this is the ignores for vcsh to enable you to add without using -f.
  6. If also using mr (myrepos) then also cd into ~/.config/mr/config.d/ and remove the <vcsh-repo>.vcsh symlink (to ../available.d/<vcsh-repo>.vcsh). This removes it from the mr list.
  7. Remember to commit the files to chezmoi!
  8. Repeat for the remaining repos.

Finally, there will only be the mr repo in vcsh list and you are done transferring files. Now you just need to clean up mr and vcsh, by:

  1. Removing the myrepos (mr) directory: cd ~/.config and rm -rf mr.
  2. Removing the vcsh directory: cd ~/.config and rm -rf vcsh.
  3. Uninstalling mr and vcsh, which will depend on your distro. If it's Ubuntu, then it's sudo apt purge myrepos vcsh.

Summary

I think it's better to go slow and carefully migrate each file. This gives you an opportunity to assess whether you still want to manage a file under chezmoi. Also when/if you come to secrets, you'll need to manage them using something like age, which I'll do as another post/note.

Comments: