# Exploring Nix Flakes: Build LaTeX Documents Reproducibly

2021-11-17

Last updated 2021-12-30, see Changelog

This article shows how to use Nix Flakes to build LaTeX documents. It is not particularly beginner-friendly to keep it at manageable size.

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.

The proper way to learn LaTeX is to take any vaguely math-related academic course and be peer-pressured into trying it out until it works. Jokes aside, this probably isn’t an interesting read for people who are not already familiar with LaTeX; while I will explain the things I’m doing with Nix, the LaTeX code I will just throw at you assuming you can read it.

## Getting Started

In an empty directory, let’s start a document.tex file like this:

Now we want to tell Nix how to build this document. To do this, create a file flake.nix with the following content:

Our inputs are nixpkgs, the main Nix package repository, from which we primarily need TeX Live, and flake-utils, a library that provides some convenience functions.

For defining our outputs, we use eachSystem (from flake-utils) to define an output package for each system in allSystems – we do want users on any system to be able to compile our document.

The important bit pkgs.texlive.combine builds a TeX Live installation containing the TeX Live packages we specify. For building our minimal document, we start with scheme-minimal and include latex-bin (to have lualatex) and latexmk (our helper script to build the document).

### 2021-11-30

• Added section describing how to produce identical documents.