A simple Nix-based operating system.
foo, pronounced /fuː/, is an operating system designed around Nix and Nixpkgs. It provides a small set of primitives for constructing Linux systems with Nix. A full example system foobar is also provided.
foo is mainly intended for my own personal use.
foo does not provide a module system. Instead, it exposes a single function,
buildFoo, which takes a configuration attrset. Composition and merging are
intentionally left to the caller and can be implemented using normal Nix
expressions.
The configuration options provided by foo are intentionally primitive:
- Kernel packages.
- Kernel modules to include in the initrd.
- Commands to run in the initrd.
- Commands to run as init (PID 1).
- Paths and artifacts to include in the system closure.
Anything beyond these primitives has to be built on top of foo. For example, foo has no concept of "activation" or system "generations", but the foobar example system adds these features.
foo produces a UKI containing the provided kernel and initrd, and exposes a toplevel closure containing the init script and any additional artifacts. By default, only the init script is included. The foo build outputs are:
- Kernel,
build.kernel - Initrd,
build.initrd - UKI,
build.uki - Toplevel,
build.toplevel
Additional build outputs can be added using the outputs option. For example,
foo has no "disk image" output, but the foobar example system adds
this output.
To produce an options doc (markdown):
nix eval -f foo optionsMd --rawThis is also available in options.md. Options are not validated or checked.
An example system, "foobar", is provided which uses foo to build a minimal system with:
- Activation and system closure with familiar
swandetc /etcas an overlay with an immutable erofs lower and writable tmpfs upper- Impermanence (tmpfs) with persistent
/nix,/var,/home - Multi-user Nix with read-only
/nix/storeandnix-daemonin a private mount namespace - System generations using Nix Profiles, and switching with
foobar-rebuild - Basic networking and SSL certificates
- Disk image with
systemd-repartandsystemd-bootbootloader
foobar's configuration can also be extended using
.extend (for eg, to add services).
To build the example:
nix build -f foobar build.diskImageThis can be booted with QEMU.
