Migrating from vcsh to chezmoi
May 1, 2025 · 5 minute read · CommentsTags: linux
Words: 1095
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:
- vcsh doesn't have support for secrets.
- I'm planning to migrate my laptop & desktop to Universal Blue Linux (from Ubuntu).
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:
- I have to have Keybase installed on all of my computers. This might be the case anyway, but it's a dependency I don't want to have to have to install my dotfiles on a new machine.
- The Keybase encrypted git repositories feature may simply disappear one day. Zoom don't appear to be that interested in maintaining it.
- Any files with secrets have to be stored in the encrypted git repository. This means that, say, if Neovim needed a secret, then either all of the config would need to be in the encrypted repo, or a file would be split out.
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:
- Ensure that all the vcsh repositories are up to date across all the machines that they are used on.
- Use
vcsh run <vcsh-repo> git ls-files
to find out what files are managed in that repo. - 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).
- Then cd into
~/.config/vcsh/repo.d/
and remove the associate<vcsh-repo>.git
directory. - 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
. - 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. - Remember to commit the files to chezmoi!
- 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:
- Removing the myrepos (
mr
) directory:cd ~/.config
andrm -rf mr
. - Removing the vcsh directory:
cd ~/.config
andrm -rf vcsh
. - Uninstalling
mr
andvcsh
, which will depend on your distro. If it's Ubuntu, then it'ssudo 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.