Tags

system configuration is logic programming

1. refresher: what is Nix?

Nix is best known as a system for building and deploying software.

But what is software made out of?

  1. Dependencies (e.g.: compiler, libraries)
  2. A build plan (e.g.: Makefile)
  3. Outputs (e.g.: binaries)

Nix can build and deploy anything that can be modeled in this way.

In particular, it can build and deploy an entire operating system (in sensu lato).

2. problem 0: features

An operating system is not a bag of unrelated files.

Rather, the contents of various files are correlated.

For example, if we want the default user shell to be Bash, we probably also want to set up completions and add bash (and sh) to the list of available shells.

# Adapted from nixpkgs/nixos/modules/programs/bash/bash.nix.
{ pkgs, ... }: {
  users.defaultUserShell = pkgs.bashInteractive;
  environment.pathsToLink = [
    "/etc/bash_completion.d"
    "/share/bash-completion"
  ];
  environment.shells = [
    "/run/current-system/sw/bin/bash"
    "/run/current-system/sw/bin/sh"
    "${pkgs.bashInteractive}/bin/bash"
    "${pkgs.bashInteractive}/bin/sh"
  ];
}

This is “problem 0” because you could solve it in pure Nix: just split correlated settings out into a file.

{
  inherit (import ./bash.nix);
}

This is our main paradigm for system configuration: higher-level settings as bundles of lower-level settings.

3. problem 1: “overloaded” settings

4. problem 2: feature dependency

5. problem 3: setting priority

6. Greenspun's tenth rule

Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.

The NixOS module system is certainly ad hoc and informally specified.

Author: Nicholas Coltharp (mail@heraplem.xyz)

Last modified: 2026-06-09 Tue 12:21

Emacs 30.2 (Org mode 9.7.11)

Validate