···11# This file constructs the standard build environment for the
22-# Linux/i686 platform. It's completely pure; that is, it relies on no
22+# Linux platform. It's completely pure; that is, it relies on no
33# external (non-Nix) tools, such as /usr/bin/gcc, and it contains a C
44# compiler and linker that do not search in default locations,
55# ensuring purity of components produced by it.
66+#
77+# It starts from prebuilt seed bootstrapFiles and creates a series of
88+# nixpkgs instances (stages) to gradually rebuild stdenv, which
99+# is used to build all other packages (including the bootstrapFiles).
1010+#
1111+# Goals of the bootstrap process:
1212+# 1. final stdenv must not reference any of the bootstrap files.
1313+# 2. final stdenv must not contain any of the bootstrap files
1414+# (the only current violation is libgcc_s.so in glibc).
1515+# 3. final stdenv must not contain any of the files directly
1616+# generated by the bootstrap code generators (assembler, linker,
1717+# compiler). The only current violations are: libgcc_s.so in glibc,
1818+# the lib{mpfr,mpc,gmp,isl} which are statically linked
1919+# into the final gcc).
2020+#
2121+# These goals ensure that final packages and final stdenv are built
2222+# exclusively using nixpkgs package definitions and don't depend
2323+# on bootstrapTools (via direct references, inclusion
2424+# of copied code, or code compiled directly by bootstrapTools).
2525+#
2626+# Stages are described below along with their definitions.
2727+#
2828+# Debugging stdenv dependency graph:
2929+# An useful tool to explore dependencies across stages is to use
3030+# '__bootPackages' attribute of 'stdenv. Examples of last 3 stages:
3131+# - stdenv
3232+# - stdenv.__bootPackages.stdenv
3333+# - stdenv.__bootPackages.stdenv.__bootPackages.stdenv
3434+# - ... and so on.
3535+#
3636+# To explore build-time dependencies in graphical form one can use
3737+# the following:
3838+# $ nix-store --query --graph $(nix-instantiate -A stdenv) |
3939+# grep -P -v '[.]sh|[.]patch|bash|[.]tar' | # avoid clutter
4040+# dot -Tsvg > stdenv-final.svg
4141+#
4242+# To find all the packages built by a particular stdenv instance:
4343+# $ for stage in 0 1 2 3 4; do
4444+# echo "stage${stage} used in:"
4545+# nix-store --query --graph $(nix-instantiate -A stdenv) |
4646+# grep -P ".*bootstrap-stage${stage}-stdenv.*->.*" |
4747+# sed 's/"[0-9a-z]\{32\}-/"/g'
4848+# done
4949+#
5050+# To verify which stdenv was used to build a given final package:
5151+# $ nix-store --query --graph $(nix-instantiate -A stdenv) |
5252+# grep -P -v '[.]sh|[.]patch|bash|[.]tar' |
5353+# grep -P '.*stdenv.*->.*glibc-2'
5454+# "...-bootstrap-stage2-stdenv-linux.drv" -> "...-glibc-2.35-224.drv";
5555+#
5656+# For a TUI (rather than CLI) view, you can use:
5757+#
5858+# $ nix-tree --derivation $(nix-instantiate -A stdenv)
659{ lib
760, localSystem, crossSystem, config, overlays, crossOverlays ? []
861···147200148201 # Build a dummy stdenv with no GCC or working fetchurl. This is
149202 # because we need a stdenv to build the GCC wrapper and fetchurl.
203203+ #
204204+ # resulting stage0 stdenv:
205205+ # - coreutils, binutils, glibc, gcc: from bootstrapFiles
150206 (prevStage: stageFun prevStage {
151207 name = "bootstrap-stage0";
152208···202258 # If we ever need to use a package from more than one stage back, we
203259 # simply re-export those packages in the middle stage(s) using the
204260 # overrides attribute and the inherit syntax.
261261+ #
262262+ # resulting stage1 stdenv:
263263+ # - coreutils, binutils, glibc, gcc: from bootstrapFiles
205264 (prevStage: stageFun prevStage {
206265 name = "bootstrap-stage1";
207266···228287229288 # 2nd stdenv that contains our own rebuilt binutils and is used for
230289 # compiling our own Glibc.
290290+ #
291291+ # resulting stage2 stdenv:
292292+ # - coreutils, glibc, gcc: from bootstrapFiles
293293+ # - binutils: from nixpkgs, built by bootstrapFiles toolchain
231294 (prevStage: stageFun prevStage {
232295 name = "bootstrap-stage2";
233296···296359 # Construct a third stdenv identical to the 2nd, except that this
297360 # one uses the rebuilt Glibc from stage2. It still uses the recent
298361 # binutils and rest of the bootstrap tools, including GCC.
362362+ #
363363+ # resulting stage3 stdenv:
364364+ # - coreutils, gcc: from bootstrapFiles
365365+ # - glibc, binutils: from nixpkgs, built by bootstrapFiles toolchain
299366 (prevStage: stageFun prevStage {
300367 name = "bootstrap-stage3";
301368···332399333400 # Construct a fourth stdenv that uses the new GCC. But coreutils is
334401 # still from the bootstrap tools.
402402+ #
403403+ # resulting stage4 stdenv:
404404+ # - coreutils: from bootstrapFiles
405405+ # - glibc, binutils: from nixpkgs, built by bootstrapFiles toolchain
406406+ # - gcc: from nixpkgs, built by bootstrapFiles toolchain. Can assume
407407+ # it has almost no code from bootstrapTools as gcc bootstraps
408408+ # internally. The only exceptions are crt files from glibc
409409+ # built by bootstrapTools used to link executables and libraries,
410410+ # and the bootstrapTools-built, statically-linked
411411+ # lib{mpfr,mpc,gmp,isl}.a which are linked into the final gcc
412412+ # (see commit cfde88976ba4cddd01b1bb28b40afd12ea93a11d).
335413 (prevStage: stageFun prevStage {
336414 name = "bootstrap-stage4";
337415···388466 # When updating stdenvLinux, make sure that the result has no
389467 # dependency (`nix-store -qR') on bootstrapTools or the first
390468 # binutils built.
469469+ #
470470+ # resulting stage5 (final) stdenv:
471471+ # - coreutils, binutils: from nixpkgs, built by nixpkgs toolchain
472472+ # - glibc: from nixpkgs, built by bootstrapFiles toolchain
473473+ # - gcc: from nixpkgs, built by bootstrapFiles toolchain. Can assume
474474+ # it has almost no code from bootstrapTools as gcc bootstraps
475475+ # internally. The only exceptions are crt files from glibc
476476+ # built by bootstrapTools used to link executables and libraries,
477477+ # and the bootstrapTools-built, statically-linked
478478+ # lib{mpfr,mpc,gmp,isl}.a which are linked into the final gcc
479479+ # (see commit cfde88976ba4cddd01b1bb28b40afd12ea93a11d).
391480 (prevStage: {
392481 inherit config overlays;
393482 stdenv = import ../generic rec {