···1# This file constructs the standard build environment for the
2-# Linux/i686 platform. It's completely pure; that is, it relies on no
3# external (non-Nix) tools, such as /usr/bin/gcc, and it contains a C
4# compiler and linker that do not search in default locations,
5# ensuring purity of components produced by it.
000000000000000000000000000000000000000000000000000006{ lib
7, localSystem, crossSystem, config, overlays, crossOverlays ? []
8···147148 # Build a dummy stdenv with no GCC or working fetchurl. This is
149 # because we need a stdenv to build the GCC wrapper and fetchurl.
000150 (prevStage: stageFun prevStage {
151 name = "bootstrap-stage0";
152···202 # If we ever need to use a package from more than one stage back, we
203 # simply re-export those packages in the middle stage(s) using the
204 # overrides attribute and the inherit syntax.
000205 (prevStage: stageFun prevStage {
206 name = "bootstrap-stage1";
207···228229 # 2nd stdenv that contains our own rebuilt binutils and is used for
230 # compiling our own Glibc.
0000231 (prevStage: stageFun prevStage {
232 name = "bootstrap-stage2";
233···296 # Construct a third stdenv identical to the 2nd, except that this
297 # one uses the rebuilt Glibc from stage2. It still uses the recent
298 # binutils and rest of the bootstrap tools, including GCC.
0000299 (prevStage: stageFun prevStage {
300 name = "bootstrap-stage3";
301···332333 # Construct a fourth stdenv that uses the new GCC. But coreutils is
334 # still from the bootstrap tools.
00000000000335 (prevStage: stageFun prevStage {
336 name = "bootstrap-stage4";
337···388 # When updating stdenvLinux, make sure that the result has no
389 # dependency (`nix-store -qR') on bootstrapTools or the first
390 # binutils built.
00000000000391 (prevStage: {
392 inherit config overlays;
393 stdenv = import ../generic rec {
···1# This file constructs the standard build environment for the
2+# Linux platform. It's completely pure; that is, it relies on no
3# external (non-Nix) tools, such as /usr/bin/gcc, and it contains a C
4# compiler and linker that do not search in default locations,
5# ensuring purity of components produced by it.
6+#
7+# It starts from prebuilt seed bootstrapFiles and creates a series of
8+# nixpkgs instances (stages) to gradually rebuild stdenv, which
9+# is used to build all other packages (including the bootstrapFiles).
10+#
11+# Goals of the bootstrap process:
12+# 1. final stdenv must not reference any of the bootstrap files.
13+# 2. final stdenv must not contain any of the bootstrap files
14+# (the only current violation is libgcc_s.so in glibc).
15+# 3. final stdenv must not contain any of the files directly
16+# generated by the bootstrap code generators (assembler, linker,
17+# compiler). The only current violations are: libgcc_s.so in glibc,
18+# the lib{mpfr,mpc,gmp,isl} which are statically linked
19+# into the final gcc).
20+#
21+# These goals ensure that final packages and final stdenv are built
22+# exclusively using nixpkgs package definitions and don't depend
23+# on bootstrapTools (via direct references, inclusion
24+# of copied code, or code compiled directly by bootstrapTools).
25+#
26+# Stages are described below along with their definitions.
27+#
28+# Debugging stdenv dependency graph:
29+# An useful tool to explore dependencies across stages is to use
30+# '__bootPackages' attribute of 'stdenv. Examples of last 3 stages:
31+# - stdenv
32+# - stdenv.__bootPackages.stdenv
33+# - stdenv.__bootPackages.stdenv.__bootPackages.stdenv
34+# - ... and so on.
35+#
36+# To explore build-time dependencies in graphical form one can use
37+# the following:
38+# $ nix-store --query --graph $(nix-instantiate -A stdenv) |
39+# grep -P -v '[.]sh|[.]patch|bash|[.]tar' | # avoid clutter
40+# dot -Tsvg > stdenv-final.svg
41+#
42+# To find all the packages built by a particular stdenv instance:
43+# $ for stage in 0 1 2 3 4; do
44+# echo "stage${stage} used in:"
45+# nix-store --query --graph $(nix-instantiate -A stdenv) |
46+# grep -P ".*bootstrap-stage${stage}-stdenv.*->.*" |
47+# sed 's/"[0-9a-z]\{32\}-/"/g'
48+# done
49+#
50+# To verify which stdenv was used to build a given final package:
51+# $ nix-store --query --graph $(nix-instantiate -A stdenv) |
52+# grep -P -v '[.]sh|[.]patch|bash|[.]tar' |
53+# grep -P '.*stdenv.*->.*glibc-2'
54+# "...-bootstrap-stage2-stdenv-linux.drv" -> "...-glibc-2.35-224.drv";
55+#
56+# For a TUI (rather than CLI) view, you can use:
57+#
58+# $ nix-tree --derivation $(nix-instantiate -A stdenv)
59{ lib
60, localSystem, crossSystem, config, overlays, crossOverlays ? []
61···200201 # Build a dummy stdenv with no GCC or working fetchurl. This is
202 # because we need a stdenv to build the GCC wrapper and fetchurl.
203+ #
204+ # resulting stage0 stdenv:
205+ # - coreutils, binutils, glibc, gcc: from bootstrapFiles
206 (prevStage: stageFun prevStage {
207 name = "bootstrap-stage0";
208···258 # If we ever need to use a package from more than one stage back, we
259 # simply re-export those packages in the middle stage(s) using the
260 # overrides attribute and the inherit syntax.
261+ #
262+ # resulting stage1 stdenv:
263+ # - coreutils, binutils, glibc, gcc: from bootstrapFiles
264 (prevStage: stageFun prevStage {
265 name = "bootstrap-stage1";
266···287288 # 2nd stdenv that contains our own rebuilt binutils and is used for
289 # compiling our own Glibc.
290+ #
291+ # resulting stage2 stdenv:
292+ # - coreutils, glibc, gcc: from bootstrapFiles
293+ # - binutils: from nixpkgs, built by bootstrapFiles toolchain
294 (prevStage: stageFun prevStage {
295 name = "bootstrap-stage2";
296···359 # Construct a third stdenv identical to the 2nd, except that this
360 # one uses the rebuilt Glibc from stage2. It still uses the recent
361 # binutils and rest of the bootstrap tools, including GCC.
362+ #
363+ # resulting stage3 stdenv:
364+ # - coreutils, gcc: from bootstrapFiles
365+ # - glibc, binutils: from nixpkgs, built by bootstrapFiles toolchain
366 (prevStage: stageFun prevStage {
367 name = "bootstrap-stage3";
368···399400 # Construct a fourth stdenv that uses the new GCC. But coreutils is
401 # still from the bootstrap tools.
402+ #
403+ # resulting stage4 stdenv:
404+ # - coreutils: from bootstrapFiles
405+ # - glibc, binutils: from nixpkgs, built by bootstrapFiles toolchain
406+ # - gcc: from nixpkgs, built by bootstrapFiles toolchain. Can assume
407+ # it has almost no code from bootstrapTools as gcc bootstraps
408+ # internally. The only exceptions are crt files from glibc
409+ # built by bootstrapTools used to link executables and libraries,
410+ # and the bootstrapTools-built, statically-linked
411+ # lib{mpfr,mpc,gmp,isl}.a which are linked into the final gcc
412+ # (see commit cfde88976ba4cddd01b1bb28b40afd12ea93a11d).
413 (prevStage: stageFun prevStage {
414 name = "bootstrap-stage4";
415···466 # When updating stdenvLinux, make sure that the result has no
467 # dependency (`nix-store -qR') on bootstrapTools or the first
468 # binutils built.
469+ #
470+ # resulting stage5 (final) stdenv:
471+ # - coreutils, binutils: from nixpkgs, built by nixpkgs toolchain
472+ # - glibc: from nixpkgs, built by bootstrapFiles toolchain
473+ # - gcc: from nixpkgs, built by bootstrapFiles toolchain. Can assume
474+ # it has almost no code from bootstrapTools as gcc bootstraps
475+ # internally. The only exceptions are crt files from glibc
476+ # built by bootstrapTools used to link executables and libraries,
477+ # and the bootstrapTools-built, statically-linked
478+ # lib{mpfr,mpc,gmp,isl}.a which are linked into the final gcc
479+ # (see commit cfde88976ba4cddd01b1bb28b40afd12ea93a11d).
480 (prevStage: {
481 inherit config overlays;
482 stdenv = import ../generic rec {