Nixing splitsh/lite

I'm a fan of monorepos and use them for my presentations and books rather than creating a new Git repository for every book and presentation.

I've done the same for the Drupal Gather project - a Drupal distribution that I've started building for meetup and user group websites that contains an example project, an installation profile and several recipes - all stored and developed in the same Git repository.

For deployment and consumption via Composer, I want each sub-project to be available in its own standalone repository, so I need a way to split each project from the monorepo when needed.

Git has the subtree split command, but it is slow and although it's improved by the --rejoin option, it creates additional commits in the repository for both the split code and a merge commit containing the metadata.

I've also had several caching errors when trying to perform a split - even from a fresh clone - that have prevented me from deploying changes, so I wanted to look for other options.

splitsh/lite

Fabien Potencier - the creator of Symfony - has spoken about how Symfony uses a combination of a monorepo and many-repo strategies and has open sourced a tool based on the one used by Symfony.

It's written in Go and uses libgit2, but has some versioning challenges.

From the README:

First, you need to install libgit2, preferably using your package manager of choice.

If you get libgit2 version 1.5, you're all set and jump to the compilation step below. If not, you first need to change the git2go version used in the code. Using the table on the libgit2 repository, figure out which version of the git2go you need based on the libgit2 library you installed.

This seemed like a great use case for Nix and its reproducible build system.

Adding a Nix flake

The current version of libgit2 in nixpkgs is 1.9.2 - too new for the tool to use and for git2go.

By pinning nixpkgs to the 22.11 channel, I was able to get the required 1.5 version of libgit2 and create a package based on it and pkg-config - both of which are needed to build the project.

Now I can easily build the project using nix build or create and use a dev shell with nix develop.

Submitting a pull request

I have created a pull request to add the Nix flake to the main project repository.

If it's not added, I'll create a standalone flake in its own repository.

In the meantime, you can test it from my forked version using either nix run github:opdavies/splitsh-lite/add-nix-flake or nix shell github:opdavies/splitsh-lite/add-nix-flake.

If you need any assistance, feel free to get in touch.