Skip to main content

Managing External Dependencies with Chezmoi

·512 words·3 mins

I use chezmoi for my dotfiles. To find out why and how to get started, check out my talk from Chemnitz Linux Days 2025.

Within chezmoi, you can use the file .chezmoiexternal.toml to download archives or git repositories during updates. This is particularly useful for managing external dependencies. Let me walk you through some common use cases.

Git Repositories
#

As I use Oh My Zsh for my shell, I clone the repository to .oh-my-zsh. That’s easy with this entry:

[".oh-my-zsh"]
  type = "git-repo"
  url = "https://github.com/ohmyzsh/ohmyzsh.git"
  refreshPeriod = "168h"

This clones the repository to ~/.oh-my-zsh (the path specified in the square brackets). To prevent Oh My Zsh’s built-in auto-update mechanism, I added the following line to my ~/.zshrc:

DISABLE_AUTO_UPDATE="true"

This way, I let chezmoi handle the updates instead of Oh My Zsh’s own update system.

Downloading Releases
#

When you want to get the latest release from a GitHub repository, you can configure it in .chezmoiexternal.toml:

[".local/share"]
  type = "archive"
  url = "https://github.com/neovim/neovim/releases/latest/download/nvim-{{ .chezmoi.os }}-x86_64.tar.gz"
  refreshPeriod = "168h"

This downloads the latest release of neovim from GitHub and extracts the files to ~/.local/share. The package extraction creates a folder named nvim-linux-x86_64. I then created a symbolic link to a folder in my $PATH:

ls ~/.local/bin/nvim -al
lrwxrwxrwx. 1 stoeps stoeps 56 Mar  5 20:41 /var/home/stoeps/.local/bin/nvim -> /var/home/stoeps/.local/share/nvim-linux-x86_64/bin/nvim

This symbolic link is also part of my Chezmoi repository.

With this setup, each time I run chezmoi apply (but only once every 168 hours, which equals 7 days), I get the latest release of neovim.

I manage this with chezmoi rather than within my distrobox/toolboxes because I want to use the latest and greatest neovim version across all my toolboxes.

Releases with Version Numbers (updated 2025-04-14)
#

Some GitHub software includes the version number in the filename, which means you can’t simply use “latest” in the URL.

Note

In the initial version of the post, I showed a script to check for the version number and update .chezmoiexternal.toml, but I got a mail from Tom Payne the maintainer of chezmoi, who pointed me to the GitHub functions included in chezmoi. He also sent me the link to his dotfiles repository with working examples.

So we can just use gitHubLatestReleaseAssetURL to get the latest version from Hugo:

[".local/bin/hugo"]
    type = "archive-file"
    url = {{ gitHubLatestReleaseAssetURL "gohugoio/hugo" (printf "hugo_*_%s-%s.tar.gz" .chezmoi.os .chezmoi.arch) | quote }}
    executable = true
    path = "hugo"

This extracts just the Hugo binary from the downloaded package and places it directly into ~/.local/bin/hugo. The download URL uses variables for .chezmoi.os and .chezmoi.arch, which get replaced with the values from the running system (in my case, linux and amd64).

Since I build my blog with a GitLab action using the latest available Hugo version, it’s important for me to have an up-to-date version locally so I can test changes and new posts directly.

I really appreciate that Tom monitors articles and talks about chezmoi, and he also sent me a mail with a shortcut for my talk at Chemnitz Linux Days on the day of the talk. Thanks for the awesome tool Tom!

Christoph Stoettner
Author
Christoph Stoettner
I work at Vegard IT GmbH as a senior consultant, focusing on collaboration software, Kubernetes, security, and automation. I primarily work with HCL Connections, WebSphere Application Server, Kubernetes, Ansible, Terraform, and Linux. My daily work occasionally leads to technical talks and blog articles, which I share here more or less regularly.

Related

Selfhost Shaarli

I use Shaarli since ages to collect links, notes and bookmarks. I worked a little bit on that collection and started to share some as public lists. On my mobile device I bought a license for Stakali, it fits perfectly into my workflows. I often search on my mobile and share the link through Stakali to my desktop. Stakali just needs the URL and the API Key of Shaarli, but I got errors. So I analyzed the source and app with:

Build your own Watson Workspace Linux Client

·539 words·3 mins
Watson Workspace Clients are only available for Windows and Mac OS. I’m a 100% Linux user on my devices and I use a Windows virtual machine only if I can’t avoid it. To communicate with colleagues, IBM and DNUG I need to use Watson Workplace, opening the web view is possible, but then I need to search the right tab or forget to open it. Since some weeks there is Zoom (Web / Video meetings) integrated with Watson Workspace too.: Watson Workspace clients are based on Electron. I’m not a big fan of Electron clients, most of them are big and need tons of system resources. There is enough written about advantages and disadvantages, so I just leave it that way.