We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Nix modules: Improving Nix's discoverability and usability

Formal Metadata

Title
Nix modules: Improving Nix's discoverability and usability
Title of Series
Number of Parts
19
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date2020
LanguageEnglish

Content Metadata

Subject Area
Genre
Abstract
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.