NixCon 2020: Online Edition

Nix modules: Improving Nix's discoverability and usability
10-16, 11:15–11:40 (UTC), Main Stream

Nix's configuration language is quite powerful, but suffers from a
lack of discoverability, usability and consistency. In this talk, I'll
describe an experimental Nix module system that provides a consistent,
discoverable mechanism to write configurations such as packages and
NixOS systems, and show how this enables a better user experience for
both new and advanced users.


Nix's configuration language is quite powerful, but suffers from a
lack of discoverability, usability and consistency. To name just a few
examples:

  • There is no easy way to find out from the command line or from the
    REPL what arguments are supported by functions like
    stdenv.mkDerivation or buildPythonPackage.

  • Mechanisms like the .override attribute provide an almost unlimited
    ability to customize packages, but the only way to figure out what
    you can override is to read the source of the Nix package, and
    writing overrides is often black magic.

  • NixOS has a nice self-documenting module system, but Nix packages
    are written in a completely different functional style.

  • The Nix CLI doesn't know anything about package functions, .override
    and .overrideDerivation, the NixOS module system, the Nixpkgs
    config attribute set, Nixpkgs overlays, or any other customization
    mechanisms that have emerged over the years.

  • The syntax and semantics of Nix expressions are often an obstacle to
    new users and have a steep learning curve.

In this talk, I'll show an experimental Nix module system, similar to
the NixOS module system, to replace the "functional" package style
using in Nixpkgs. This means that functions like mkDerivation or
buildPythonPackage as well as packages become modules that can build
on each other. For instance, the "GNU Hello" package is a module that
inherits from the unixPackage module, which in turn inherits from other
modules like derivation. Package customization is done in the same
way: by inheriting a module.

These modules, just like in NixOS, have types and documentation. As a
result, everything becomes discoverable and modifiable from the
command line. For instance, there is a command nix list-options that
shows everything that can be customized in a package. It also provides
a standard for documentation: the command nix doc generates HTML
documentation for the modules in a flake.

See also: Slides (159.1 KB)

Eelco Dolstra is a Senior Software Engineer at Tweag I/O. He obtained
a PhD in Computer Science from Utrecht University in 2006 and was a
postdoctoral researcher at Utrecht University and Delft University of
Technology. From 2012 to 2018 he was a Software Engineer at LogicBlox
(acquired by Infor in 2016). As part of his PhD research project at
Utrecht University, he developed Nix, the purely functional package
manager. Together with Armijn Hemel, he started the NixOS Linux
distribution in 2006. He joined Tweag I/O in 2018. He also serves as
President of the NixOS Foundation.