30 # ${libc.src}/sysdeps/unix/sysv/linux/loongarch/lp64/libnsl.abilist does not exist!
31 withLibnsl = !stdenv.hostPlatform.isLoongArch64;
33 stdenv.mkDerivation (finalAttrs: {
34 name = "stdenv-bootstrap-tools";
37 # Increase priority to unblock nixpkgs-unstable
38 # https://github.com/NixOS/nixpkgs/pull/104679#issuecomment-732267288
39 schedulingPriority = 200;
43 buildPackages.nukeReferences
50 mkdir -p $out/bin $out/lib $out/libexec
54 if (stdenv.hostPlatform.libc == "glibc") then
56 # Copy what we need of Glibc.
57 cp -d ${libc.out}/lib/ld*.so* $out/lib
58 cp -d ${libc.out}/lib/libc*.so* $out/lib
59 cp -d ${libc.out}/lib/libc_nonshared.a $out/lib
60 cp -d ${libc.out}/lib/libm*.so* $out/lib
61 cp -d ${libc.out}/lib/libdl*.so* $out/lib
62 cp -d ${libc.out}/lib/librt*.so* $out/lib
63 cp -d ${libc.out}/lib/libpthread*.so* $out/lib
65 + lib.optionalString withLibnsl ''
66 cp -d ${libc.out}/lib/libnsl*.so* $out/lib
69 cp -d ${libc.out}/lib/libutil*.so* $out/lib
70 cp -d ${libc.out}/lib/libnss*.so* $out/lib
71 cp -d ${libc.out}/lib/libresolv*.so* $out/lib
72 # Copy all runtime files to enable non-PIE, PIE, static PIE and profile-generated builds
73 cp -d ${libc.out}/lib/*.o $out/lib
75 # Hacky compat with our current unpack-bootstrap-tools.sh
76 ln -s librt.so "$out"/lib/librt-dummy.so
78 cp -rL ${libc.dev}/include $out
81 # libc can contain linker scripts: find them, copy their deps,
82 # and get rid of absolute paths (nuke-refs would make them useless)
83 local lScripts=$(grep --files-with-matches --max-count=1 'GNU ld script' -R "$out/lib")
84 cp -d -t "$out/lib/" $(cat $lScripts | tr " " "\n" | grep -F '${libc.out}' | sort -u)
85 for f in $lScripts; do
86 substituteInPlace "$f" --replace '${libc.out}/lib/' ""
89 # Hopefully we won't need these.
90 rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
91 find $out/include -name .install -exec rm {} \;
92 find $out/include -name ..install.cmd -exec rm {} \;
93 mv $out/include $out/include-glibc
95 else if (stdenv.hostPlatform.libc == "musl") then
97 # Copy what we need from musl
98 cp ${libc.out}/lib/* $out/lib
99 cp -rL ${libc.dev}/include $out
102 rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
103 find $out/include -name .install -exec rm {} \;
104 find $out/include -name ..install.cmd -exec rm {} \;
105 mv $out/include $out/include-libc
108 throw "unsupported libc for bootstrap tools"
111 # Copy coreutils, bash, etc.
112 cp -d ${coreutilsMinimal.out}/bin/* $out/bin
113 (cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users)
115 cp ${bash.out}/bin/bash $out/bin
116 cp ${findutils.out}/bin/find $out/bin
117 cp ${findutils.out}/bin/xargs $out/bin
118 cp -d ${diffutils.out}/bin/* $out/bin
119 cp -d ${gnused.out}/bin/* $out/bin
120 cp -d ${gnugrep.out}/bin/grep $out/bin
121 cp ${gawk.out}/bin/gawk $out/bin
122 cp -d ${gawk.out}/bin/awk $out/bin
123 cp ${tarMinimal.out}/bin/tar $out/bin
124 cp ${gzip.out}/bin/.gzip-wrapped $out/bin/gzip
125 cp ${bzip2.bin}/bin/bzip2 $out/bin
126 cp -d ${gnumake.out}/bin/* $out/bin
127 cp -d ${patch}/bin/* $out/bin
128 cp ${patchelf}/bin/* $out/bin
130 cp -d ${gnugrep.pcre2.out}/lib/libpcre2*.so* $out/lib # needed by grep
132 # Copy what we need of GCC.
133 cp -d ${bootGCC.out}/bin/gcc $out/bin
134 cp -d ${bootGCC.out}/bin/cpp $out/bin
135 cp -d ${bootGCC.out}/bin/g++ $out/bin
136 cp ${bootGCC.lib}/lib/libgcc_s.so* $out/lib
137 cp -d ${bootGCC.lib}/lib/libstdc++.so* $out/lib
138 cp -d ${bootGCC.out}/lib/libssp.a* $out/lib
139 cp -d ${bootGCC.out}/lib/libssp_nonshared.a $out/lib
140 cp -rd ${bootGCC.out}/lib/gcc $out/lib
141 chmod -R u+w $out/lib
142 rm -f $out/lib/gcc/*/*/include*/linux
143 rm -f $out/lib/gcc/*/*/include*/sound
144 rm -rf $out/lib/gcc/*/*/include*/root
145 rm -f $out/lib/gcc/*/*/include-fixed/asm
146 rm -rf $out/lib/gcc/*/*/plugin
147 #rm -f $out/lib/gcc/*/*/*.a
148 cp -rd ${bootGCC.out}/libexec/* $out/libexec
149 chmod -R u+w $out/libexec
150 rm -rf $out/libexec/gcc/*/*/plugin
151 mkdir -p $out/include
152 cp -rd ${bootGCC.out}/include/c++ $out/include
153 chmod -R u+w $out/include
154 rm -rf $out/include/c++/*/ext/pb_ds
155 rm -rf $out/include/c++/*/ext/parallel
157 cp -d ${gmpxx.out}/lib/libgmp*.so* $out/lib
158 cp -d ${mpfr.out}/lib/libmpfr*.so* $out/lib
159 cp -d ${libmpc.out}/lib/libmpc*.so* $out/lib
160 cp -d ${zlib.out}/lib/libz.so* $out/lib
163 + lib.optionalString (stdenv.hostPlatform.isRiscV) ''
164 # libatomic is required on RiscV platform for C/C++ atomics and pthread
165 # even though they may be translated into native instructions.
166 cp -d ${bootGCC.out}/lib/libatomic.a* $out/lib
170 cp -d ${bzip2.out}/lib/libbz2.so* $out/lib
173 for i in as ld ar ranlib nm strip readelf objdump; do
174 cp ${bootBinutils.out}/bin/$i $out/bin
176 cp -r '${lib.getLib binutils.bintools}'/lib/* "$out/lib/"
180 # Strip executables even further.
181 for i in $out/bin/* $out/libexec/gcc/*/*/*; do
182 if test -x $i -a ! -L $i; then
190 nuke-refs $out/lib/*/*
191 nuke-refs $out/libexec/gcc/*/*/*
192 nuke-refs $out/lib/gcc/*/*/*
193 nuke-refs $out/lib/gcc/*/*/include-fixed/*{,/*}
197 mv $out/.pack $out/pack
200 XZ_OPT="-9 -e" tar cvJf $out/on-server/bootstrap-tools.tar.xz --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 -C $out/pack .
201 cp ${busyboxMinimal}/bin/busybox $out/on-server
202 chmod u+w $out/on-server/busybox
203 nuke-refs $out/on-server/busybox
206 # The result should not contain any references (store paths) so
207 # that we can safely copy them out of the store and to other
208 # locations in the store.
209 allowedReferences = [ ];
213 # Make them their own store paths to test that busybox still works when the binary is named /nix/store/HASH-busybox
214 busybox = runCommand "busybox" { } "cp ${finalAttrs.finalPackage}/on-server/busybox $out";
216 runCommand "bootstrap-tools.tar.xz" { }
217 "cp ${finalAttrs.finalPackage}/on-server/bootstrap-tools.tar.xz $out";