Exploring Nix Flakes: Usable Go Plugins

2022-02-04

Last updated 2022-02-17, see Changelog

Building plugin-supporting applications in Go is currently a sub-par experience. Go does have a -buildmode=plugin that lets you create .so files, which can then be loaded as plugin in a Go application. But:

In this article, I will show how to use Nix Flakes as a build system for Go supporting plugin management. This article has three parts, excluding the abstract you are just reading:

I will assume you are familiar with Nix Flakes and Go. In particular, I will show some complex Nix expressions and assume you can read them. If you don’t know much about Nix and are in a hurry, I recommend this article for a quick overview of the language and Flakes. A proper way to learn about Nix is the Nix Pills series, and this series about Nix Flakes.

This article may also be interesting for people who simply are curious how to use Nix with Go. To follow the instructions in this article, you need the nix utility installed and Flake support enabled. Executing the commands shown in this article will potentially trigger downloads of multiple GB of data.

If you want to follow the article’s instructions, create an empty directory that will be the root for all files and subdirectories we’ll create We need all files processed by Nix to be checked in to version control, so initialize a git repository in this directory with git init. All code discussed in this article is available on GitHub, so if you don’t want to copy code from the article, you can also just clone that repository.

Changelog

2022-02-17