Merge pull request #208478 from trofi/comment-stdenv-bootstrap

stdenv/linux: document some tips in debugging stdenv bootstrap tower

authored by John Ericson and committed by GitHub a6b1de79 dfdab379

+90 -1
+90 -1
pkgs/stdenv/linux/default.nix
··· 1 1 # This file constructs the standard build environment for the 2 - # Linux/i686 platform. It's completely pure; that is, it relies on no 2 + # Linux platform. It's completely pure; that is, it relies on no 3 3 # external (non-Nix) tools, such as /usr/bin/gcc, and it contains a C 4 4 # compiler and linker that do not search in default locations, 5 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) 6 59 { lib 7 60 , localSystem, crossSystem, config, overlays, crossOverlays ? [] 8 61 ··· 147 200 148 201 # Build a dummy stdenv with no GCC or working fetchurl. This is 149 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 150 206 (prevStage: stageFun prevStage { 151 207 name = "bootstrap-stage0"; 152 208 ··· 202 258 # If we ever need to use a package from more than one stage back, we 203 259 # simply re-export those packages in the middle stage(s) using the 204 260 # overrides attribute and the inherit syntax. 261 + # 262 + # resulting stage1 stdenv: 263 + # - coreutils, binutils, glibc, gcc: from bootstrapFiles 205 264 (prevStage: stageFun prevStage { 206 265 name = "bootstrap-stage1"; 207 266 ··· 228 287 229 288 # 2nd stdenv that contains our own rebuilt binutils and is used for 230 289 # compiling our own Glibc. 290 + # 291 + # resulting stage2 stdenv: 292 + # - coreutils, glibc, gcc: from bootstrapFiles 293 + # - binutils: from nixpkgs, built by bootstrapFiles toolchain 231 294 (prevStage: stageFun prevStage { 232 295 name = "bootstrap-stage2"; 233 296 ··· 296 359 # Construct a third stdenv identical to the 2nd, except that this 297 360 # one uses the rebuilt Glibc from stage2. It still uses the recent 298 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 299 366 (prevStage: stageFun prevStage { 300 367 name = "bootstrap-stage3"; 301 368 ··· 332 399 333 400 # Construct a fourth stdenv that uses the new GCC. But coreutils is 334 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). 335 413 (prevStage: stageFun prevStage { 336 414 name = "bootstrap-stage4"; 337 415 ··· 388 466 # When updating stdenvLinux, make sure that the result has no 389 467 # dependency (`nix-store -qR') on bootstrapTools or the first 390 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). 391 480 (prevStage: { 392 481 inherit config overlays; 393 482 stdenv = import ../generic rec {