diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index f7607633618b..d96df87c32bc 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -142,6 +142,14 @@ lib.makeScope gawk = gawk-mes; }; + glibc = callPackage ./glibc { + gcc = gcc-latest; + gnumake = gnumake-musl; + gnutar = gnutar-latest; + gnugrep = gnugrep-static; + gawk = gawk-static; + }; + gnugrep = callPackage ./gnugrep { bash = bash_2_05; tinycc = tinycc-mes; @@ -323,6 +331,7 @@ lib.makeScope echo ${gcc46-cxx.tests.hello-world} echo ${gcc8.tests.hello-world} echo ${gcc-latest.tests.hello-world} + echo ${glibc.tests.hello-world} echo ${gnugrep.tests.get-version} echo ${gnugrep-static.tests.get-version} echo ${gnum4.tests.get-version} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix new file mode 100644 index 000000000000..c2cfa6fc018c --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix @@ -0,0 +1,112 @@ +{ + lib, + buildPlatform, + hostPlatform, + fetchurl, + bash, + gcc, + binutils, + linux-headers, + gnumake, + gnused, + gnugrep, + gawk, + diffutils, + findutils, + python, + bison, + gnutar, + xz, +}: +let + pname = "glibc"; + version = "2.38"; + + src = fetchurl { + url = "mirror://gnu/libc/glibc-${version}.tar.xz"; + hash = "sha256-+4KZiZiyspllRnvBtp0VLpwwfSzzAcnq+0VVt3DvP9I="; + }; + + linkerFile = + { + x86_64-linux = "ld-linux-x86-64"; + i686-linux = "ld-linux"; + } + .${buildPlatform.system}; +in +bash.runCommand "${pname}-${version}" + { + inherit pname version; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnused + gnugrep + gawk + diffutils + findutils + python + bison + gnutar + xz + ]; + + passthru.tests.hello-world = + result: + bash.runCommand "${pname}-simple-program-${version}" + { + nativeBuildInputs = [ + gcc + binutils + ]; + } + '' + cat <> test.c + #include + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + gcc \ + -Wl,--dynamic-linker=${result}/lib/${linkerFile}.so.2 \ + -B${result}/lib \ + -I${result}/include \ + -o test test.c + ./test + mkdir $out + ''; + + meta = { + description = "The GNU C Library"; + homepage = "https://www.gnu.org/software/libc/"; + license = lib.licenses.lgpl2Plus; + platforms = lib.platforms.linux; + teams = [ lib.teams.minimal-bootstrap ]; + }; + } + '' + # Unpack + tar xf ${src} + cd glibc-${version} + + # Configure + mkdir build + cd build + # libstdc++.so is built against musl and fails to link + export CXX=false + bash ../configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --with-headers=${linux-headers}/include + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES INSTALL_UNCOMPRESSED=yes install + find $out/{bin,sbin,lib,libexec} -type f -exec strip --strip-unneeded {} + || true + ''