A full binary bootstrap chain for Nix.
Find a file
Aleksi Hannula 81f071f1ec fix: Build tcc-musl through an intermediate stage
If tinycc is linked with a musl which in turn was built by tcc-mes,
then this musl has broken implementations of the math library on
certain arches, which is in turn caused tcc-mes having stubbed math
functions. The only way to get a trustworthy musl is to build it with
an intermediate tcc-musl, where the intermediate tcc-musl has at least
working ldexp and frexp.

Issues in the math library were surfacing on RISC-V when building gmp.
2025-10-28 03:31:26 +00:00
npins update lib in npins 2025-10-23 21:46:42 +00:00
scripts Add simple script to check reproducibility 2025-10-23 19:49:22 +00:00
src fix: Build tcc-musl through an intermediate stage 2025-10-28 03:31:26 +00:00
.gitignore chore: extract from labs 2025-03-30 06:50:39 -07:00
default.nix add format.sh from labs, reformat tree (#18) 2025-10-18 15:40:01 +00:00
flake.lock chore: extract from labs 2025-03-30 06:50:39 -07:00
flake.nix add format.sh from labs, reformat tree (#18) 2025-10-18 15:40:01 +00:00
format.sh add format.sh from labs, reformat tree (#18) 2025-10-18 15:40:01 +00:00
LICENSE chore: extract from labs 2025-03-30 06:50:39 -07:00
README.md update README 2025-10-28 02:43:02 +00:00

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.

inputs.foundation.url = "https://git.auxolotl.org/auxolotl/foundation/archive/main.tar.gz";

To import this library without using Nix Flakes, you will need to use fetchTarball and import the library entrypoint.

You probably need to specify the system argument, which needs to be one of the supported systems. Otherwise, Foundation will default to your current system (builtins.currentSystem). Since we only support bootstrapping on 32-bit x86 right now, that probably won't work. If you use an unsupported system with Foundation, it will fail to evaluate.

let
    foundation_tarball = builtins.fetchTarball {
        url = "https://git.auxolotl.org/auxolotl/foundation/archive/main.tar.gz";
        sha256 = "<sha256>";
    };
    foundation = import foundation_tarball {
        # Specifying a system is optional but very likely to be necessary
        system = "i686-linux";
    };
in
    # ...

Supported systems

For now, Aux Foundation only supports bootstrapping for "i686-linux".

Bypassing Geoblocking

If you get an error(possibly with different hashes) such as

error: hash mismatch in file downloaded from 'https://repo.or.cz/tinycc.git/snapshot/fd6d2180c5c801bb0b4c5dde27d61503059fc97d.tar.gz':
         specified: sha256-R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA=
         got:       sha256-YFl5pQIdfJAn4ijH1UU8OY+DRtJ0LPd5r0eoIF8iyMI=

and you're in the UK, you will need to manually add the tinycc revisions to the store, because of Online Safety Act-caused geoblocking.

If you have Tor running, you can use it as a proxy with the below script to manually add the items to your nix store.

curl --proxy socks5://localhost:9050 -LO https://repo.or.cz/tinycc.git/snapshot/86f3d8e33105435946383aee52487b5ddf918140.tar.gz
curl --proxy socks5://localhost:9050 -LO https://repo.or.cz/tinycc.git/snapshot/fd6d2180c5c801bb0b4c5dde27d61503059fc97d.tar.gz

nix-store --add-fixed sha256 86f3d8e33105435946383aee52487b5ddf918140.tar.gz
nix-store --add-fixed sha256 fd6d2180c5c801bb0b4c5dde27d61503059fc97d.tar.gz

Alternatively, use a VPN or some other form of proxy to download the files

and add them to your nix store as shown above.

This will fix the build until a garbage collection run.

ftpmirror.gnu.org HTTP errors

If you get an error such as

error: unable to download 'https://ftpmirror.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz': HTTP error 403 (Forbidden)

or any other HTTP error, try re-running the build. Some of the mirrors in the ftpmirror.gnu.org pool may be flaky, and retrying will get a different mirror chosen. Once it's downloaded, it will be cached in your nix store, so you won't run into the issue again until a garbage collection run.

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).

Additionally, please keep Markdown files such as this one hard-wrapped to a width of 80 columns.

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. 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:

{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.

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 compil the original tools it used from C sources.

Stage 1

This stage is responsible for building up to a recent version of gcc. Along with the compiler, this stage provides things like bash, coreutils, gnumake, and several other important tools.

Stage 2

This stage refines the existing packages by building static binaries as well as the most recent versions of the tools. In addition, certain load-bearing packages such as patchelf and glibc are built.