lol

treewide: Leverage new top-level `libc` in bootstrap, and simplify

Picking up where #414321 left off, we can now simplify some things by
using `pkgs.libc` or `targetPackages.libc` consistently.

Individual packages should probably continue using `stdenv.cc.libc`, for
now at least, since it is possible they are given a `stdenv.cc` with an
alternative libc, but for the treewide code, the top-level `libc`
package is preferable and easier to work with.

Co-authored-by: Tristan Ross <rosscomputerguy@protonmail.com>

+93 -80
+1 -1
pkgs/servers/x11/xorg/overrides.nix
··· 242 242 buildPackages.stdenv.cc 243 243 ] 244 244 ++ lib.optionals stdenv.hostPlatform.isStatic [ 245 - (xorg.buildPackages.stdenv.cc.libc.static or null) 245 + (xorg.buildPackages.libc.static or null) 246 246 ]; 247 247 preConfigure = '' 248 248 sed 's,^as_dummy.*,as_dummy="\$PATH",' -i configure
+6 -2
pkgs/stdenv/darwin/default.nix
··· 132 132 bintools = prevStage.darwin.binutils; 133 133 134 134 isClang = true; 135 - libc = prevStage.darwin.libSystem; 135 + inherit (prevStage) libc; 136 136 inherit (prevStage.llvmPackages) libcxx; 137 137 138 138 inherit lib; ··· 582 582 583 583 assert allDeps isFromNixpkgs [ 584 584 (sdkPackagesNoCC prevStage) 585 - { inherit (prevStage.darwin) binutils libSystem; } 585 + { 586 + inherit (prevStage.darwin) binutils libSystem; 587 + inherit (prevStage) libc; 588 + } 586 589 ]; 587 590 588 591 stageFun prevStage { ··· 1260 1263 assert isBuiltByNixpkgsCompiler prevStage.darwin.sigtool; 1261 1264 1262 1265 assert isFromNixpkgs prevStage.darwin.libSystem; 1266 + assert isFromNixpkgs prevStage.libc; 1263 1267 assert isFromNixpkgs prevStage.darwin.binutils-unwrapped; 1264 1268 1265 1269 assert isBuiltByNixpkgsCompiler prevStage.llvmPackages.clang-unwrapped;
+28 -16
pkgs/stdenv/linux/default.nix
··· 158 158 isFromBootstrapFiles = true; 159 159 }; 160 160 161 - getLibc = stage: stage.${localSystem.libc}; 162 - 163 161 # This function builds the various standard environments used during 164 162 # the bootstrap. In all stages, we build an stdenv and the package 165 163 # set that can be built with that stdenv. ··· 207 205 cc = prevStage.gcc-unwrapped; 208 206 bintools = prevStage.binutils; 209 207 isGNU = true; 210 - libc = getLibc prevStage; 208 + inherit (prevStage) libc; 211 209 inherit lib; 212 210 inherit (prevStage) coreutils gnugrep; 213 211 stdenvNoCC = prevStage.ccWrapperStdenv; ··· 221 219 postFixup = 222 220 (a.postFixup or "") 223 221 + '' 224 - echo "--sysroot=${lib.getDev (getLibc prevStage)}" >> $out/nix-support/cc-cflags 222 + echo "--sysroot=${lib.getDev prevStage.libc}" >> $out/nix-support/cc-cflags 225 223 ''; 226 224 } 227 225 ); ··· 293 291 nativeTools = false; 294 292 nativeLibc = false; 295 293 expand-response-params = ""; 296 - libc = getLibc self; 297 294 inherit lib; 298 - inherit (self) stdenvNoCC coreutils gnugrep; 295 + inherit (self) 296 + stdenvNoCC 297 + coreutils 298 + gnugrep 299 + libc 300 + ; 299 301 bintools = bootstrapTools; 300 302 runtimeShell = "${bootstrapTools}/bin/bash"; 301 303 }; ··· 320 322 # previous stage0 stdenv: 321 323 assert isFromBootstrapFiles prevStage.binutils.bintools; 322 324 assert isFromBootstrapFiles prevStage."${localSystem.libc}"; 325 + assert isFromBootstrapFiles prevStage.libc; 323 326 assert isFromBootstrapFiles prevStage.gcc-unwrapped; 324 327 assert isFromBootstrapFiles prevStage.coreutils; 325 328 assert isFromBootstrapFiles prevStage.gnugrep; ··· 339 342 binutils 340 343 ; 341 344 342 - ${localSystem.libc} = getLibc prevStage; 345 + ${localSystem.libc} = prevStage.${localSystem.libc}; 343 346 344 347 # A threaded perl build needs glibc/libpthread_nonshared.a, 345 348 # which is not included in bootstrapTools, so disable threading. ··· 374 377 prevStage: 375 378 assert isBuiltByBootstrapFilesCompiler prevStage.binutils-unwrapped; 376 379 assert isFromBootstrapFiles prevStage."${localSystem.libc}"; 380 + assert isFromBootstrapFiles prevStage.libc; 377 381 assert isFromBootstrapFiles prevStage.gcc-unwrapped; 378 382 assert isFromBootstrapFiles prevStage.coreutils; 379 383 assert isFromBootstrapFiles prevStage.gnugrep; ··· 393 397 perl 394 398 patchelf 395 399 ; 396 - ${localSystem.libc} = getLibc prevStage; 400 + ${localSystem.libc} = prevStage.${localSystem.libc}; 397 401 gmp = super.gmp.override { cxx = false; }; 398 402 # This stage also rebuilds binutils which will of course be used only in the next stage. 399 403 # We inherit this until stage3, in stage4 it will be rebuilt using the adjacent bash/runtimeShell pkg. ··· 484 488 # previous stage1 stdenv: 485 489 assert isBuiltByBootstrapFilesCompiler prevStage.binutils-unwrapped; 486 490 assert isFromBootstrapFiles prevStage."${localSystem.libc}"; 491 + assert isFromBootstrapFiles prevStage.libc; 487 492 assert isBuiltByBootstrapFilesCompiler prevStage.gcc-unwrapped; 488 493 assert isFromBootstrapFiles prevStage.coreutils; 489 494 assert isFromBootstrapFiles prevStage.gnugrep; ··· 508 513 doCheck = false; 509 514 }); 510 515 516 + # Avoids infinite recursion, as this is in the build-time dependencies of libc. 517 + libiconv = self.libcIconv prevStage.libc; 518 + 511 519 # We need libidn2 and its dependency libunistring as glibc dependency. 512 520 # To avoid the cycle, we build against bootstrap libc, nuke references, 513 521 # and use the result as input for our final glibc. We also pass this pair ··· 538 546 binutils = prevStage.binutils.override { 539 547 # Rewrap the binutils with the new glibc, so both the next 540 548 # stage's wrappers use it. 541 - libc = getLibc self; 549 + inherit (self) libc; 542 550 543 551 # Unfortunately, when building gcc in the next stage, its LTO plugin 544 552 # would use the final libc but `ld` would use the bootstrap one, ··· 557 565 mkdir -p "$out"/bin 558 566 cp -a '${prevStage.bintools.bintools}'/bin/* "$out"/bin/ 559 567 chmod +w "$out"/bin/ld.bfd 560 - patchelf --set-interpreter '${getLibc self}'/lib/ld*.so.? \ 561 - --set-rpath "${getLibc self}/lib:$(patchelf --print-rpath "$out"/bin/ld.bfd)" \ 568 + patchelf --set-interpreter '${self.libc}'/lib/ld*.so.? \ 569 + --set-rpath "${self.libc}/lib:$(patchelf --print-rpath "$out"/bin/ld.bfd)" \ 562 570 "$out"/bin/ld.bfd 563 571 ''; 564 572 }; ··· 589 597 # previous stage2 stdenv: 590 598 assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped; 591 599 assert isBuiltByNixpkgsCompiler prevStage.${localSystem.libc}; 600 + assert isBuiltByNixpkgsCompiler prevStage.libc; 592 601 assert isBuiltByBootstrapFilesCompiler prevStage.gcc-unwrapped; 593 602 assert isFromBootstrapFiles prevStage.coreutils; 594 603 assert isFromBootstrapFiles prevStage.gnugrep; ··· 625 634 gmp = super.gmp.override { cxx = false; }; 626 635 } 627 636 // { 628 - ${localSystem.libc} = getLibc prevStage; 637 + ${localSystem.libc} = prevStage.${localSystem.libc}; 629 638 gcc-unwrapped = 630 639 (super.gcc-unwrapped.override ( 631 640 commonGccOverrides ··· 661 670 # previous stage3 stdenv: 662 671 assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped; 663 672 assert isBuiltByNixpkgsCompiler prevStage.${localSystem.libc}; 673 + assert isBuiltByNixpkgsCompiler prevStage.libc; 664 674 assert isBuiltByNixpkgsCompiler prevStage.gcc-unwrapped; 665 675 assert isFromBootstrapFiles prevStage.coreutils; 666 676 assert isFromBootstrapFiles prevStage.gnugrep; ··· 684 694 libidn2 685 695 libunistring 686 696 ; 687 - ${localSystem.libc} = getLibc prevStage; 697 + ${localSystem.libc} = prevStage.${localSystem.libc}; 688 698 # Since this is the first fresh build of binutils since stage2, our own runtimeShell will be used. 689 699 binutils = super.binutils.override { 690 700 # Build expand-response-params with last stage like below ··· 702 712 inherit (prevStage) expand-response-params; 703 713 cc = prevStage.gcc-unwrapped; 704 714 bintools = self.binutils; 705 - libc = getLibc self; 706 715 inherit lib; 707 716 inherit (self) 708 717 stdenvNoCC 709 718 coreutils 710 719 gnugrep 711 720 runtimeShell 721 + libc 712 722 ; 713 723 fortify-headers = self.fortify-headers; 714 724 }; ··· 736 746 # which applies here as well. 737 747 assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped; 738 748 assert isBuiltByNixpkgsCompiler prevStage.${localSystem.libc}; 749 + assert isBuiltByNixpkgsCompiler prevStage.libc; 739 750 assert isBuiltByNixpkgsCompiler prevStage.gcc-unwrapped; 740 751 assert isBuiltByNixpkgsCompiler prevStage.coreutils; 741 752 assert isBuiltByNixpkgsCompiler prevStage.gnugrep; ··· 843 854 libunistring 844 855 ] 845 856 # More complicated cases 846 - ++ (map (x: lib.getOutput x (getLibc prevStage)) [ 857 + ++ (map (x: lib.getOutput x (prevStage.libc)) [ 847 858 "out" 848 859 "dev" 849 860 "bin" ··· 893 904 libunistring 894 905 ; 895 906 inherit (prevStage.gnugrep) pcre2; 896 - ${localSystem.libc} = getLibc prevStage; 907 + ${localSystem.libc} = prevStage.${localSystem.libc}; 897 908 898 909 # Hack: avoid libidn2.{bin,dev} referencing bootstrap tools. There's a logical cycle. 899 910 libidn2 = import ../../development/libraries/libidn2/no-bootstrap-reference.nix { ··· 925 936 # which applies here as well. 926 937 assert isBuiltByNixpkgsCompiler prevStage.binutils-unwrapped; 927 938 assert isBuiltByNixpkgsCompiler prevStage.${localSystem.libc}; 939 + assert isBuiltByNixpkgsCompiler prevStage.libc; 928 940 assert isBuiltByNixpkgsCompiler prevStage.gcc-unwrapped; 929 941 assert isBuiltByNixpkgsCompiler prevStage.coreutils; 930 942 assert isBuiltByNixpkgsCompiler prevStage.gnugrep;
+6 -3
pkgs/stdenv/linux/make-bootstrap-tools.nix
··· 3 3 }: 4 4 5 5 let 6 - inherit (pkgs) lib stdenv config; 7 - 8 - libc = pkgs.stdenv.cc.libc; 6 + inherit (pkgs) 7 + lib 8 + stdenv 9 + config 10 + libc 11 + ; 9 12 10 13 patchelf = pkgs.patchelf.overrideAttrs (previousAttrs: { 11 14 NIX_CFLAGS_COMPILE = (previousAttrs.NIX_CFLAGS_COMPILE or [ ]) ++ [
+49 -53
pkgs/top-level/all-packages.nix
··· 6181 6181 wrapBintoolsWith = 6182 6182 { 6183 6183 bintools, 6184 - libc ? if stdenv.targetPlatform != stdenv.hostPlatform then targetPackages.libc else stdenv.cc.libc, 6184 + libc ? targetPackages.libc or pkgs.libc, 6185 6185 ... 6186 6186 }@extraArgs: 6187 6187 callPackage ../build-support/bintools-wrapper ( ··· 8198 8198 8199 8199 # We can choose: 8200 8200 libc = 8201 - if stdenv.hostPlatform == stdenv.buildPlatform then 8202 - # TODO get rid of this branch after the native boostrap is reworked 8203 - stdenv.cc.libc 8201 + let 8202 + inherit (stdenv.hostPlatform) libc; 8203 + # libc is hackily often used from the previous stage. This `or` 8204 + # hack fixes the hack, *sigh*. 8205 + in 8206 + if libc == null then 8207 + null 8208 + else if libc == "glibc" then 8209 + glibc 8210 + else if libc == "bionic" then 8211 + bionic 8212 + else if libc == "uclibc" then 8213 + uclibc 8214 + else if libc == "avrlibc" then 8215 + avrlibc 8216 + else if libc == "newlib" && stdenv.hostPlatform.isMsp430 then 8217 + msp430Newlib 8218 + else if libc == "newlib" && stdenv.hostPlatform.isVc4 then 8219 + vc4-newlib 8220 + else if libc == "newlib" && stdenv.hostPlatform.isOr1k then 8221 + or1k-newlib 8222 + else if libc == "newlib" then 8223 + newlib 8224 + else if libc == "newlib-nano" then 8225 + newlib-nano 8226 + else if libc == "musl" then 8227 + musl 8228 + else if libc == "msvcrt" then 8229 + windows.mingw_w64 8230 + else if libc == "ucrt" then 8231 + windows.mingw_w64 8232 + else if libc == "libSystem" then 8233 + if stdenv.hostPlatform.useiOSPrebuilt then darwin.iosSdkPkgs.libraries else darwin.libSystem 8234 + else if libc == "fblibc" then 8235 + freebsd.libc 8236 + else if libc == "oblibc" then 8237 + openbsd.libc 8238 + else if libc == "nblibc" then 8239 + netbsd.libc 8240 + else if libc == "wasilibc" then 8241 + wasilibc 8242 + else if libc == "relibc" then 8243 + relibc 8244 + else if name == "llvm" then 8245 + llvmPackages_20.libc 8204 8246 else 8205 - let 8206 - inherit (stdenv.hostPlatform) libc; 8207 - # libc is hackily often used from the previous stage. This `or` 8208 - # hack fixes the hack, *sigh*. 8209 - in 8210 - if libc == null then 8211 - null 8212 - else if libc == "glibc" then 8213 - glibc 8214 - else if libc == "bionic" then 8215 - bionic 8216 - else if libc == "uclibc" then 8217 - uclibc 8218 - else if libc == "avrlibc" then 8219 - avrlibc 8220 - else if libc == "newlib" && stdenv.hostPlatform.isMsp430 then 8221 - msp430Newlib 8222 - else if libc == "newlib" && stdenv.hostPlatform.isVc4 then 8223 - vc4-newlib 8224 - else if libc == "newlib" && stdenv.hostPlatform.isOr1k then 8225 - or1k-newlib 8226 - else if libc == "newlib" then 8227 - newlib 8228 - else if libc == "newlib-nano" then 8229 - newlib-nano 8230 - else if libc == "musl" then 8231 - musl 8232 - else if libc == "msvcrt" then 8233 - windows.mingw_w64 8234 - else if libc == "ucrt" then 8235 - windows.mingw_w64 8236 - else if libc == "libSystem" then 8237 - if stdenv.hostPlatform.useiOSPrebuilt then darwin.iosSdkPkgs.libraries else darwin.libSystem 8238 - else if libc == "fblibc" then 8239 - freebsd.libc 8240 - else if libc == "oblibc" then 8241 - openbsd.libc 8242 - else if libc == "nblibc" then 8243 - netbsd.libc 8244 - else if libc == "wasilibc" then 8245 - wasilibc 8246 - else if libc == "relibc" then 8247 - relibc 8248 - else if name == "llvm" then 8249 - llvmPackages_20.libc 8250 - else 8251 - throw "Unknown libc ${libc}"; 8247 + throw "Unknown libc ${libc}"; 8252 8248 8253 8249 threads = 8254 8250 lib.optionalAttrs (stdenv.hostPlatform.isMinGW && !(stdenv.hostPlatform.useLLVM or false)) ··· 8772 8768 "fblibc" 8773 8769 ] 8774 8770 then 8775 - libcIconv (if stdenv.hostPlatform != stdenv.buildPlatform then libc else stdenv.cc.libc) 8771 + libcIconv pkgs.libc 8776 8772 else if stdenv.hostPlatform.isDarwin then 8777 8773 darwin.libiconv 8778 8774 else ··· 8798 8794 "musl" 8799 8795 ] 8800 8796 then 8801 - lib.getBin stdenv.cc.libc 8797 + lib.getBin libc 8802 8798 else if stdenv.hostPlatform.isDarwin then 8803 8799 lib.getBin libiconv 8804 8800 else if stdenv.hostPlatform.isFreeBSD then
+1 -2
pkgs/top-level/darwin-packages.nix
··· 56 56 }; 57 57 58 58 binutils = pkgs.wrapBintoolsWith { 59 - libc = 60 - if stdenv.targetPlatform != stdenv.hostPlatform then targetPackages.libc else pkgs.stdenv.cc.libc; 59 + inherit (targetPackages) libc; 61 60 bintools = self.binutils-unwrapped; 62 61 }; 63 62
+2 -3
pkgs/top-level/unixtools.nix
··· 95 95 linux = pkgs.util-linux; 96 96 }; 97 97 getconf = { 98 - linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc else pkgs.netbsd.getconf; 98 + linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.libc else pkgs.netbsd.getconf; 99 99 darwin = pkgs.darwin.system_cmds; 100 100 # I don't see any obvious arg exec in the doc/manpage 101 101 binlore = '' ··· 103 103 ''; 104 104 }; 105 105 getent = { 106 - linux = 107 - if stdenv.hostPlatform.libc == "glibc" then pkgs.stdenv.cc.libc.getent else pkgs.netbsd.getent; 106 + linux = if stdenv.hostPlatform.libc == "glibc" then pkgs.libc.getent else pkgs.netbsd.getent; 108 107 darwin = pkgs.netbsd.getent; 109 108 freebsd = pkgs.freebsd.getent; 110 109 openbsd = pkgs.openbsd.getent;