From 3fe60580da3c32fa6eb175bcd478631e1994dd49 Mon Sep 17 00:00:00 2001
From: Jake Hamilton <jake.hamilton@hey.com>
Date: Tue, 4 Jun 2024 19:04:40 -0700
Subject: [PATCH] feat: add foundation

---
 .gitignore                                    |    2 +
 README.md                                     |    7 +-
 foundation/LICENSE                            |   23 +
 foundation/README.md                          |   95 ++
 foundation/flake.lock                         |   23 +
 foundation/flake.nix                          |   37 +
 foundation/src/builders/file/text/default.nix |   63 +
 foundation/src/builders/kaem/default.nix      |   65 +
 foundation/src/builders/raw/default.nix       |   42 +
 foundation/src/default.nix                    |   12 +
 foundation/src/exports/default.nix            |   38 +
 foundation/src/platform/default.nix           |  324 +++++
 foundation/src/stages/stage0/default.nix      |   76 +
 foundation/src/stages/stage0/kaem/build.kaem  |    3 +
 foundation/src/stages/stage0/kaem/default.nix |   77 +
 .../stage0/mescc-tools-extra/build.kaem       |   40 +
 .../stage0/mescc-tools-extra/default.nix      |   79 +
 .../src/stages/stage0/mescc-tools/build.kaem  |  205 +++
 .../src/stages/stage0/mescc-tools/default.nix |  178 +++
 .../src/stages/stage0/phases/phase00.nix      |  223 +++
 .../src/stages/stage0/phases/phase01.nix      |   62 +
 .../src/stages/stage0/phases/phase02.nix      |   63 +
 .../src/stages/stage0/phases/phase03.nix      |   73 +
 .../src/stages/stage0/phases/phase04.nix      |   79 +
 .../src/stages/stage0/phases/phase05.nix      |   93 ++
 .../src/stages/stage0/phases/phase06.nix      |  144 ++
 .../src/stages/stage0/phases/phase07.nix      |  134 ++
 .../src/stages/stage0/phases/phase08.nix      |  159 +++
 .../src/stages/stage0/phases/phase09.nix      |  178 +++
 .../src/stages/stage0/phases/phase10.nix      |  184 +++
 .../src/stages/stage0/phases/phase11.nix      |  184 +++
 .../src/stages/stage0/phases/phase12.nix      |  186 +++
 foundation/src/stages/stage1/default.nix      |   17 +
 foundation/src/stages/stage1/mes/default.nix  |   12 +
 foundation/src/system/default.nix             |   11 +
 lib/flake.nix                                 |    2 +-
 lib/src/attrs/default.nix                     |   14 +
 lib/src/default.nix                           |    1 +
 lib/src/licenses/all.nix                      | 1270 +++++++++++++++++
 lib/src/licenses/default.nix                  |   33 +
 lib/src/modules/default.nix                   |    4 +-
 lib/src/packages/default.nix                  |    8 +
 lib/src/paths/default.nix                     |   32 +
 43 files changed, 4549 insertions(+), 6 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 foundation/LICENSE
 create mode 100644 foundation/README.md
 create mode 100644 foundation/flake.lock
 create mode 100644 foundation/flake.nix
 create mode 100644 foundation/src/builders/file/text/default.nix
 create mode 100644 foundation/src/builders/kaem/default.nix
 create mode 100644 foundation/src/builders/raw/default.nix
 create mode 100644 foundation/src/default.nix
 create mode 100644 foundation/src/exports/default.nix
 create mode 100644 foundation/src/platform/default.nix
 create mode 100644 foundation/src/stages/stage0/default.nix
 create mode 100644 foundation/src/stages/stage0/kaem/build.kaem
 create mode 100644 foundation/src/stages/stage0/kaem/default.nix
 create mode 100644 foundation/src/stages/stage0/mescc-tools-extra/build.kaem
 create mode 100644 foundation/src/stages/stage0/mescc-tools-extra/default.nix
 create mode 100644 foundation/src/stages/stage0/mescc-tools/build.kaem
 create mode 100644 foundation/src/stages/stage0/mescc-tools/default.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase00.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase01.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase02.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase03.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase04.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase05.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase06.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase07.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase08.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase09.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase10.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase11.nix
 create mode 100644 foundation/src/stages/stage0/phases/phase12.nix
 create mode 100644 foundation/src/stages/stage1/default.nix
 create mode 100644 foundation/src/stages/stage1/mes/default.nix
 create mode 100644 foundation/src/system/default.nix
 create mode 100644 lib/src/licenses/all.nix
 create mode 100644 lib/src/licenses/default.nix

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2bbdbfe
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.direnv
+result
diff --git a/README.md b/README.md
index 80477fe..f75f1f7 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,7 @@ may collaborate.
 
 ## Experiments
 
-| Name             | Phase     | Description                                              |
-| ---------------- | --------- | -------------------------------------------------------- |
-| [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. |
+| Name                           | Phase     | Description                                                                |
+| ------------------------------ | --------- | -------------------------------------------------------------------------- |
+| [Aux Lib](./lib)               | Iteration | A library of common functions used in the Aux ecosystem.                   |
+| [Aux Foundation](./foundation) | Idea      | Foundational packages which allow for bootstrapping a greater package set. |
diff --git a/foundation/LICENSE b/foundation/LICENSE
new file mode 100644
index 0000000..22c5fd5
--- /dev/null
+++ b/foundation/LICENSE
@@ -0,0 +1,23 @@
+MIT License
+Copyright (c) 2003-2023 Eelco Dolstra and the Nixpkgs/NixOS contributors
+Copyright (c) 2024 Aux Contributors
+
+Permission is hereby granted, free
+of charge, to any person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to the
+following conditions:
+
+The above copyright notice and this permission notice
+(including the next paragraph) shall be included in all copies or substantial
+portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
+EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/foundation/README.md b/foundation/README.md
new file mode 100644
index 0000000..5afb185
--- /dev/null
+++ b/foundation/README.md
@@ -0,0 +1,95 @@
+# Aux Foundation
+
+Aux Foundation provides a set of foundational packages which are required for bootstrapping
+a larger package set.
+
+## Usage
+
+Packages can be imported both with and without Nix Flakes. To import them using Nix Flakes,
+add this repository as an input.
+
+```nix
+inputs.foundation.url = "github:auxolotl/labs?dir=foundation";
+```
+
+To import this library without using Nix Flakes, you will need to use `fetchTarball` and
+import the library entrypoint.
+
+```nix
+let
+    labs = builtins.fetchTarball {
+        url = "https://github.com/auxolotl/labs/archive/main.tar.gz";
+        sha256 = "<sha256>";
+    };
+    lib = import "${labs}/foundation";
+in
+    # ...
+```
+
+## Development
+
+This foundational package set is created using modules. Each builder and package is separated
+accordingly and can be found in their respective directories. In addition, packages are grouped
+into the different stages of the bootstrapping process.
+
+### Inputs
+
+Due to the fundamental nature of this project, the only accepted input is `lib` which itself
+has no dependencies. _Everything_ else must be built from scratch in the package set.
+
+### Formatting
+
+> **Note:** To keep this flake light and keep its inputs empty we do not include a package
+> set which would provide a formatter. Instead please run `nix run nixpkgs#nixfmt-rfc-style`
+> until an improved solution is available.
+
+All code in this project must be formatted using the provided formatter in the `flake.nix`
+file. You can run this formatter using the command `nix fmt` (not currently available).
+
+### Code Quality
+
+In order to keep the project approachable and easy to maintain, certain patterns are not allowed.
+In particular, the use of `with` and `rec` are not allowed. Additionally, you should prefer the
+fully qualified name of a variable rather than creating intermediate ones using `inherit`.
+
+### Builders
+
+Builders are wrappers around `builtins.derivation` and provide additional functionality via
+abstraction. They can be found in [`./src/builders`](./src/builders). Each builder specifies
+its own `build` function which can be called elsewhere in the package set to construct packages.
+
+For example, here is a module that makes use of the `kaem` builder:
+
+```nix
+{config}: let
+    builders = config.aux.foundation.builders;
+    stage0 = config.aux.foundation.stages.stage0;
+
+    package = builders.kaem.build {
+        name = "my-package";
+
+        deps.build.host = [
+            stage0.mescc-tools.package
+            stage0.mescc-tools-extra.package
+        ];
+
+        script = ''
+            mkdir ''${out}/bin
+            cp ${./my-binary} ''${out}/bin/my-package
+            chmod 555 ''${out}/bin/my-package
+        '';
+    };
+in
+    # ...
+```
+
+### Stages
+
+The bootstrapping process is broken up into different stages which focus on different goals.
+Each stage can be found in [`./src/stages`](./src/stages).
+
+#### Stage 0
+
+This stage is responsible for starting with a single binary seed and producing the tools
+necessary to compile (simple) C code. This stage will then compile the original tools it
+used from C sources.
diff --git a/foundation/flake.lock b/foundation/flake.lock
new file mode 100644
index 0000000..ae29a0d
--- /dev/null
+++ b/foundation/flake.lock
@@ -0,0 +1,23 @@
+{
+  "nodes": {
+    "lib": {
+      "locked": {
+        "lastModified": 1,
+        "narHash": "sha256-303zkU+ntdAF6JLE9gA3k5piX5RvKtQp6JXovZWzDdQ=",
+        "path": "../lib",
+        "type": "path"
+      },
+      "original": {
+        "path": "../lib",
+        "type": "path"
+      }
+    },
+    "root": {
+      "inputs": {
+        "lib": "lib"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/foundation/flake.nix b/foundation/flake.nix
new file mode 100644
index 0000000..f17fe5d
--- /dev/null
+++ b/foundation/flake.nix
@@ -0,0 +1,37 @@
+{
+  description = "A set of foundational packages required for bootstrapping a larger package set.";
+
+  inputs = {
+    lib = {
+      url = "path:../lib";
+    };
+  };
+
+  outputs = inputs: let
+    inherit (inputs.lib) lib;
+
+    modules = import ./src;
+
+    forEachSystem = lib.attrs.generate [
+      "x86_64-linux"
+      "aarch64-linux"
+      # "x86_64-darwin"
+      # "aarch64-darwin"
+    ];
+  in {
+    modules.aux = modules;
+
+    packages = forEachSystem (
+      system: let
+        result = lib.modules.run {
+          modules =
+            (builtins.attrValues modules)
+            ++ [
+              {config.aux.system = system;}
+            ];
+        };
+      in
+        result.config.exports.resolved.packages
+    );
+  };
+}
diff --git a/foundation/src/builders/file/text/default.nix b/foundation/src/builders/file/text/default.nix
new file mode 100644
index 0000000..957f8ed
--- /dev/null
+++ b/foundation/src/builders/file/text/default.nix
@@ -0,0 +1,63 @@
+{
+  lib,
+  config,
+}: let
+  system = config.aux.system;
+in {
+  options.aux.foundation.builders.file.text = {
+    build = lib.options.create {
+      type = lib.types.function lib.types.package;
+      description = "Builds a package using the text file builder.";
+    };
+  };
+
+  config = {
+    aux.foundation.builders.file.text = {
+      build = lib.modules.overrides.default (settings @ {
+        name,
+        contents,
+        isExecutable ? false,
+        destination ? "",
+        meta ? {},
+        extras ? {},
+        ...
+      }: let
+        script =
+          ''
+            target=''${out}''${destination}
+          ''
+          + lib.strings.when (builtins.dirOf destination == ".") ''
+            mkdir -p ''${out}''${destinationDir}
+          ''
+          + ''
+            cp ''${contentPath} ''${target}
+          ''
+          + lib.strings.when isExecutable ''
+            chmod 555 ''${target}
+          '';
+        package = builtins.derivation (
+          (builtins.removeAttrs settings ["meta" "extras" "executable" "isExecutable"])
+          // {
+            inherit name system contents destination;
+            destinationDir = builtins.dirOf destination;
+
+            passAsFile = ["contents"];
+
+            builder = "${config.aux.foundation.stages.stage0.kaem.package}/bin/kaem";
+
+            args = [
+              "--verbose"
+              "--strict"
+              "--file"
+              (builtins.toFile "write-text-to-file.kaem" script)
+            ];
+          }
+        );
+      in
+        package
+        // {
+          inherit meta extras;
+        });
+    };
+  };
+}
diff --git a/foundation/src/builders/kaem/default.nix b/foundation/src/builders/kaem/default.nix
new file mode 100644
index 0000000..36f3304
--- /dev/null
+++ b/foundation/src/builders/kaem/default.nix
@@ -0,0 +1,65 @@
+{
+  lib,
+  config,
+}: let
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+
+  stage0 = config.aux.foundation.stages.stage0;
+in {
+  options.aux.foundation.builders.kaem = {
+    build = lib.options.create {
+      type = lib.types.function lib.types.package;
+      description = "Builds a package using the kaem builder.";
+    };
+  };
+
+  config = {
+    aux.foundation.builders.kaem = {
+      build = lib.modules.overrides.default (settings @ {
+        name,
+        script,
+        meta ? {},
+        extras ? {},
+        env ? {},
+        deps ? {},
+        ...
+      }: let
+        package = builtins.derivation (
+          (builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"])
+          env
+          // {
+            inherit name system;
+
+            builder = "${stage0.kaem.package}/bin/kaem";
+
+            args = [
+              "--verbose"
+              "--strict"
+              "--file"
+              (
+                builders.file.text.build {
+                  name = "${name}-builder";
+                  contents = script;
+                }
+              )
+            ];
+
+            PATH = lib.paths.bin (
+              (deps.build.host or [])
+              ++ [
+                stage0.kaem.package
+                stage0.mescc-tools.package
+                stage0.mescc-tools-extra.package
+              ]
+            );
+          }
+        );
+      in
+        package
+        // {
+          inherit meta extras;
+        });
+    };
+  };
+}
diff --git a/foundation/src/builders/raw/default.nix b/foundation/src/builders/raw/default.nix
new file mode 100644
index 0000000..d32c1b1
--- /dev/null
+++ b/foundation/src/builders/raw/default.nix
@@ -0,0 +1,42 @@
+{
+  lib,
+  config,
+}: let
+  system = config.aux.system;
+in {
+  options.aux.foundation.builders.raw = {
+    build = lib.options.create {
+      type = lib.types.function lib.types.package;
+      description = "Builds a package using the raw builder.";
+    };
+  };
+
+  config = {
+    aux.foundation.builders.raw = {
+      build = lib.modules.overrides.default (settings @ {
+        pname,
+        version,
+        executable,
+        args ? [],
+        meta ? {},
+        extras ? {},
+        ...
+      }: let
+        package = builtins.derivation (
+          (builtins.removeAttrs settings ["meta" "extras" "executable"])
+          // {
+            inherit version pname system args;
+
+            name = "${pname}-${version}";
+
+            builder = executable;
+          }
+        );
+      in
+        package
+        // {
+          inherit meta extras;
+        });
+    };
+  };
+}
diff --git a/foundation/src/default.nix b/foundation/src/default.nix
new file mode 100644
index 0000000..3c4458e
--- /dev/null
+++ b/foundation/src/default.nix
@@ -0,0 +1,12 @@
+let
+  modules = {
+    builderFileText = ./builders/file/text;
+    builderKaem = ./builders/kaem;
+    builderRaw = ./builders/raw;
+    exports = ./exports;
+    platform = ./platform;
+    stage0 = ./stages/stage0;
+    system = ./system;
+  };
+in
+  modules
diff --git a/foundation/src/exports/default.nix b/foundation/src/exports/default.nix
new file mode 100644
index 0000000..902bce8
--- /dev/null
+++ b/foundation/src/exports/default.nix
@@ -0,0 +1,38 @@
+{
+  lib,
+  config,
+}: let
+  options = {
+    packages = lib.options.create {
+      default.value = {};
+
+      type = lib.types.attrs.of lib.types.package;
+    };
+  };
+in {
+  options = {
+    exports = {
+      inherit (options) packages;
+
+      resolved = {
+        inherit (options) packages;
+      };
+    };
+  };
+
+  config = {
+    exports.resolved =
+      builtins.mapAttrs (
+        name: value:
+          lib.attrs.filter
+          (
+            name: value:
+              if value ? meta && value.meta ? platforms
+              then builtins.elem config.aux.system value.meta.platforms
+              else true
+          )
+          value
+      )
+      (builtins.removeAttrs config.exports ["resolved"]);
+  };
+}
diff --git a/foundation/src/platform/default.nix b/foundation/src/platform/default.nix
new file mode 100644
index 0000000..8ef4bd5
--- /dev/null
+++ b/foundation/src/platform/default.nix
@@ -0,0 +1,324 @@
+{
+  lib,
+  config,
+}: let
+  system = config.aux.system;
+
+  parts = lib.strings.split "-" system;
+
+  platform = builtins.elemAt parts 0;
+  target = builtins.elemAt parts 1;
+
+  platforms = {
+    arm = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+    };
+    armv5tel = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "5";
+      arch = "armv5t";
+    };
+    armv6m = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "6";
+      arch = "armv6-m";
+    };
+    armv6l = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "6";
+      arch = "armv6";
+    };
+    armv7a = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "7";
+      arch = "armv7-a";
+    };
+    armv7r = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "7";
+      arch = "armv7-r";
+    };
+    armv7m = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "7";
+      arch = "armv7-m";
+    };
+    armv7l = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "7";
+      arch = "armv7";
+    };
+    armv8a = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "8";
+      arch = "armv8-a";
+    };
+    armv8r = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "8";
+      arch = "armv8-a";
+    };
+    armv8m = {
+      bits = 32;
+      endian = "little";
+      family = "arm";
+      version = "8";
+      arch = "armv8-m";
+    };
+    aarch64 = {
+      bits = 64;
+      endian = "little";
+      family = "arm";
+      version = "8";
+      arch = "armv8-a";
+    };
+    aarch64_be = {
+      bits = 64;
+      endian = "big";
+      family = "arm";
+      version = "8";
+      arch = "armv8-a";
+    };
+
+    i386 = {
+      bits = 32;
+      endian = "little";
+      family = "x86";
+      arch = "i386";
+    };
+    i486 = {
+      bits = 32;
+      endian = "little";
+      family = "x86";
+      arch = "i486";
+    };
+    i586 = {
+      bits = 32;
+      endian = "little";
+      family = "x86";
+      arch = "i586";
+    };
+    i686 = {
+      bits = 32;
+      endian = "little";
+      family = "x86";
+      arch = "i686";
+    };
+    x86_64 = {
+      bits = 64;
+      endian = "little";
+      family = "x86";
+      arch = "x86-64";
+    };
+
+    microblaze = {
+      bits = 32;
+      endian = "big";
+      family = "microblaze";
+    };
+    microblazeel = {
+      bits = 32;
+      endian = "little";
+      family = "microblaze";
+    };
+
+    mips = {
+      bits = 32;
+      endian = "big";
+      family = "mips";
+    };
+    mipsel = {
+      bits = 32;
+      endian = "little";
+      family = "mips";
+    };
+    mips64 = {
+      bits = 64;
+      endian = "big";
+      family = "mips";
+    };
+    mips64el = {
+      bits = 64;
+      endian = "little";
+      family = "mips";
+    };
+
+    mmix = {
+      bits = 64;
+      endian = "big";
+      family = "mmix";
+    };
+
+    m68k = {
+      bits = 32;
+      endian = "big";
+      family = "m68k";
+    };
+
+    powerpc = {
+      bits = 32;
+      endian = "big";
+      family = "power";
+    };
+    powerpc64 = {
+      bits = 64;
+      endian = "big";
+      family = "power";
+    };
+    powerpc64le = {
+      bits = 64;
+      endian = "little";
+      family = "power";
+    };
+    powerpcle = {
+      bits = 32;
+      endian = "little";
+      family = "power";
+    };
+
+    riscv32 = {
+      bits = 32;
+      endian = "little";
+      family = "riscv";
+    };
+    riscv64 = {
+      bits = 64;
+      endian = "little";
+      family = "riscv";
+    };
+
+    s390 = {
+      bits = 32;
+      endian = "big";
+      family = "s390";
+    };
+    s390x = {
+      bits = 64;
+      endian = "big";
+      family = "s390";
+    };
+
+    sparc = {
+      bits = 32;
+      endian = "big";
+      family = "sparc";
+    };
+    sparc64 = {
+      bits = 64;
+      endian = "big";
+      family = "sparc";
+    };
+
+    wasm32 = {
+      bits = 32;
+      endian = "little";
+      family = "wasm";
+    };
+    wasm64 = {
+      bits = 64;
+      endian = "little";
+      family = "wasm";
+    };
+
+    alpha = {
+      bits = 64;
+      endian = "little";
+      family = "alpha";
+    };
+
+    rx = {
+      bits = 32;
+      endian = "little";
+      family = "rx";
+    };
+    msp430 = {
+      bits = 16;
+      endian = "little";
+      family = "msp430";
+    };
+    avr = {
+      bits = 8;
+      family = "avr";
+    };
+
+    vc4 = {
+      bits = 32;
+      endian = "little";
+      family = "vc4";
+    };
+
+    or1k = {
+      bits = 32;
+      endian = "big";
+      family = "or1k";
+    };
+
+    loongarch64 = {
+      bits = 64;
+      endian = "little";
+      family = "loongarch";
+    };
+
+    javascript = {
+      bits = 32;
+      endian = "little";
+      family = "javascript";
+    };
+  };
+in {
+  options.aux.platform = {
+    family = lib.options.create {
+      type = lib.types.string;
+      description = "Family of the platform";
+    };
+
+    bits = lib.options.create {
+      type = lib.types.int;
+      description = "Number of bits in the platform";
+    };
+
+    endian = lib.options.create {
+      type = lib.types.enum ["little" "big"];
+      default.value = "big";
+      description = "Endianess of the platform";
+    };
+
+    arch = lib.options.create {
+      type = lib.types.nullish lib.types.string;
+      default.value = null;
+      description = "Architecture of the platform";
+    };
+
+    version = lib.options.create {
+      type = lib.types.nullish lib.types.string;
+      default.value = null;
+      description = "Version of the platform";
+    };
+  };
+
+  config = {
+    aux.platform =
+      platforms.${platform}
+      or (builtins.throw "Unsupported platform: ${system}");
+  };
+}
diff --git a/foundation/src/stages/stage0/default.nix b/foundation/src/stages/stage0/default.nix
new file mode 100644
index 0000000..0ded291
--- /dev/null
+++ b/foundation/src/stages/stage0/default.nix
@@ -0,0 +1,76 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+
+  architecture =
+    if system == "x86_64-linux"
+    then "AMD64"
+    else if system == "aarch64-linux"
+    then "AArch64"
+    else if system == "i686-linux"
+    then "x86"
+    else builtins.throw "Unsupported system for stage0: ${system}";
+in {
+  includes = [
+    ./phases/phase00.nix
+    ./phases/phase01.nix
+    ./phases/phase02.nix
+    ./phases/phase03.nix
+    ./phases/phase04.nix
+    ./phases/phase05.nix
+    ./phases/phase06.nix
+    ./phases/phase07.nix
+    ./phases/phase08.nix
+    ./phases/phase09.nix
+    ./phases/phase10.nix
+    ./phases/phase11.nix
+    ./phases/phase12.nix
+
+    ./mescc-tools
+    ./mescc-tools-extra
+    ./kaem
+  ];
+
+  config = {
+    exports = {
+      packages = {
+        stage0-hex0 = cfg.hex0.package;
+
+        stage0-hex1 = cfg.hex1.package;
+
+        stage0-hex2-0 = cfg.hex2-0.package;
+
+        stage0-catm = cfg.catm.package;
+
+        stage0-M0 = cfg.M0.package;
+
+        stage0-cc_arch = cfg.cc_arch.package;
+
+        stage0-M2 = cfg.M2.package;
+
+        stage0-blood-elf = cfg.blood-elf.package;
+
+        stage0-M1-0 = cfg.M1-0.package;
+
+        stage0-hex2-1 = cfg.hex2-1.package;
+
+        stage0-M1 = cfg.M1.package;
+
+        stage0-hex2 = cfg.hex2.package;
+
+        stage0-kaem-unwrapped = cfg.kaem-unwrapped.package;
+
+        stage0-mescc-tools = cfg.mescc-tools.package;
+
+        stage0-mescc-tools-extra = cfg.mescc-tools-extra.package;
+
+        stage0-kaem = cfg.kaem.package;
+      };
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/kaem/build.kaem b/foundation/src/stages/stage0/kaem/build.kaem
new file mode 100644
index 0000000..164854f
--- /dev/null
+++ b/foundation/src/stages/stage0/kaem/build.kaem
@@ -0,0 +1,3 @@
+mkdir -p ${out}/bin
+cp ${kaemUnwrapped} ${out}/bin/kaem
+chmod 555 ${out}/bin/kaem
diff --git a/foundation/src/stages/stage0/kaem/default.nix b/foundation/src/stages/stage0/kaem/default.nix
new file mode 100644
index 0000000..4947847
--- /dev/null
+++ b/foundation/src/stages/stage0/kaem/default.nix
@@ -0,0 +1,77 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.kaem;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1 = config.aux.foundation.stages.stage0.M1;
+  hex2 = config.aux.foundation.stages.stage0.hex2;
+  kaem-unwrapped = config.aux.foundation.stages.stage0.kaem-unwrapped;
+  mescc-tools = config.aux.foundation.stages.stage0.mescc-tools;
+  mescc-tools-extra = config.aux.foundation.stages.stage0.mescc-tools-extra;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.kaem = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for kaem.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Minimal build tool for running scripts on systems that lack any shell.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.kaem = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "kaem";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = kaem-unwrapped.package;
+
+        args = [
+          "--verbose"
+          "--strict"
+          "--file"
+          ./build.kaem
+        ];
+
+        kaemUnwrapped = kaem-unwrapped.package;
+        PATH = lib.paths.bin [mescc-tools-extra.package];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/mescc-tools-extra/build.kaem b/foundation/src/stages/stage0/mescc-tools-extra/build.kaem
new file mode 100644
index 0000000..1fe3042
--- /dev/null
+++ b/foundation/src/stages/stage0/mescc-tools-extra/build.kaem
@@ -0,0 +1,40 @@
+# This is a modified version of mescc-tools-extra/mescc-tools-extra.kaem
+# https://github.com/oriansj/mescc-tools-extra/blob/ec53af69d6d2119b47b369cd0ec37ac806e7ad60/mescc-tools-extra.kaem
+# - Paths to build inputs have been changed for nix
+# - Added additional step to create $out directory
+
+## Copyright (C) 2017 Jeremiah Orians
+## This file is part of mescc-tools.
+##
+## mescc-tools is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## mescc-tools is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with mescc-tools.  If not, see <http://www.gnu.org/licenses/>.
+
+alias CC="${mesccTools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f"
+cd ${src}
+
+# Create output folder
+CC mkdir.c -o ${TMP}/mkdir
+${TMP}/mkdir -p ${out}/bin
+
+CC sha256sum.c -o ${out}/bin/sha256sum
+CC match.c -o ${out}/bin/match
+CC mkdir.c -o ${out}/bin/mkdir
+CC untar.c -o ${out}/bin/untar
+CC ungz.c -o ${out}/bin/ungz
+CC unbz2.c -o ${out}/bin/unbz2
+CC catm.c -o ${out}/bin/catm
+CC cp.c -o ${out}/bin/cp
+CC chmod.c -o ${out}/bin/chmod
+CC rm.c -o ${out}/bin/rm
+CC replace.c -o ${out}/bin/replace
+
diff --git a/foundation/src/stages/stage0/mescc-tools-extra/default.nix b/foundation/src/stages/stage0/mescc-tools-extra/default.nix
new file mode 100644
index 0000000..337524c
--- /dev/null
+++ b/foundation/src/stages/stage0/mescc-tools-extra/default.nix
@@ -0,0 +1,79 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.mescc-tools-extra;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1 = config.aux.foundation.stages.stage0.M1;
+  hex2 = config.aux.foundation.stages.stage0.hex2;
+  kaem-unwrapped = config.aux.foundation.stages.stage0.kaem-unwrapped;
+  mescc-tools = config.aux.foundation.stages.stage0.mescc-tools;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.mescc-tools-extra = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for mescc-tools-extra.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.mescc-tools-extra = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "mescc-tools-tools";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = kaem-unwrapped.package;
+
+        args = [
+          "--verbose"
+          "--strict"
+          "--file"
+          ./build.kaem
+        ];
+
+        src = hex0.mescc-tools-extra.src;
+
+        m2libcOS = "linux";
+        m2libcArch = hex0.m2libc.architecture;
+        mesccTools = mescc-tools.package;
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/mescc-tools/build.kaem b/foundation/src/stages/stage0/mescc-tools/build.kaem
new file mode 100644
index 0000000..0db41f4
--- /dev/null
+++ b/foundation/src/stages/stage0/mescc-tools/build.kaem
@@ -0,0 +1,205 @@
+# This is a modified version of stage0-posix/x86/mescc-tools-full-kaem.kaem
+# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-full-kaem.kaem
+# - Paths to build inputs have been changed for nix
+
+# Mes --- Maxwell Equations of Software
+# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
+# Copyright © 2017,2019 Jeremiah Orians
+#
+# This file is part of Mes.
+#
+# Mes is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# Mes is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Mes.  If not, see <http://www.gnu.org/licenses/>.
+
+${mkdir} -p ${out}/bin
+${cp} ${M2} ${out}/bin/M2
+${chmod} 0555 ${out}/bin/M2
+${cp} ${M1} ${out}/bin/M1
+${chmod} 0555 ${out}/bin/M1
+${cp} ${hex2} ${out}/bin/hex2
+${chmod} 0555 ${out}/bin/hex2
+
+# M2-Mesoplanet searches for runtime dependencies in environment variables
+# We can hardcode them with the "replace" utility from mescc-tools-extra
+${replace} \
+	--file ${m2mesoplanet}/cc.c \
+	--output ./cc_patched.c \
+	--match-on "env_lookup(\"M2LIBC_PATH\")" \
+	--replace-with "\"${m2libc}\""
+${replace} \
+	--file ${m2mesoplanet}/cc_spawn.c \
+	--output ./cc_spawn_patched.c \
+	--match-on "env_lookup(\"PATH\")" \
+	--replace-with "\"${out}/bin:\""
+
+###############################################
+# Phase-12 Build M2-Mesoplanet from M2-Planet #
+###############################################
+
+${M2} --architecture ${m2libcArch} \
+  -f ${m2libc}/sys/types.h \
+  -f ${m2libc}/stddef.h \
+  -f ${m2libc}/${m2libcArch}/linux/fcntl.c \
+  -f ${m2libc}/fcntl.c \
+  -f ${m2libc}/${m2libcArch}/linux/unistd.c \
+  -f ${m2libc}/${m2libcArch}/linux/sys/stat.c \
+  -f ${m2libc}/stdlib.c \
+  -f ${m2libc}/stdio.h \
+  -f ${m2libc}/stdio.c \
+  -f ${m2libc}/string.c \
+  -f ${m2libc}/bootstrappable.c \
+  -f ${m2mesoplanet}/cc.h \
+  -f ${m2mesoplanet}/cc_globals.c \
+  -f ${m2mesoplanet}/cc_env.c \
+  -f ${m2mesoplanet}/cc_reader.c \
+  -f ./cc_spawn_patched.c \
+  -f ${m2mesoplanet}/cc_core.c \
+  -f ${m2mesoplanet}/cc_macro.c \
+  -f ./cc_patched.c \
+  --debug \
+  -o ./M2-Mesoplanet-1.M1
+
+${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1
+
+${M1} --architecture ${m2libcArch} \
+  ${endianFlag} \
+  -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
+  -f ${m2libc}/${m2libcArch}/libc-full.M1 \
+  -f ./M2-Mesoplanet-1.M1 \
+  -f ./M2-Mesoplanet-1-footer.M1 \
+  -o ./M2-Mesoplanet-1.hex2
+
+${hex2} --architecture ${m2libcArch} \
+  ${endianFlag} \
+  --base-address ${baseAddress} \
+  -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
+  -f ./M2-Mesoplanet-1.hex2 \
+  -o ${out}/bin/M2-Mesoplanet
+
+#################################################
+# Phase-13 Build final blood-elf from C sources #
+#################################################
+
+${M2} --architecture ${m2libcArch} \
+	-f ${m2libc}/sys/types.h \
+	-f ${m2libc}/stddef.h \
+	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
+	-f ${m2libc}/fcntl.c \
+	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
+	-f ${m2libc}/stdlib.c \
+	-f ${m2libc}/stdio.h \
+	-f ${m2libc}/stdio.c \
+	-f ${m2libc}/bootstrappable.c \
+	-f ${mesccTools}/stringify.c \
+	-f ${mesccTools}/blood-elf.c \
+	--debug \
+	-o ./blood-elf-1.M1
+
+${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1
+
+${M1} --architecture ${m2libcArch} \
+	${endianFlag} \
+	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
+	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
+	-f ./blood-elf-1.M1 \
+	-f ./blood-elf-1-footer.M1 \
+	-o ./blood-elf-1.hex2
+
+${hex2} --architecture ${m2libcArch} \
+	${endianFlag} \
+	--base-address ${baseAddress} \
+	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
+	-f ./blood-elf-1.hex2 \
+	-o ${out}/bin/blood-elf
+
+# Now we have our shipping debuggable blood-elf, the rest will be down hill from
+# here as we have ALL of the core pieces of compiling and assembling debuggable
+# programs in a debuggable form with corresponding C source code.
+
+#############################################
+# Phase-14 Build get_machine from C sources #
+#############################################
+
+${M2} --architecture ${m2libcArch} \
+	-f ${m2libc}/sys/types.h \
+	-f ${m2libc}/stddef.h \
+	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
+	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
+	-f ${m2libc}/fcntl.c \
+	-f ${m2libc}/stdlib.c \
+	-f ${m2libc}/stdio.h \
+	-f ${m2libc}/stdio.c \
+	-f ${m2libc}/bootstrappable.c \
+	-f ${mesccTools}/get_machine.c \
+	--debug \
+	-o get_machine.M1
+
+${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1
+
+${M1} --architecture ${m2libcArch} \
+	${endianFlag} \
+	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
+	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
+	-f ./get_machine.M1 \
+	-f ./get_machine-footer.M1 \
+	-o ./get_machine.hex2
+
+${hex2} --architecture ${m2libcArch} \
+	${endianFlag} \
+	--base-address ${baseAddress} \
+	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
+	-f ./get_machine.hex2 \
+	-o ${out}/bin/get_machine
+
+############################################
+# Phase-15 Build M2-Planet from M2-Planet  #
+############################################
+
+${M2} --architecture ${m2libcArch} \
+	-f ${m2libc}/sys/types.h \
+	-f ${m2libc}/stddef.h \
+	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
+	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
+	-f ${m2libc}/fcntl.c \
+	-f ${m2libc}/stdlib.c \
+	-f ${m2libc}/stdio.h \
+	-f ${m2libc}/stdio.c \
+	-f ${m2libc}/bootstrappable.c \
+	-f ${m2planet}/cc.h \
+	-f ${m2planet}/cc_globals.c \
+	-f ${m2planet}/cc_reader.c \
+	-f ${m2planet}/cc_strings.c \
+	-f ${m2planet}/cc_types.c \
+	-f ${m2planet}/cc_core.c \
+	-f ${m2planet}/cc_macro.c \
+	-f ${m2planet}/cc.c \
+	--debug \
+	-o ./M2-1.M1
+
+${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1
+
+${M1} --architecture ${m2libcArch} \
+	${endianFlag} \
+	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
+	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
+	-f ./M2-1.M1 \
+	-f ./M2-1-footer.M1 \
+	-o ./M2-1.hex2
+
+${hex2} --architecture ${m2libcArch} \
+	${endianFlag} \
+	--base-address ${baseAddress} \
+	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
+	-f ./M2-1.hex2 \
+	-o ${out}/bin/M2-Planet
+
diff --git a/foundation/src/stages/stage0/mescc-tools/default.nix b/foundation/src/stages/stage0/mescc-tools/default.nix
new file mode 100644
index 0000000..ba7e56e
--- /dev/null
+++ b/foundation/src/stages/stage0/mescc-tools/default.nix
@@ -0,0 +1,178 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.mescc-tools;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1 = config.aux.foundation.stages.stage0.M1;
+  hex2 = config.aux.foundation.stages.stage0.hex2;
+  kaem-unwrapped = config.aux.foundation.stages.stage0.kaem-unwrapped;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+
+  bloodFlag =
+    if config.aux.platform.bits == 64
+    then "--64"
+    else " ";
+  endianFlag =
+    if config.aux.platform.endian == "little"
+    then "--little-endian"
+    else "--big-endian";
+  baseAddress =
+    if config.aux.system == "x86_64-linux"
+    then "0x00600000"
+    else if config.aux.system == "aarch64-linux"
+    then "0x00600000"
+    else if config.aux.system == "i686-linux"
+    then "0x08048000"
+    else builtins.throw "Unsupported system: ${config.aux.system}";
+
+  getExtraUtil = name: let
+    script = builtins.toFile "build-${name}.kaem" ''
+        ''${M2} --architecture ${hex0.m2libc.architecture} \
+        -f ''${m2libc}/sys/types.h \
+        -f ''${m2libc}/stddef.h \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/linux/fcntl.c \
+        -f ''${m2libc}/fcntl.c \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/linux/unistd.c \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/linux/sys/stat.c \
+        -f ''${m2libc}/stdlib.c \
+        -f ''${m2libc}/stdio.h \
+        -f ''${m2libc}/stdio.c \
+        -f ''${m2libc}/string.c \
+        -f ''${m2libc}/bootstrappable.c \
+        -f ''${mesccToolsExtra}/${name}.c \
+        --debug \
+        -o ${name}.M1
+
+      ''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1
+
+      ''${M1} --architecture ${hex0.m2libc.architecture} \
+        ${endianFlag} \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1 \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/libc-full.M1 \
+        -f ${name}.M1 \
+        -f ${name}-footer.M1 \
+        -o ${name}.hex2
+
+      ''${hex2} --architecture ${hex0.m2libc.architecture} \
+        ${endianFlag} \
+        -f ''${m2libc}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2 \
+        -f ${name}.hex2 \
+        --base-address ${baseAddress} \
+        -o ''${out}
+
+    '';
+  in
+    builders.raw.build {
+      pname = "mescc-tools-extra-${name}";
+      version = "1.6.0";
+
+      meta = cfg.meta;
+
+      executable = kaem-unwrapped.package;
+
+      args = [
+        "--verbose"
+        "--strict"
+        "--file"
+        script
+      ];
+
+      src = hex0.src;
+      M1 = M1.package;
+      M2 = M2.package;
+      blood-elf-0 = blood-elf.package;
+      hex2 = hex2.package;
+      m2libc = hex0.m2libc.src;
+      m2planet = hex0.m2planet.src;
+      m2mesoplanet = hex0.m2mesoplanet.src;
+      mesccTools = hex0.mescc-tools.src;
+      mesccToolsExtra = hex0.mescc-tools-extra.src;
+
+      bloodFlag = bloodFlag;
+      endianFlag = endianFlag;
+      baseAddress = baseAddress;
+    };
+in {
+  options.aux.foundation.stages.stage0.mescc-tools = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for mescc-tools.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.mescc-tools = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "mescc-tools";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = kaem-unwrapped.package;
+
+        args = [
+          "--verbose"
+          "--strict"
+          "--file"
+          ./build.kaem
+        ];
+
+        M1 = M1.package;
+        M2 = M2.package;
+        blood-elf-0 = blood-elf.package;
+        hex2 = hex2.package;
+
+        m2libc = hex0.m2libc.src;
+        m2libcArch = hex0.m2libc.architecture;
+        m2planet = hex0.m2planet.src;
+        m2mesoplanet = hex0.m2mesoplanet.src;
+        mesccTools = hex0.mescc-tools.src;
+        mesccToolsExtra = hex0.mescc-tools-extra.src;
+
+        bloodFlag = bloodFlag;
+        endianFlag = endianFlag;
+        baseAddress = baseAddress;
+
+        mkdir = getExtraUtil "mkdir";
+        cp = getExtraUtil "cp";
+        chmod = getExtraUtil "chmod";
+        replace = getExtraUtil "replace";
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase00.nix b/foundation/src/stages/stage0/phases/phase00.nix
new file mode 100644
index 0000000..a778220
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase00.nix
@@ -0,0 +1,223 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.hex0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+
+  architecture =
+    if system == "x86_64-linux"
+    then "AMD64"
+    else if system == "aarch64-linux"
+    then "AArch64"
+    else if system == "i686-linux"
+    then "x86"
+    else builtins.throw "Unsupported system for stage0: ${system}";
+in {
+  options.aux.foundation.stages.stage0.hex0 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for hex0.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Minimal assembler for bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+
+    hash = lib.options.create {
+      type = lib.types.nullish lib.types.string;
+      default = {
+        text = "<sha256 hash>";
+        value = null;
+      };
+    };
+
+    executable = lib.options.create {
+      type = lib.types.package;
+      description = "The derivation to use to build hex0.";
+    };
+
+    src = lib.options.create {
+      type = lib.types.string;
+      description = "The source for the hex0 build files.";
+    };
+
+    m2libc = {
+      src = lib.options.create {
+        type = lib.types.string;
+        description = "The source for the M2libc build files.";
+      };
+
+      architecture = lib.options.create {
+        type = lib.types.string;
+        description = "The architecture to use for the M2libc source.";
+        default = {
+          value = lib.strings.lower architecture;
+          text = ''"amd64" or "aarch64" or "x86"'';
+        };
+      };
+    };
+
+    m2planet = {
+      src = lib.options.create {
+        type = lib.types.string;
+        description = "The source for the M2-Planet build files.";
+      };
+    };
+
+    m2mesoplanet = {
+      src = lib.options.create {
+        type = lib.types.string;
+        description = "The source for the M2-MesoPlanet build files.";
+      };
+    };
+
+    mescc-tools = {
+      src = lib.options.create {
+        type = lib.types.string;
+        description = "The source for the mescc-tools build files.";
+      };
+    };
+
+    mescc-tools-extra = {
+      src = lib.options.create {
+        type = lib.types.string;
+        description = "The source for the mescc-tools-extra build files.";
+      };
+    };
+
+    architecture = lib.options.create {
+      type = lib.types.string;
+      description = "The architecture to use for the source.";
+      default = {
+        value = architecture;
+        text = ''"AMD64" or "AArch64" or "x86"'';
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.hex0 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "hex0";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = cfg.executable;
+
+        args = [
+          "${cfg.src}/hex0_${architecture}.hex0"
+          (builtins.placeholder "out")
+        ];
+
+        outputHashMode = "recursive";
+        outputHashAlgo = "sha256";
+        outputHash = cfg.hash;
+      });
+
+      hash = lib.modules.overrides.default (
+        if system == "x86_64-linux"
+        then "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo="
+        else if system == "aarch64-linux"
+        then "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="
+        else if system == "i686-linux"
+        then "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="
+        else null
+      );
+
+      executable = lib.modules.overrides.default (import <nix/fetchurl.nix> {
+        name = "hex0-seed";
+        url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${architecture}/hex0-seed";
+        executable = true;
+        hash = cfg.hash;
+      });
+
+      # All sources are combined a central repository via submodules. Due to potential quirks surrounding
+      # fetching that, we are instead fetching each submodule directly. The central repository is located
+      # here: https://github.com/oriansj/stage0-posix
+      src =
+        if architecture == "AMD64"
+        then
+          builtins.fetchTarball {
+            url = "https://github.com/oriansj/stage0-posix-amd64/archive/93fbe4c08772d8df1412e2554668e24cf604088c.tar.gz";
+            sha256 = "10d1xnjzqplpfip3pm89bydd501x1bcgkg7lkkadyq5bqpad5flp";
+          }
+        else if architecture == "AArch64"
+        then
+          # FIXME: We may need to patch the aarch64 variant.
+          # https://github.com/oriansj/M2libc/pull/17
+          builtins.fetchTarball {
+            url = "https://github.com/oriansj/stage0-posix-aarch64/archive/39a43f803d572b53f95d42507202152eeda18361.tar.gz";
+            sha256 = "1x607hr3n5j89394d156r23igpx8hifjd14ygksx7902rlwrrry2";
+          }
+        else if architecture == "x86"
+        then
+          builtins.fetchTarball {
+            url = "https://github.com/oriansj/stage0-posix-x86/archive/e86bf7d304bae5ce5ccc88454bb60cf0837e941f.tar.gz";
+            sha256 = "1c1fk793yzq8zbg60n2zd22fsmirc3zr26fj0iskap456g84nxv8";
+          }
+        else builtins.throw "Unsupported architecture for stage0: ${architecture}";
+
+      m2libc = {
+        src = builtins.fetchTarball {
+          url = "https://github.com/oriansj/M2libc/archive/de7c75f144176c3b9be77695d9bf94440445aeae.tar.gz";
+          sha256 = "01k81zn8yx4jg6fbcjgkrf9rp074yikkmwqykdgi9143yfb2k3yv";
+        };
+      };
+
+      m2planet = {
+        src = builtins.fetchTarball {
+          url = "https://github.com/oriansj/M2-Planet/archive/51dc63b349ca13fa57b345964254cf26930c0a7d.tar.gz";
+          sha256 = "1kksk260dh6qd0dzgl9vgs67fs0lsxs9w0gniy0ii5fgmqxi8p65";
+        };
+      };
+
+      m2mesoplanet = {
+        src = builtins.fetchTarball {
+          url = "https://github.com/oriansj/M2-Mesoplanet/archive/c80645f06b035debaa08e95da3206346a9f61b97.tar.gz";
+          sha256 = "02vzqln38ylfnd88p87935yf26i60gkbv93ns5j7parqgyyz2kl4";
+        };
+      };
+
+      mescc-tools = {
+        src = builtins.fetchTarball {
+          url = "https://github.com/oriansj/mescc-tools/archive/5d37991e22d1e4147411a766f4410508ba872962.tar.gz";
+          sha256 = "1xgpqhc5diim3rr9a00939976svrbhfp4v5970548a137fdynl4c";
+        };
+      };
+
+      mescc-tools-extra = {
+        src = builtins.fetchTarball {
+          url = "https://github.com/oriansj/mescc-tools-extra/archive/c1bd4ab4c5b994d8167c1e6dfc14050dc151a911.tar.gz";
+          sha256 = "0v8vxn3a8rxbgi6vcw73jqkw9j5vg3qlvd4sxk2w0fpybjml8brd";
+        };
+      };
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase01.nix b/foundation/src/stages/stage0/phases/phase01.nix
new file mode 100644
index 0000000..355989c
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase01.nix
@@ -0,0 +1,62 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.hex1;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.hex1 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for hex0.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.hex1 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "hex1";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex0.package;
+
+        args = [
+          "${hex0.src}/hex1_${hex0.architecture}.hex0"
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase02.nix b/foundation/src/stages/stage0/phases/phase02.nix
new file mode 100644
index 0000000..ab2606c
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase02.nix
@@ -0,0 +1,63 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.hex2-0;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex1 = config.aux.foundation.stages.stage0.hex1;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.hex2-0 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for hex2-0.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.hex2-0 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "hex2-0";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex1.package;
+
+        args = [
+          "${hex0.src}/hex2_${hex0.architecture}.hex1"
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase03.nix b/foundation/src/stages/stage0/phases/phase03.nix
new file mode 100644
index 0000000..156e5cf
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase03.nix
@@ -0,0 +1,73 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.catm;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex1 = config.aux.foundation.stages.stage0.hex1;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.catm = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for catm.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.catm = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "catm";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable =
+          if hex0.architecture == "AArch64"
+          then hex1.package
+          else hex2-0.package;
+
+        args =
+          if hex0.architecture == "AArch64"
+          then [
+            "${hex0.src}/catm_${hex0.architecture}.hex1"
+            (builtins.placeholder "out")
+          ]
+          else [
+            "${hex0.src}/catm_${hex0.architecture}.hex2"
+            (builtins.placeholder "out")
+          ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase04.nix b/foundation/src/stages/stage0/phases/phase04.nix
new file mode 100644
index 0000000..57808fa
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase04.nix
@@ -0,0 +1,79 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.M0;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.M0 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for M0.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.M0 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "M0";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          M0_hex2-0 = builders.raw.build {
+            pname = "M0_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
+              "${hex0.src}/M0_${hex0.architecture}.hex2"
+            ];
+          };
+        in [
+          M0_hex2-0
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase05.nix b/foundation/src/stages/stage0/phases/phase05.nix
new file mode 100644
index 0000000..3c11dbe
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase05.nix
@@ -0,0 +1,93 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.cc_arch;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.cc_arch = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for cc_arch.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.cc_arch = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "cc_arch";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          cc_arch0_hex2-0 = builders.raw.build {
+            pname = "cc_arch0_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M0.package;
+
+            args = [
+              "${hex0.src}/cc_${hex0.m2libc.architecture}.M1"
+              (builtins.placeholder "out")
+            ];
+          };
+          cc_arch1_hex2-0 = builders.raw.build {
+            pname = "cc_arch1_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
+              cc_arch0_hex2-0
+            ];
+          };
+        in [
+          cc_arch1_hex2-0
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase06.nix b/foundation/src/stages/stage0/phases/phase06.nix
new file mode 100644
index 0000000..728e3e7
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase06.nix
@@ -0,0 +1,144 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.M2;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.M2 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for M2.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.M2 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "M2";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          M2_c = builders.raw.build {
+            pname = "M2_c";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
+              "${hex0.m2planet.src}/cc.h"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "${hex0.m2planet.src}/cc_globals.c"
+              "${hex0.m2planet.src}/cc_reader.c"
+              "${hex0.m2planet.src}/cc_strings.c"
+              "${hex0.m2planet.src}/cc_types.c"
+              "${hex0.m2planet.src}/cc_core.c"
+              "${hex0.m2planet.src}/cc_macro.c"
+              "${hex0.m2planet.src}/cc.c"
+            ];
+          };
+          M2_M1 = builders.raw.build {
+            pname = "M2_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = cc_arch.package;
+
+            args = [
+              M2_c
+              (builtins.placeholder "out")
+            ];
+          };
+          M2_M1' = builders.raw.build {
+            pname = "M2_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
+              M2_M1
+            ];
+          };
+          M2_hex2-0 = builders.raw.build {
+            pname = "M2_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M0.package;
+
+            args = [
+              M2_M1'
+              (builtins.placeholder "out")
+            ];
+          };
+          M2_hex2-0' = builders.raw.build {
+            pname = "M2_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
+              M2_hex2-0
+            ];
+          };
+        in [
+          M2_hex2-0'
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase07.nix b/foundation/src/stages/stage0/phases/phase07.nix
new file mode 100644
index 0000000..ee4e8b0
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase07.nix
@@ -0,0 +1,134 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.blood-elf;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.blood-elf = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for blood-elf.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.blood-elf = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "blood-elf";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          blood-elf_M1 = builders.raw.build {
+            pname = "blood-elf_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/stringify.c"
+              "-f"
+              "${hex0.mescc-tools.src}/blood-elf.c"
+              "--bootstrap-mode"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          blood-elf_M1' = builders.raw.build {
+            pname = "blood-elf_M1-1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
+              blood-elf_M1
+            ];
+          };
+          blood-elf_hex2-0 = builders.raw.build {
+            pname = "blood-elf_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M0.package;
+
+            args = [
+              blood-elf_M1'
+              (builtins.placeholder "out")
+            ];
+          };
+          blood-elf_hex2-0' = builders.raw.build {
+            pname = "blood-elf_hex2-0-1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
+              blood-elf_hex2-0
+            ];
+          };
+        in [
+          blood-elf_hex2-0'
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase08.nix b/foundation/src/stages/stage0/phases/phase08.nix
new file mode 100644
index 0000000..c678c85
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase08.nix
@@ -0,0 +1,159 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.M1-0;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.M1-0 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for M1-0.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.M1-0 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "M1-0";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          M1-macro-0_M1 = builders.raw.build {
+            pname = "M1-macro-0_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/stringify.c"
+              "-f"
+              "${hex0.mescc-tools.src}/M1-macro.c"
+              "--bootstrap-mode"
+              "--debug"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          M1-macro-0-footer_M1 = builders.raw.build {
+            pname = "M1-macro-0-footer_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = blood-elf.package;
+
+            args =
+              (lib.lists.when (config.aux.platform.bits == 64) "--64")
+              ++ [
+                "-f"
+                M1-macro-0_M1
+                (
+                  if config.aux.platform.endian == "little"
+                  then "--little-endian"
+                  else "--big-endian"
+                )
+                "-o"
+                (builtins.placeholder "out")
+              ];
+          };
+          M1-macro-0_M1' = builders.raw.build {
+            pname = "M1-macro-0_M1-1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
+              M1-macro-0_M1
+              M1-macro-0-footer_M1
+            ];
+          };
+          M1-macro-0_hex2-0 = builders.raw.build {
+            pname = "M1-macro-0_hex2-0";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M0.package;
+
+            args = [
+              M1-macro-0_M1'
+              (builtins.placeholder "out")
+            ];
+          };
+          M1-macro-0_hex2-0' = builders.raw.build {
+            pname = "M1-macro-0_hex2-0-1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
+              M1-macro-0_hex2-0
+            ];
+          };
+        in [
+          M1-macro-0_hex2-0'
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase09.nix b/foundation/src/stages/stage0/phases/phase09.nix
new file mode 100644
index 0000000..08dc589
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase09.nix
@@ -0,0 +1,178 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.hex2-1;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1-0 = config.aux.foundation.stages.stage0.M1-0;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.hex2-1 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for hex2-1.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.hex2-1 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "hex2-1";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-0.package;
+
+        args = let
+          hex2_linker_M1 = builders.raw.build {
+            pname = "hex2_linker_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/sys/types.h"
+              "-f"
+              "${hex0.m2libc.src}/stddef.h"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
+              "-f"
+              "${hex0.m2libc.src}/stdlib.c"
+              "-f"
+              "${hex0.m2libc.src}/stdio.h"
+              "-f"
+              "${hex0.m2libc.src}/stdio.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2.h"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2_linker.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2_word.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2.c"
+              "--debug"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          hex2_linker-footer_M1 = builders.raw.build {
+            pname = "hex2_linker-footer_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = blood-elf.package;
+
+            args =
+              (lib.lists.when (config.aux.platform.bits == 64) "--64")
+              ++ [
+                "-f"
+                hex2_linker_M1
+                (
+                  if config.aux.platform.endian == "little"
+                  then "--little-endian"
+                  else "--big-endian"
+                )
+                "-o"
+                (builtins.placeholder "out")
+              ];
+          };
+          hex2_linker_hex2 = builders.raw.build {
+            pname = "hex2_linker_hex2";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M1-0.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
+              "-f"
+              hex2_linker_M1
+              "-f"
+              hex2_linker-footer_M1
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          hex2_linker_hex2' = builders.raw.build {
+            pname = "hex2_linker_hex2-1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = catm.package;
+
+            args = [
+              (builtins.placeholder "out")
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
+              hex2_linker_hex2
+            ];
+          };
+        in [
+          hex2_linker_hex2'
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase10.nix b/foundation/src/stages/stage0/phases/phase10.nix
new file mode 100644
index 0000000..b941865
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase10.nix
@@ -0,0 +1,184 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.M1;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1-0 = config.aux.foundation.stages.stage0.M1-0;
+  hex2-1 = config.aux.foundation.stages.stage0.hex2-1;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.M1 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for M1.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.M1 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "M1";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-1.package;
+
+        args = let
+          M1-macro_M1 = builders.raw.build {
+            pname = "M1-macro_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/sys/types.h"
+              "-f"
+              "${hex0.m2libc.src}/stddef.h"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
+              "-f"
+              "${hex0.m2libc.src}/string.c"
+              "-f"
+              "${hex0.m2libc.src}/stdlib.c"
+              "-f"
+              "${hex0.m2libc.src}/stdio.h"
+              "-f"
+              "${hex0.m2libc.src}/stdio.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/stringify.c"
+              "-f"
+              "${hex0.mescc-tools.src}/M1-macro.c"
+              "--debug"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          M1-macro-footer_M1 = builders.raw.build {
+            pname = "M1-macro-footer_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = blood-elf.package;
+
+            args =
+              (lib.lists.when (config.aux.platform.bits == 64) "--64")
+              ++ [
+                "-f"
+                M1-macro_M1
+                (
+                  if config.aux.platform.endian == "little"
+                  then "--little-endian"
+                  else "--big-endian"
+                )
+                "-o"
+                (builtins.placeholder "out")
+              ];
+          };
+          M1-macro_hex2 = builders.raw.build {
+            pname = "M1-macro_hex2";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M1-0.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
+              "-f"
+              M1-macro_M1
+              "-f"
+              M1-macro-footer_M1
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+        in [
+          "--architecture"
+          hex0.m2libc.architecture
+          (
+            if config.aux.platform.endian == "little"
+            then "--little-endian"
+            else "--big-endian"
+          )
+          "--base-address"
+          (
+            if config.aux.system == "x86_64-linux"
+            then "0x00600000"
+            else if config.aux.system == "aarch64-linux"
+            then "0x00600000"
+            else if config.aux.system == "i686-linux"
+            then "0x08048000"
+            else builtins.throw "Unsupported system: ${config.aux.system}"
+          )
+          "-f"
+          "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
+          "-f"
+          M1-macro_hex2
+          "-o"
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase11.nix b/foundation/src/stages/stage0/phases/phase11.nix
new file mode 100644
index 0000000..68775f5
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase11.nix
@@ -0,0 +1,184 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.hex2;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1 = config.aux.foundation.stages.stage0.M1;
+  hex2-1 = config.aux.foundation.stages.stage0.hex2-1;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.hex2 = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for hex2.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.hex2 = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "hex2";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2-1.package;
+
+        args = let
+          hex2_linker_M1 = builders.raw.build {
+            pname = "hex2_linker_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/sys/types.h"
+              "-f"
+              "${hex0.m2libc.src}/stddef.h"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
+              "-f"
+              "${hex0.m2libc.src}/stdlib.c"
+              "-f"
+              "${hex0.m2libc.src}/stdio.h"
+              "-f"
+              "${hex0.m2libc.src}/stdio.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2.h"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2_linker.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2_word.c"
+              "-f"
+              "${hex0.mescc-tools.src}/hex2.c"
+              "--debug"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          hex2_linker-footer_M1 = builders.raw.build {
+            pname = "hex2_linker-footer_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = blood-elf.package;
+
+            args = [
+              (lib.lists.when (config.aux.platform.bits == 64) "--64")
+              "-f"
+              hex2_linker_M1
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          hex2_linker_hex2 = builders.raw.build {
+            pname = "hex2_linker_hex2";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M1.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
+              "-f"
+              hex2_linker_M1
+              "-f"
+              hex2_linker-footer_M1
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+        in [
+          "--architecture"
+          hex0.m2libc.architecture
+          (
+            if config.aux.platform.endian == "little"
+            then "--little-endian"
+            else "--big-endian"
+          )
+          "--base-address"
+          (
+            if config.aux.system == "x86_64-linux"
+            then "0x00600000"
+            else if config.aux.system == "aarch64-linux"
+            then "0x00600000"
+            else if config.aux.system == "i686-linux"
+            then "0x08048000"
+            else builtins.throw "Unsupported system: ${config.aux.system}"
+          )
+          "-f"
+          "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
+          "-f"
+          hex2_linker_hex2
+          "-o"
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage0/phases/phase12.nix b/foundation/src/stages/stage0/phases/phase12.nix
new file mode 100644
index 0000000..b9d1d5a
--- /dev/null
+++ b/foundation/src/stages/stage0/phases/phase12.nix
@@ -0,0 +1,186 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage0.kaem-unwrapped;
+  hex0 = config.aux.foundation.stages.stage0.hex0;
+  catm = config.aux.foundation.stages.stage0.catm;
+  M0 = config.aux.foundation.stages.stage0.M0;
+  cc_arch = config.aux.foundation.stages.stage0.cc_arch;
+  M2 = config.aux.foundation.stages.stage0.M2;
+  blood-elf = config.aux.foundation.stages.stage0.blood-elf;
+  M1 = config.aux.foundation.stages.stage0.M1;
+  hex2 = config.aux.foundation.stages.stage0.hex2;
+
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  options.aux.foundation.stages.stage0.kaem-unwrapped = {
+    package = lib.options.create {
+      type = lib.types.package;
+      description = "The package to use for kaem-unwrapped.";
+    };
+
+    meta = {
+      description = lib.options.create {
+        type = lib.types.string;
+        description = "Description for the package.";
+        default.value = "Collection of tools for use in bootstrapping.";
+      };
+
+      homepage = lib.options.create {
+        type = lib.types.string;
+        description = "Homepage for the package.";
+        default.value = "https://github.com/oriansj/stage0-posix";
+      };
+
+      license = lib.options.create {
+        # TODO: Add a proper type for licenses.
+        type = lib.types.attrs.any;
+        description = "License for the package.";
+        default.value = lib.licenses.gpl3Plus;
+      };
+
+      platforms = lib.options.create {
+        type = lib.types.list.of lib.types.string;
+        description = "Platforms the package supports.";
+        default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
+      };
+    };
+  };
+
+  config = {
+    aux.foundation.stages.stage0.kaem-unwrapped = {
+      package = lib.modules.overrides.default (builders.raw.build {
+        pname = "kaem-unwrapped";
+        version = "1.6.0";
+
+        meta = cfg.meta;
+
+        executable = hex2.package;
+
+        args = let
+          kaem_M1 = builders.raw.build {
+            pname = "kaem_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M2.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              "-f"
+              "${hex0.m2libc.src}/sys/types.h"
+              "-f"
+              "${hex0.m2libc.src}/stddef.h"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/fcntl.c"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
+              "-f"
+              "${hex0.m2libc.src}/string.c"
+              "-f"
+              "${hex0.m2libc.src}/stdlib.c"
+              "-f"
+              "${hex0.m2libc.src}/stdio.h"
+              "-f"
+              "${hex0.m2libc.src}/stdio.c"
+              "-f"
+              "${hex0.m2libc.src}/bootstrappable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/Kaem/kaem.h"
+              "-f"
+              "${hex0.mescc-tools.src}/Kaem/variable.c"
+              "-f"
+              "${hex0.mescc-tools.src}/Kaem/kaem_globals.c"
+              "-f"
+              "${hex0.mescc-tools.src}/Kaem/kaem.c"
+              "--debug"
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          kaem-footer_M1 = builders.raw.build {
+            pname = "kaem-footer_M1";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = blood-elf.package;
+
+            args = [
+              (lib.lists.when (config.aux.platform.bits == 64) "--64")
+              "-f"
+              kaem_M1
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+          kaem_hex2 = builders.raw.build {
+            pname = "kaem_hex2";
+            version = "1.6.0";
+
+            meta = cfg.meta;
+
+            executable = M1.package;
+
+            args = [
+              "--architecture"
+              hex0.m2libc.architecture
+              (
+                if config.aux.platform.endian == "little"
+                then "--little-endian"
+                else "--big-endian"
+              )
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
+              "-f"
+              "${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
+              "-f"
+              kaem_M1
+              "-f"
+              kaem-footer_M1
+              "-o"
+              (builtins.placeholder "out")
+            ];
+          };
+        in [
+          "--architecture"
+          hex0.m2libc.architecture
+          (
+            if config.aux.platform.endian == "little"
+            then "--little-endian"
+            else "--big-endian"
+          )
+          "--base-address"
+          (
+            if config.aux.system == "x86_64-linux"
+            then "0x00600000"
+            else if config.aux.system == "aarch64-linux"
+            then "0x00600000"
+            else if config.aux.system == "i686-linux"
+            then "0x08048000"
+            else builtins.throw "Unsupported system: ${config.aux.system}"
+          )
+          "-f"
+          "${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
+          "-f"
+          kaem_hex2
+          "-o"
+          (builtins.placeholder "out")
+        ];
+      });
+    };
+  };
+}
diff --git a/foundation/src/stages/stage1/default.nix b/foundation/src/stages/stage1/default.nix
new file mode 100644
index 0000000..7c18f8e
--- /dev/null
+++ b/foundation/src/stages/stage1/default.nix
@@ -0,0 +1,17 @@
+{
+  lib,
+  config,
+}: let
+  cfg = config.aux.foundation.stages.stage1;
+in {
+  includes = [
+    ./mes
+  ];
+
+  config = {
+    exports = {
+      packages = {
+      };
+    };
+  };
+}
diff --git a/foundation/src/stages/stage1/mes/default.nix b/foundation/src/stages/stage1/mes/default.nix
new file mode 100644
index 0000000..7baaee0
--- /dev/null
+++ b/foundation/src/stages/stage1/mes/default.nix
@@ -0,0 +1,12 @@
+{
+  lib,
+  config,
+}: let
+  system = config.aux.system;
+  builders = config.aux.foundation.builders;
+in {
+  config = {
+    aux.foundation.stages.stage0.mes = {
+    };
+  };
+}
diff --git a/foundation/src/system/default.nix b/foundation/src/system/default.nix
new file mode 100644
index 0000000..388366d
--- /dev/null
+++ b/foundation/src/system/default.nix
@@ -0,0 +1,11 @@
+{lib}: {
+  options.aux = {
+    system = lib.options.create {
+      type = lib.types.string;
+      description = ''
+        The system to build packages for. This value can be provided as either
+        `config.aux.system` or by setting the `system` argument for modules.
+      '';
+    };
+  };
+}
diff --git a/lib/flake.nix b/lib/flake.nix
index 8501377..bf835a3 100644
--- a/lib/flake.nix
+++ b/lib/flake.nix
@@ -1,5 +1,5 @@
 {
-  description = "A very basic flake";
+  description = "A NixPkgs library replacement containing helper functions and a module system.";
 
   outputs = _: {
     lib = import ./src;
diff --git a/lib/src/attrs/default.nix b/lib/src/attrs/default.nix
index 4d47802..e3ed4dd 100644
--- a/lib/src/attrs/default.nix
+++ b/lib/src/attrs/default.nix
@@ -144,5 +144,19 @@ lib: {
       valid = builtins.concatMap process names;
     in
       builtins.listToAttrs valid;
+
+    ## Generate an attribute set from a list of names and a function that is
+    ## applied to each name.
+    ##
+    ## @type (List String) -> (String -> Any) -> Attrs
+    generate = names: f: let
+      pairs =
+        builtins.map (name: {
+          inherit name;
+          value = f name;
+        })
+        names;
+    in
+      builtins.listToAttrs pairs;
   };
 }
diff --git a/lib/src/default.nix b/lib/src/default.nix
index 33eb8e4..c3ea1db 100644
--- a/lib/src/default.nix
+++ b/lib/src/default.nix
@@ -6,6 +6,7 @@ let
     ./fp
     ./generators
     ./importers
+    ./licenses
     ./lists
     ./math
     ./modules
diff --git a/lib/src/licenses/all.nix b/lib/src/licenses/all.nix
new file mode 100644
index 0000000..7fec5b0
--- /dev/null
+++ b/lib/src/licenses/all.nix
@@ -0,0 +1,1270 @@
+{
+  abstyles = {
+    spdxId = "Abstyles";
+    fullName = "Abstyles License";
+  };
+
+  acsl14 = {
+    fullName = "Anti-Capitalist Software License v1.4";
+    url = "https://anticapitalist.software/";
+    /*
+    restrictions on corporations apply for both use and redistribution
+    */
+    free = false;
+    redistributable = false;
+  };
+
+  activision = {
+    # https://doomwiki.org/wiki/Raven_source_code_licensing
+    fullName = "Activision EULA";
+    url = "https://www.doomworld.com/eternity/activision_eula.txt";
+    free = false;
+  };
+
+  afl20 = {
+    spdxId = "AFL-2.0";
+    fullName = "Academic Free License v2.0";
+  };
+
+  afl21 = {
+    spdxId = "AFL-2.1";
+    fullName = "Academic Free License v2.1";
+  };
+
+  afl3 = {
+    spdxId = "AFL-3.0";
+    fullName = "Academic Free License v3.0";
+  };
+
+  agpl3Only = {
+    spdxId = "AGPL-3.0-only";
+    fullName = "GNU Affero General Public License v3.0 only";
+  };
+
+  agpl3Plus = {
+    spdxId = "AGPL-3.0-or-later";
+    fullName = "GNU Affero General Public License v3.0 or later";
+  };
+
+  aladdin = {
+    spdxId = "Aladdin";
+    fullName = "Aladdin Free Public License";
+    free = false;
+  };
+
+  amazonsl = {
+    fullName = "Amazon Software License";
+    url = "https://aws.amazon.com/asl/";
+    free = false;
+  };
+
+  amd = {
+    fullName = "AMD License Agreement";
+    url = "https://developer.amd.com/amd-license-agreement/";
+    free = false;
+  };
+
+  aom = {
+    fullName = "Alliance for Open Media Patent License 1.0";
+    url = "https://aomedia.org/license/patent-license/";
+  };
+
+  apple-psl10 = {
+    spdxId = "APSL-1.0";
+    fullName = "Apple Public Source License 1.0";
+  };
+
+  apple-psl20 = {
+    spdxId = "APSL-2.0";
+    fullName = "Apple Public Source License 2.0";
+  };
+
+  arphicpl = {
+    spdxId = "Arphic-1999";
+    fullName = "Arphic Public License";
+    url = "https://www.freedesktop.org/wiki/Arphic_Public_License/";
+  };
+
+  artistic1 = {
+    spdxId = "Artistic-1.0";
+    fullName = "Artistic License 1.0";
+  };
+
+  artistic1-cl8 = {
+    spdxId = "Artistic-1.0-cl8";
+    fullName = "Artistic License 1.0 w/clause 8";
+  };
+
+  artistic2 = {
+    spdxId = "Artistic-2.0";
+    fullName = "Artistic License 2.0";
+  };
+
+  asl20 = {
+    spdxId = "Apache-2.0";
+    fullName = "Apache License 2.0";
+  };
+
+  asl20-llvm = {
+    spdxId = "Apache-2.0 WITH LLVM-exception";
+    fullName = "Apache License 2.0 with LLVM Exceptions";
+  };
+
+  bitstreamVera = {
+    spdxId = "Bitstream-Vera";
+    fullName = "Bitstream Vera Font License";
+  };
+
+  bitTorrent10 = {
+    spdxId = "BitTorrent-1.0";
+    fullName = " BitTorrent Open Source License v1.0";
+  };
+
+  bitTorrent11 = {
+    spdxId = "BitTorrent-1.1";
+    fullName = " BitTorrent Open Source License v1.1";
+  };
+
+  bola11 = {
+    url = "https://blitiri.com.ar/p/bola/";
+    fullName = "Buena Onda License Agreement 1.1";
+  };
+
+  boost = {
+    spdxId = "BSL-1.0";
+    fullName = "Boost Software License 1.0";
+  };
+
+  beerware = {
+    spdxId = "Beerware";
+    fullName = "Beerware License";
+  };
+
+  blueOak100 = {
+    spdxId = "BlueOak-1.0.0";
+    fullName = "Blue Oak Model License 1.0.0";
+  };
+
+  bsd0 = {
+    spdxId = "0BSD";
+    fullName = "BSD Zero Clause License";
+  };
+
+  bsd1 = {
+    spdxId = "BSD-1-Clause";
+    fullName = "BSD 1-Clause License";
+  };
+
+  bsd2 = {
+    spdxId = "BSD-2-Clause";
+    fullName = ''BSD 2-clause "Simplified" License'';
+  };
+
+  bsd2Patent = {
+    spdxId = "BSD-2-Clause-Patent";
+    fullName = "BSD-2-Clause Plus Patent License";
+  };
+
+  bsd2WithViews = {
+    spdxId = "BSD-2-Clause-Views";
+    fullName = "BSD 2-Clause with views sentence";
+  };
+
+  bsd3 = {
+    spdxId = "BSD-3-Clause";
+    fullName = ''BSD 3-clause "New" or "Revised" License'';
+  };
+
+  bsd3Clear = {
+    spdxId = "BSD-3-Clause-Clear";
+    fullName = "BSD 3-Clause Clear License";
+  };
+
+  bsdOriginal = {
+    spdxId = "BSD-4-Clause";
+    fullName = ''BSD 4-clause "Original" or "Old" License'';
+  };
+
+  bsdOriginalShortened = {
+    spdxId = "BSD-4-Clause-Shortened";
+    fullName = "BSD 4 Clause Shortened";
+  };
+
+  bsdOriginalUC = {
+    spdxId = "BSD-4-Clause-UC";
+    fullName = "BSD 4-Clause University of California-Specific";
+  };
+
+  bsdProtection = {
+    spdxId = "BSD-Protection";
+    fullName = "BSD Protection License";
+  };
+
+  bsl11 = {
+    fullName = "Business Source License 1.1";
+    url = "https://mariadb.com/bsl11";
+    free = false;
+    redistributable = true;
+  };
+
+  caossl = {
+    fullName = "Computer Associates Open Source Licence Version 1.0";
+    url = "http://jxplorer.org/licence.html";
+  };
+
+  cal10 = {
+    spdxId = "CAL-1.0";
+    fullName = "Cryptographic Autonomy License version 1.0 (CAL-1.0)";
+    url = "https://opensource.org/licenses/CAL-1.0";
+  };
+
+  caldera = {
+    spdxId = "Caldera";
+    fullName = "Caldera License";
+    url = "http://www.lemis.com/grog/UNIX/ancient-source-all.pdf";
+  };
+
+  capec = {
+    fullName = "Common Attack Pattern Enumeration and Classification";
+    url = "https://capec.mitre.org/about/termsofuse.html";
+  };
+
+  clArtistic = {
+    spdxId = "ClArtistic";
+    fullName = "Clarified Artistic License";
+  };
+
+  cc0 = {
+    spdxId = "CC0-1.0";
+    fullName = "Creative Commons Zero v1.0 Universal";
+  };
+
+  cc-by-nc-nd-30 = {
+    spdxId = "CC-BY-NC-ND-3.0";
+    fullName = "Creative Commons Attribution Non Commercial No Derivative Works 3.0 Unported";
+    free = false;
+  };
+
+  cc-by-nc-nd-40 = {
+    spdxId = "CC-BY-NC-ND-4.0";
+    fullName = "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International";
+    free = false;
+  };
+
+  cc-by-nc-sa-20 = {
+    spdxId = "CC-BY-NC-SA-2.0";
+    fullName = "Creative Commons Attribution Non Commercial Share Alike 2.0";
+    free = false;
+  };
+
+  cc-by-nc-sa-25 = {
+    spdxId = "CC-BY-NC-SA-2.5";
+    fullName = "Creative Commons Attribution Non Commercial Share Alike 2.5";
+    free = false;
+  };
+
+  cc-by-nc-sa-30 = {
+    spdxId = "CC-BY-NC-SA-3.0";
+    fullName = "Creative Commons Attribution Non Commercial Share Alike 3.0";
+    free = false;
+  };
+
+  cc-by-nc-sa-40 = {
+    spdxId = "CC-BY-NC-SA-4.0";
+    fullName = "Creative Commons Attribution Non Commercial Share Alike 4.0";
+    free = false;
+  };
+
+  cc-by-nc-30 = {
+    spdxId = "CC-BY-NC-3.0";
+    fullName = "Creative Commons Attribution Non Commercial 3.0 Unported";
+    free = false;
+  };
+
+  cc-by-nc-40 = {
+    spdxId = "CC-BY-NC-4.0";
+    fullName = "Creative Commons Attribution Non Commercial 4.0 International";
+    free = false;
+  };
+
+  cc-by-nd-30 = {
+    spdxId = "CC-BY-ND-3.0";
+    fullName = "Creative Commons Attribution-No Derivative Works v3.00";
+    free = false;
+  };
+
+  cc-by-sa-10 = {
+    spdxId = "CC-BY-SA-1.0";
+    fullName = "Creative Commons Attribution Share Alike 1.0";
+  };
+
+  cc-by-sa-20 = {
+    spdxId = "CC-BY-SA-2.0";
+    fullName = "Creative Commons Attribution Share Alike 2.0";
+  };
+
+  cc-by-sa-25 = {
+    spdxId = "CC-BY-SA-2.5";
+    fullName = "Creative Commons Attribution Share Alike 2.5";
+  };
+
+  cc-by-10 = {
+    spdxId = "CC-BY-1.0";
+    fullName = "Creative Commons Attribution 1.0";
+  };
+
+  cc-by-20 = {
+    spdxId = "CC-BY-2.0";
+    fullName = "Creative Commons Attribution 2.0";
+  };
+
+  cc-by-30 = {
+    spdxId = "CC-BY-3.0";
+    fullName = "Creative Commons Attribution 3.0";
+  };
+
+  cc-by-sa-30 = {
+    spdxId = "CC-BY-SA-3.0";
+    fullName = "Creative Commons Attribution Share Alike 3.0";
+  };
+
+  cc-by-40 = {
+    spdxId = "CC-BY-4.0";
+    fullName = "Creative Commons Attribution 4.0";
+  };
+
+  cc-by-sa-40 = {
+    spdxId = "CC-BY-SA-4.0";
+    fullName = "Creative Commons Attribution Share Alike 4.0";
+  };
+
+  cddl = {
+    spdxId = "CDDL-1.0";
+    fullName = "Common Development and Distribution License 1.0";
+  };
+
+  cecill20 = {
+    spdxId = "CECILL-2.0";
+    fullName = "CeCILL Free Software License Agreement v2.0";
+  };
+
+  cecill21 = {
+    spdxId = "CECILL-2.1";
+    fullName = "CeCILL Free Software License Agreement v2.1";
+  };
+
+  cecill-b = {
+    spdxId = "CECILL-B";
+    fullName = "CeCILL-B Free Software License Agreement";
+  };
+
+  cecill-c = {
+    spdxId = "CECILL-C";
+    fullName = "CeCILL-C Free Software License Agreement";
+  };
+
+  cpal10 = {
+    spdxId = "CPAL-1.0";
+    fullName = "Common Public Attribution License 1.0";
+  };
+
+  commons-clause = {
+    fullName = "Commons Clause License";
+    url = "https://commonsclause.com/";
+    free = false;
+  };
+
+  cpl10 = {
+    spdxId = "CPL-1.0";
+    fullName = "Common Public License 1.0";
+  };
+
+  curl = {
+    spdxId = "curl";
+    fullName = "curl License";
+  };
+
+  doc = {
+    spdxId = "DOC";
+    fullName = "DOC License";
+  };
+
+  drl10 = {
+    spdxId = "DRL-1.0";
+    fullName = "Detection Rule License 1.0";
+  };
+
+  dtoa = {
+    spdxId = "dtoa";
+    fullName = "dtoa License";
+  };
+
+  eapl = {
+    fullName = "EPSON AVASYS PUBLIC LICENSE";
+    url = "https://avasys.jp/hp/menu000000700/hpg000000603.htm";
+    free = false;
+  };
+
+  ecl20 = {
+    fullName = "Educational Community License, Version 2.0";
+    url = "https://opensource.org/licenses/ECL-2.0";
+    shortName = "ECL 2.0";
+    spdxId = "ECL-2.0";
+  };
+
+  efl10 = {
+    spdxId = "EFL-1.0";
+    fullName = "Eiffel Forum License v1.0";
+  };
+
+  efl20 = {
+    spdxId = "EFL-2.0";
+    fullName = "Eiffel Forum License v2.0";
+  };
+
+  elastic20 = {
+    spdxId = "Elastic-2.0";
+    fullName = "Elastic License 2.0";
+    url = "https://github.com/elastic/elasticsearch/blob/main/licenses/ELASTIC-LICENSE-2.0.txt";
+    free = false;
+  };
+
+  epl10 = {
+    spdxId = "EPL-1.0";
+    fullName = "Eclipse Public License 1.0";
+  };
+
+  epl20 = {
+    spdxId = "EPL-2.0";
+    fullName = "Eclipse Public License 2.0";
+  };
+
+  epson = {
+    fullName = "Seiko Epson Corporation Software License Agreement for Linux";
+    url = "https://download.ebz.epson.net/dsc/du/02/eula/global/LINUX_EN.html";
+    free = false;
+  };
+
+  eupl11 = {
+    spdxId = "EUPL-1.1";
+    fullName = "European Union Public License 1.1";
+  };
+
+  eupl12 = {
+    spdxId = "EUPL-1.2";
+    fullName = "European Union Public License 1.2";
+  };
+
+  fdl11Only = {
+    spdxId = "GFDL-1.1-only";
+    fullName = "GNU Free Documentation License v1.1 only";
+  };
+
+  fdl11Plus = {
+    spdxId = "GFDL-1.1-or-later";
+    fullName = "GNU Free Documentation License v1.1 or later";
+  };
+
+  fdl12Only = {
+    spdxId = "GFDL-1.2-only";
+    fullName = "GNU Free Documentation License v1.2 only";
+  };
+
+  fdl12Plus = {
+    spdxId = "GFDL-1.2-or-later";
+    fullName = "GNU Free Documentation License v1.2 or later";
+  };
+
+  fdl13Only = {
+    spdxId = "GFDL-1.3-only";
+    fullName = "GNU Free Documentation License v1.3 only";
+  };
+
+  fdl13Plus = {
+    spdxId = "GFDL-1.3-or-later";
+    fullName = "GNU Free Documentation License v1.3 or later";
+  };
+
+  ffsl = {
+    fullName = "Floodgap Free Software License";
+    url = "https://www.floodgap.com/software/ffsl/license.html";
+    free = false;
+  };
+
+  fraunhofer-fdk = {
+    fullName = "Fraunhofer FDK AAC Codec Library";
+    spdxId = "FDK-AAC";
+  };
+
+  free = {
+    fullName = "Unspecified free software license";
+  };
+
+  ftl = {
+    spdxId = "FTL";
+    fullName = "Freetype Project License";
+  };
+
+  g4sl = {
+    fullName = "Geant4 Software License";
+    url = "https://geant4.web.cern.ch/geant4/license/LICENSE.html";
+  };
+
+  geogebra = {
+    fullName = "GeoGebra Non-Commercial License Agreement";
+    url = "https://www.geogebra.org/license";
+    free = false;
+  };
+
+  generaluser = {
+    fullName = "GeneralUser GS License v2.0";
+    url = "https://www.schristiancollins.com/generaluser.php"; # license included in sources
+  };
+
+  gfl = {
+    fullName = "GUST Font License";
+    url = "https://www.gust.org.pl/projects/e-foundry/licenses/GUST-FONT-LICENSE.txt";
+  };
+
+  gfsl = {
+    fullName = "GUST Font Source License";
+    url = "https://www.gust.org.pl/projects/e-foundry/licenses/GUST-FONT-SOURCE-LICENSE.txt";
+  };
+
+  gpl1Only = {
+    spdxId = "GPL-1.0-only";
+    fullName = "GNU General Public License v1.0 only";
+  };
+
+  gpl1Plus = {
+    spdxId = "GPL-1.0-or-later";
+    fullName = "GNU General Public License v1.0 or later";
+  };
+
+  gpl2Only = {
+    spdxId = "GPL-2.0-only";
+    fullName = "GNU General Public License v2.0 only";
+  };
+
+  gpl2Classpath = {
+    spdxId = "GPL-2.0-with-classpath-exception";
+    fullName = "GNU General Public License v2.0 only (with Classpath exception)";
+  };
+
+  gpl2ClasspathPlus = {
+    fullName = "GNU General Public License v2.0 or later (with Classpath exception)";
+    url = "https://fedoraproject.org/wiki/Licensing/GPL_Classpath_Exception";
+  };
+
+  gpl2Oss = {
+    fullName = "GNU General Public License version 2 only (with OSI approved licenses linking exception)";
+    url = "https://www.mysql.com/about/legal/licensing/foss-exception";
+  };
+
+  gpl2Plus = {
+    spdxId = "GPL-2.0-or-later";
+    fullName = "GNU General Public License v2.0 or later";
+  };
+
+  gpl3Only = {
+    spdxId = "GPL-3.0-only";
+    fullName = "GNU General Public License v3.0 only";
+  };
+
+  gpl3Plus = {
+    spdxId = "GPL-3.0-or-later";
+    fullName = "GNU General Public License v3.0 or later";
+  };
+
+  gpl3ClasspathPlus = {
+    fullName = "GNU General Public License v3.0 or later (with Classpath exception)";
+    url = "https://fedoraproject.org/wiki/Licensing/GPL_Classpath_Exception";
+  };
+
+  giftware = {
+    spdxId = "Giftware";
+    fullName = "Giftware License";
+  };
+
+  hpnd = {
+    spdxId = "HPND";
+    fullName = "Historic Permission Notice and Disclaimer";
+  };
+
+  hpndSellVariant = {
+    fullName = "Historical Permission Notice and Disclaimer - sell variant";
+    spdxId = "HPND-sell-variant";
+  };
+
+  hpndUc = {
+    spdxId = "HPND-UC";
+    fullName = "Historical Permission Notice and Disclaimer - University of California variant";
+  };
+
+  # Intel's license, seems free
+  iasl = {
+    spdxId = "Intel-ACPI";
+    fullName = "iASL";
+    url = "https://old.calculate-linux.org/packages/licenses/iASL";
+  };
+
+  icu = {
+    spdxId = "ICU";
+    fullName = "ICU";
+  };
+
+  ijg = {
+    spdxId = "IJG";
+    fullName = "Independent JPEG Group License";
+  };
+
+  imagemagick = {
+    fullName = "ImageMagick License";
+    spdxId = "ImageMagick";
+  };
+
+  imlib2 = {
+    spdxId = "Imlib2";
+    fullName = "Imlib2 License";
+  };
+
+  info-zip = {
+    spdxId = "Info-ZIP";
+    fullName = "Info-ZIP License";
+    url = "https://infozip.sourceforge.net/license.html";
+  };
+
+  inria-compcert = {
+    fullName = "INRIA Non-Commercial License Agreement for the CompCert verified compiler";
+    url = "https://compcert.org/doc/LICENSE.txt";
+    free = false;
+  };
+
+  inria-icesl = {
+    fullName = "End User License Agreement for IceSL Software";
+    url = "https://icesl.loria.fr/assets/pdf/EULA_IceSL_binary.pdf";
+    free = false;
+  };
+
+  inria-zelus = {
+    fullName = "INRIA Non-Commercial License Agreement for the Zélus compiler";
+    url = "https://github.com/INRIA/zelus/raw/829f2b97cba93b0543a9ca0272269e6b8fdad356/LICENSE";
+    free = false;
+  };
+
+  ipa = {
+    spdxId = "IPA";
+    fullName = "IPA Font License";
+  };
+
+  ipl10 = {
+    spdxId = "IPL-1.0";
+    fullName = "IBM Public License v1.0";
+  };
+
+  isc = {
+    spdxId = "ISC";
+    fullName = "ISC License";
+  };
+
+  # Proprietary binaries; free to redistribute without modification.
+  databricks = {
+    fullName = "Databricks Proprietary License";
+    url = "https://pypi.org/project/databricks-connect";
+    free = false;
+  };
+
+  databricks-dbx = {
+    fullName = "DataBricks eXtensions aka dbx License";
+    url = "https://github.com/databrickslabs/dbx/blob/743b579a4ac44531f764c6e522dbe5a81a7dc0e4/LICENSE";
+    free = false;
+    redistributable = false;
+  };
+
+  fair = {
+    fullName = "Fair License";
+    spdxId = "Fair";
+    free = true;
+  };
+
+  fairsource09 = {
+    fullName = "Fair Source License, version 0.9";
+    url = "https://fair.io/v0.9.txt";
+    free = false;
+    redistributable = true;
+  };
+
+  hl3 = {
+    fullName = "Hippocratic License v3.0";
+    url = "https://firstdonoharm.dev/version/3/0/core.txt";
+    free = false;
+    redistributable = true;
+  };
+
+  issl = {
+    fullName = "Intel Simplified Software License";
+    url = "https://software.intel.com/en-us/license/intel-simplified-software-license";
+    free = false;
+  };
+
+  knuth = {
+    fullName = "Knuth CTAN License";
+    spdxId = "Knuth-CTAN";
+  };
+
+  lal12 = {
+    spdxId = "LAL-1.2";
+    fullName = "Licence Art Libre 1.2";
+  };
+
+  lal13 = {
+    spdxId = "LAL-1.3";
+    fullName = "Licence Art Libre 1.3";
+  };
+
+  lens = {
+    fullName = "Lens Terms of Service Agreement";
+    url = "https://k8slens.dev/licenses/tos";
+    free = false;
+  };
+
+  lgpl2Only = {
+    spdxId = "LGPL-2.0-only";
+    fullName = "GNU Library General Public License v2 only";
+  };
+
+  lgpl2Plus = {
+    spdxId = "LGPL-2.0-or-later";
+    fullName = "GNU Library General Public License v2 or later";
+  };
+
+  lgpl21Only = {
+    spdxId = "LGPL-2.1-only";
+    fullName = "GNU Lesser General Public License v2.1 only";
+  };
+
+  lgpl21Plus = {
+    spdxId = "LGPL-2.1-or-later";
+    fullName = "GNU Lesser General Public License v2.1 or later";
+  };
+
+  lgpl3Only = {
+    spdxId = "LGPL-3.0-only";
+    fullName = "GNU Lesser General Public License v3.0 only";
+  };
+
+  lgpl3Plus = {
+    spdxId = "LGPL-3.0-or-later";
+    fullName = "GNU Lesser General Public License v3.0 or later";
+  };
+
+  lgpllr = {
+    spdxId = "LGPLLR";
+    fullName = "Lesser General Public License For Linguistic Resources";
+  };
+
+  libpng = {
+    spdxId = "Libpng";
+    fullName = "libpng License";
+  };
+
+  libpng2 = {
+    spdxId = "libpng-2.0"; # Used since libpng 1.6.36.
+    fullName = "PNG Reference Library version 2";
+  };
+
+  libssh2 = {
+    fullName = "libssh2 License";
+    url = "https://www.libssh2.org/license.html";
+  };
+
+  libtiff = {
+    spdxId = "libtiff";
+    fullName = "libtiff License";
+  };
+
+  llgpl21 = {
+    fullName = "Lisp LGPL; GNU Lesser General Public License version 2.1 with Franz Inc. preamble for clarification of LGPL terms in context of Lisp";
+    url = "https://opensource.franz.com/preamble.html";
+  };
+
+  lppl1 = {
+    spdxId = "LPPL-1.0";
+    fullName = "LaTeX Project Public License v1.0";
+  };
+
+  lppl12 = {
+    spdxId = "LPPL-1.2";
+    fullName = "LaTeX Project Public License v1.2";
+  };
+
+  lppl13a = {
+    spdxId = "LPPL-1.3a";
+    fullName = "LaTeX Project Public License v1.3a";
+  };
+
+  lppl13c = {
+    spdxId = "LPPL-1.3c";
+    fullName = "LaTeX Project Public License v1.3c";
+  };
+
+  lpl-102 = {
+    spdxId = "LPL-1.02";
+    fullName = "Lucent Public License v1.02";
+  };
+
+  miros = {
+    spdxId = "MirOS";
+    fullName = "MirOS License";
+    url = "https://opensource.org/licenses/MirOS";
+  };
+
+  # spdx.org does not (yet) differentiate between the X11 and Expat versions
+  # for details see https://en.wikipedia.org/wiki/MIT_License#Various_versions
+  mit = {
+    spdxId = "MIT";
+    fullName = "MIT License";
+  };
+  # https://spdx.org/licenses/MIT-feh.html
+  mit-feh = {
+    spdxId = "MIT-feh";
+    fullName = "feh License";
+  };
+
+  mitAdvertising = {
+    spdxId = "MIT-advertising";
+    fullName = "Enlightenment License (e16)";
+  };
+
+  mit0 = {
+    spdxId = "MIT-0";
+    fullName = "MIT No Attribution";
+  };
+
+  mpl10 = {
+    spdxId = "MPL-1.0";
+    fullName = "Mozilla Public License 1.0";
+  };
+
+  mpl11 = {
+    spdxId = "MPL-1.1";
+    fullName = "Mozilla Public License 1.1";
+  };
+
+  mpl20 = {
+    spdxId = "MPL-2.0";
+    fullName = "Mozilla Public License 2.0";
+  };
+
+  mplus = {
+    spdxId = "mplus";
+    fullName = "M+ Font License";
+  };
+
+  mspl = {
+    spdxId = "MS-PL";
+    fullName = "Microsoft Public License";
+  };
+
+  mulan-psl2 = {
+    spdxId = "MulanPSL-2.0";
+    fullName = "Mulan Permissive Software License, Version 2";
+    url = "https://license.coscl.org.cn/MulanPSL2";
+  };
+
+  nasa13 = {
+    spdxId = "NASA-1.3";
+    fullName = "NASA Open Source Agreement 1.3";
+    free = false;
+  };
+
+  ncbiPd = {
+    spdxId = "NCBI-PD";
+    fullname = "NCBI Public Domain Notice";
+    # Due to United States copyright law, anything with this "license" does not have a copyright in the
+    # jurisdiction of the United States. However, other jurisdictions may assign the United States
+    # government copyright to the work, and the license explicitly states that in such a case, no license
+    # is granted. This is nonfree and nonredistributable in most jurisdictions other than the United States.
+    free = false;
+    redistributable = false;
+  };
+
+  ncsa = {
+    spdxId = "NCSA";
+    fullName = "University of Illinois/NCSA Open Source License";
+  };
+
+  ncul1 = {
+    spdxId = "NCUL1";
+    fullName = "Netdata Cloud UI License v1.0";
+    free = false;
+    redistributable = true; # Only if used in Netdata products.
+    url = "https://raw.githubusercontent.com/netdata/netdata/master/web/gui/v2/LICENSE.md";
+  };
+
+  nistSoftware = {
+    spdxId = "NIST-Software";
+    fullName = "NIST Software License";
+  };
+
+  nlpl = {
+    spdxId = "NLPL";
+    fullName = "No Limit Public License";
+  };
+
+  nposl3 = {
+    spdxId = "NPOSL-3.0";
+    fullName = "Non-Profit Open Software License 3.0";
+  };
+
+  nvidiaCuda = {
+    shortName = "CUDA EULA";
+    fullName = "CUDA Toolkit End User License Agreement (EULA)";
+    url = "https://docs.nvidia.com/cuda/eula/index.html#cuda-toolkit-supplement-license-agreement";
+    free = false;
+  };
+
+  nvidiaCudaRedist = {
+    shortName = "CUDA EULA";
+    fullName = "CUDA Toolkit End User License Agreement (EULA)";
+    url = "https://docs.nvidia.com/cuda/eula/index.html#cuda-toolkit-supplement-license-agreement";
+    free = false;
+    redistributable = true;
+  };
+
+  obsidian = {
+    fullName = "Obsidian End User Agreement";
+    url = "https://obsidian.md/eula";
+    free = false;
+  };
+
+  ocamlLgplLinkingException = {
+    spdxId = "OCaml-LGPL-linking-exception";
+    fullName = "OCaml LGPL Linking Exception";
+  };
+
+  ocamlpro_nc = {
+    fullName = "OCamlPro Non Commercial license version 1";
+    url = "https://alt-ergo.ocamlpro.com/http/alt-ergo-2.2.0/OCamlPro-Non-Commercial-License.pdf";
+    free = false;
+  };
+
+  odbl = {
+    spdxId = "ODbL-1.0";
+    fullName = "Open Data Commons Open Database License v1.0";
+  };
+
+  ofl = {
+    spdxId = "OFL-1.1";
+    fullName = "SIL Open Font License 1.1";
+  };
+
+  oml = {
+    spdxId = "OML";
+    fullName = "Open Market License";
+  };
+
+  openldap = {
+    spdxId = "OLDAP-2.8";
+    fullName = "Open LDAP Public License v2.8";
+  };
+
+  openssl = {
+    spdxId = "OpenSSL";
+    fullName = "OpenSSL License";
+  };
+
+  opubl = {
+    spdxId = "OPUBL-1.0";
+    fullName = "Open Publication License v1.0";
+  };
+
+  osl2 = {
+    spdxId = "OSL-2.0";
+    fullName = "Open Software License 2.0";
+  };
+
+  osl21 = {
+    spdxId = "OSL-2.1";
+    fullName = "Open Software License 2.1";
+  };
+
+  osl3 = {
+    spdxId = "OSL-3.0";
+    fullName = "Open Software License 3.0";
+  };
+
+  parity70 = {
+    spdxId = "Parity-7.0.0";
+    fullName = "Parity Public License 7.0.0";
+    url = "https://paritylicense.com/versions/7.0.0.html";
+  };
+
+  php301 = {
+    spdxId = "PHP-3.01";
+    fullName = "PHP License v3.01";
+  };
+
+  postgresql = {
+    spdxId = "PostgreSQL";
+    fullName = "PostgreSQL License";
+  };
+
+  postman = {
+    fullName = "Postman EULA";
+    url = "https://www.getpostman.com/licenses/postman_base_app";
+    free = false;
+  };
+
+  psfl = {
+    spdxId = "Python-2.0";
+    fullName = "Python Software Foundation License version 2";
+    url = "https://docs.python.org/license.html";
+  };
+
+  publicDomain = {
+    fullName = "Public Domain";
+  };
+
+  purdueBsd = {
+    fullName = " Purdue BSD-Style License"; # also know as lsof license
+    url = "https://enterprise.dejacode.com/licenses/public/purdue-bsd";
+  };
+
+  prosperity30 = {
+    fullName = "Prosperity-3.0.0";
+    free = false;
+    url = "https://prosperitylicense.com/versions/3.0.0.html";
+  };
+
+  qhull = {
+    spdxId = "Qhull";
+    fullName = "Qhull License";
+  };
+
+  qpl = {
+    spdxId = "QPL-1.0";
+    fullName = "Q Public License 1.0";
+  };
+
+  qwt = {
+    fullName = "Qwt License, Version 1.0";
+    url = "https://qwt.sourceforge.io/qwtlicense.html";
+  };
+
+  ruby = {
+    spdxId = "Ruby";
+    fullName = "Ruby License";
+  };
+
+  sendmail = {
+    spdxId = "Sendmail";
+    fullName = "Sendmail License";
+  };
+
+  sgi-b-20 = {
+    spdxId = "SGI-B-2.0";
+    fullName = "SGI Free Software License B v2.0";
+  };
+
+  # Gentoo seems to treat it as a license:
+  # https://gitweb.gentoo.org/repo/gentoo.git/tree/licenses/SGMLUG?id=7d999af4a47bf55e53e54713d98d145f935935c1
+  sgmlug = {
+    fullName = "SGML UG SGML Parser Materials license";
+  };
+
+  sleepycat = {
+    spdxId = "Sleepycat";
+    fullName = "Sleepycat License";
+  };
+
+  smail = {
+    shortName = "smail";
+    fullName = "SMAIL General Public License";
+    url = "https://sources.debian.org/copyright/license/debianutils/4.9.1/";
+  };
+
+  smlnj = {
+    spdxId = "SMLNJ";
+    fullName = "Standard ML of New Jersey License";
+  };
+
+  sspl = {
+    shortName = "SSPL";
+    fullName = "Server Side Public License";
+    url = "https://www.mongodb.com/licensing/server-side-public-license";
+    free = false;
+    # NOTE Debatable.
+    # The license a slightly modified AGPL but still considered unfree by the
+    # OSI for what seem like political reasons
+    redistributable = true; # Definitely redistributable though, it's an AGPL derivative
+  };
+
+  stk = {
+    shortName = "stk";
+    fullName = "Synthesis Tool Kit 4.3";
+    url = "https://github.com/thestk/stk/blob/master/LICENSE";
+  };
+
+  sudo = {
+    shortName = "sudo";
+    fullName = "Sudo License (ISC-style)";
+    url = "https://www.sudo.ws/about/license/";
+  };
+
+  sustainableUse = {
+    shortName = "sustainable";
+    fullName = "Sustainable Use License";
+    url = "https://github.com/n8n-io/n8n/blob/master/LICENSE.md";
+    free = false;
+    redistributable = false; # only free to redistribute "for non-commercial purposes"
+  };
+
+  tsl = {
+    shortName = "TSL";
+    fullName = "Timescale License Agreegment";
+    url = "https://github.com/timescale/timescaledb/blob/main/tsl/LICENSE-TIMESCALE";
+    unfree = true;
+  };
+
+  tcltk = {
+    spdxId = "TCL";
+    fullName = "TCL/TK License";
+  };
+
+  ucd = {
+    fullName = "Unicode Character Database License";
+    url = "https://fedoraproject.org/wiki/Licensing:UCD";
+  };
+
+  ufl = {
+    fullName = "Ubuntu Font License 1.0";
+    url = "https://ubuntu.com/legal/font-licence";
+  };
+
+  unfree = {
+    fullName = "Unfree";
+    free = false;
+  };
+
+  unfreeRedistributable = {
+    fullName = "Unfree redistributable";
+    free = false;
+    redistributable = true;
+  };
+
+  unfreeRedistributableFirmware = {
+    fullName = "Unfree redistributable firmware";
+    redistributable = true;
+    # Note: we currently consider these "free" for inclusion in the
+    # channel and NixOS images.
+  };
+
+  unicode-30 = {
+    spdxId = "Unicode-3.0";
+    fullName = "Unicode License v3";
+  };
+
+  unicode-dfs-2015 = {
+    spdxId = "Unicode-DFS-2015";
+    fullName = "Unicode License Agreement - Data Files and Software (2015)";
+  };
+
+  unicode-dfs-2016 = {
+    spdxId = "Unicode-DFS-2016";
+    fullName = "Unicode License Agreement - Data Files and Software (2016)";
+  };
+
+  unlicense = {
+    spdxId = "Unlicense";
+    fullName = "The Unlicense";
+  };
+
+  upl = {
+    spdxId = "UPL-1.0";
+    fullName = "Universal Permissive License";
+    url = "https://oss.oracle.com/licenses/upl/";
+  };
+
+  vim = {
+    spdxId = "Vim";
+    fullName = "Vim License";
+  };
+
+  virtualbox-puel = {
+    fullName = "Oracle VM VirtualBox Extension Pack Personal Use and Evaluation License (PUEL)";
+    url = "https://www.virtualbox.org/wiki/VirtualBox_PUEL";
+    free = false;
+  };
+
+  vol-sl = {
+    fullName = "Volatility Software License, Version 1.0";
+    url = "https://www.volatilityfoundation.org/license/vsl-v1.0";
+  };
+
+  vsl10 = {
+    spdxId = "VSL-1.0";
+    fullName = "Vovida Software License v1.0";
+  };
+
+  watcom = {
+    spdxId = "Watcom-1.0";
+    fullName = "Sybase Open Watcom Public License 1.0";
+  };
+
+  w3c = {
+    spdxId = "W3C";
+    fullName = "W3C Software Notice and License";
+  };
+
+  wadalab = {
+    fullName = "Wadalab Font License";
+    url = "https://fedoraproject.org/wiki/Licensing:Wadalab?rd=Licensing/Wadalab";
+  };
+
+  wtfpl = {
+    spdxId = "WTFPL";
+    fullName = "Do What The F*ck You Want To Public License";
+  };
+
+  wxWindows = {
+    spdxId = "wxWindows";
+    fullName = "wxWindows Library Licence, Version 3.1";
+  };
+
+  x11 = {
+    spdxId = "X11";
+    fullName = "X11 License";
+  };
+
+  xfig = {
+    spdxId = "Xfig";
+    fullName = "xfig";
+    url = "https://mcj.sourceforge.net/authors.html#xfig";
+  };
+
+  xinetd = {
+    spdxId = "xinetd";
+    fullName = "xinetd License";
+  };
+
+  zlib = {
+    spdxId = "Zlib";
+    fullName = "zlib License";
+  };
+
+  zpl20 = {
+    spdxId = "ZPL-2.0";
+    fullName = "Zope Public License 2.0";
+  };
+
+  zpl21 = {
+    spdxId = "ZPL-2.1";
+    fullName = "Zope Public License 2.1";
+  };
+
+  xskat = {
+    spdxId = "XSkat";
+    fullName = "XSkat License";
+  };
+}
diff --git a/lib/src/licenses/default.nix b/lib/src/licenses/default.nix
new file mode 100644
index 0000000..6dd937e
--- /dev/null
+++ b/lib/src/licenses/default.nix
@@ -0,0 +1,33 @@
+lib: {
+  licenses = let
+    raw = import ./all.nix;
+
+    defaults = name: {
+      inherit name;
+      free = true;
+    };
+
+    withDefaults = name: license: (defaults name) // license;
+    withSpdx = license:
+      if license ? spdx
+      then
+        license
+        // {
+          url = "https://spdx.org/licenses/${license.spdx}.html";
+        }
+      else license;
+    withRedistributable = license:
+      {
+        redistributable = license.free;
+      }
+      // license;
+
+    normalize = name:
+      lib.fp.pipe [
+        (withDefaults name)
+        withSpdx
+        withRedistributable
+      ];
+  in
+    builtins.mapAttrs normalize raw;
+}
diff --git a/lib/src/modules/default.nix b/lib/src/modules/default.nix
index ffe807a..2a3e83e 100644
--- a/lib/src/modules/default.nix
+++ b/lib/src/modules/default.nix
@@ -474,8 +474,8 @@ lib: {
         prefix ? [],
       }:
         lib.modules.run {
-          modules = settings.modules ++ extensions.modules;
-          args = (settings.args or {}) // extensions.args;
+          modules = (settings.modules or []) ++ (extensions.modules or []);
+          args = (settings.args or {}) // (extensions.args or {});
           prefix = extensions.prefix or settings.prefix or [];
         };
 
diff --git a/lib/src/packages/default.nix b/lib/src/packages/default.nix
index 175ed74..0373db2 100644
--- a/lib/src/packages/default.nix
+++ b/lib/src/packages/default.nix
@@ -44,5 +44,13 @@ lib: {
               else x)
           ]
           value;
+
+    ## Get an output of a package.
+    ##
+    ## @type String -> Package -> String
+    getOutput = output: package:
+      if ! package ? outputSpecified || !package.outputSpecified
+      then package.${output} or package.out or package
+      else package;
   };
 }
diff --git a/lib/src/paths/default.nix b/lib/src/paths/default.nix
index 903c109..8378c0b 100644
--- a/lib/src/paths/default.nix
+++ b/lib/src/paths/default.nix
@@ -32,5 +32,37 @@ lib: {
           && builtins.dirOf (builtins.toString value) == builtins.storeDir
         else false;
     };
+
+    ## Create a search path from a list of paths.
+    ##
+    ## @type String -> [String] -> String
+    search = target: paths:
+      lib.strings.concatMapSep
+      ":"
+      (path: path + "/" + target)
+      (builtins.filter (value: value != null) paths);
+
+    ## Create a search path from a list of packages.
+    ##
+    ## @type String -> [Package] -> String
+    searchFromOutput = output: target: packages:
+      lib.paths.search
+      target
+      (builtins.map (lib.packages.getOutput output) packages);
+
+    ## Create a search path for the binary output of a package.
+    ##
+    ## @type [Package] -> String
+    bin = lib.paths.searchFromOutput "bin" "bin";
+
+    ## Create a search path for the library output of a package.
+    ##
+    ## @type [Package] -> String
+    lib = lib.paths.searchFromOutput "lib" "lib";
+
+    ## Create a search path for the include output of a package.
+    ##
+    ## @type [Package] -> String
+    include = lib.paths.searchFromOutput "dev" "include";
   };
 }