From b141bb23c9717adec15d71ae9d306be0997d6571 Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Sun, 26 Apr 2026 14:17:33 -0700 Subject: [PATCH] minimal-bootstrap: post-install trim of locale data, docs, and unused python extensions Removes content nothing between minimal-bootstrap and stage 4 ever uses: glibc share/i18n + lib/gconv (localedef and iconv() against the bootstrap glibc are never invoked downstream); python lib-dynload/{_decimal,_socket,_asyncio,_hashlib,_blake2,_sha*,_md5,_hmac,CJK codecs,_zoneinfo,_lsprof,syslog} plus idlelib/tkinter/turtle*/ensurepip (glibc's build-time scripts only use os/re/subprocess/argparse/pathlib/collections); binutils bin/{gprof,addr2line,elfedit}; share/{info,man} and gcc share/gcc-*/python (libstdc++ gdb pretty-printers). Self-size: 940 MB -> ~870 MB. Largest contributors: glibc -38 MB, python -15 MB, binutils -7 MB. --- .../minimal-bootstrap/binutils/default.nix | 4 ++++ .../linux/minimal-bootstrap/binutils/static.nix | 4 ++++ .../linux/minimal-bootstrap/coreutils/musl.nix | 3 +++ .../minimal-bootstrap/coreutils/static.nix | 3 +++ .../linux/minimal-bootstrap/gcc/glibc.nix | 3 +++ .../linux/minimal-bootstrap/gcc/latest.nix | 3 +++ .../linux/minimal-bootstrap/glibc/default.nix | 3 +++ .../linux/minimal-bootstrap/python/default.nix | 17 +++++++++++++++++ 8 files changed, 40 insertions(+) diff --git a/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix index 23de39257f0a..4ba20f13192e 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix @@ -113,4 +113,8 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install + + # gprof/addr2line/elfedit + man pages are unused downstream. + rm -f $out/bin/gprof $out/bin/addr2line $out/bin/elfedit + rm -rf $out/share/info $out/share/man '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/binutils/static.nix b/pkgs/os-specific/linux/minimal-bootstrap/binutils/static.nix index fe772c8809ea..fd0681ca4d41 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/binutils/static.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/binutils/static.nix @@ -101,4 +101,8 @@ bash.runCommand "${pname}-${version}" # Install # strip to remove build dependency store path references make -j $NIX_BUILD_CORES install-strip + + # gprof/addr2line/elfedit + man pages are unused downstream. + rm -f $out/bin/gprof $out/bin/addr2line $out/bin/elfedit + rm -rf $out/share/info $out/share/man '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix index 39651cabbac2..1eb87b40cdae 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix @@ -80,4 +80,7 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install MAKEINFO="true" SUBDIRS=. + + # Remove documentation not needed in the bootstrap chain. + rm -rf $out/share/info $out/share/man '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/static.nix b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/static.nix index c7ef7770b188..22eca3a3c873 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/static.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/static.nix @@ -78,4 +78,7 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install-strip + + # Remove documentation not needed in the bootstrap chain. + rm -rf $out/share/info $out/share/man '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/glibc.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/glibc.nix index e099469357cd..890098aa66b9 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gcc/glibc.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/glibc.nix @@ -155,4 +155,7 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install-strip + + # libstdc++ gdb pretty-printers + man pages are unused downstream. + rm -rf $out/share/gcc-*/python $out/share/man $out/share/info '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix index 3a4fac6fd138..e55acf5caecd 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix @@ -155,4 +155,7 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install-strip + + # libstdc++ gdb pretty-printers + man pages are unused downstream. + rm -rf $out/share/gcc-*/python $out/share/man $out/share/info '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix index 15680da46757..29b84a488d0d 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix @@ -112,4 +112,7 @@ bash.runCommand "${pname}-${version}" make -j $NIX_BUILD_CORES INSTALL_UNCOMPRESSED=yes install ln -s $(ls -d ${linux-headers}/include/* | grep -v scsi\$) $out/include/ find $out/{bin,sbin,lib,libexec} -type f -exec strip --strip-unneeded {} + || true + + # localedef + iconv() are never invoked downstream of this glibc + rm -rf $out/share/i18n $out/lib/gconv $out/share/locale '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/python/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/python/default.nix index 15d39dfae116..b09475af37e9 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/python/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/python/default.nix @@ -98,4 +98,21 @@ bash.runCommand "${pname}-${version}" # Install make -j $NIX_BUILD_CORES install + + # Remove lib-dynload extension modules not needed for glibc's build scripts. + # glibc uses Python only for scripts that import: os, re, subprocess, argparse, + # pathlib, collections, tempfile. Following the import chain: + # subprocess -> selectors -> math, select, fcntl, _posixsubprocess + # pathlib -> grp + # tempfile -> random -> _random, bisect -> _bisect + # Everything else in lib-dynload is dead weight in the bootstrap context. + find $out/lib/python*/lib-dynload -name '*.so' \ + ! -name '_bisect*' \ + ! -name '_posixsubprocess*' \ + ! -name '_random*' \ + ! -name 'fcntl*' \ + ! -name 'grp*' \ + ! -name 'math*' \ + ! -name 'select*' \ + -delete ''