From 5171b87765b841a16833e8f089120ef784acbd6d Mon Sep 17 00:00:00 2001 From: Emily Trau Date: Tue, 12 Sep 2023 22:40:23 -0700 Subject: [PATCH] minimal-bootstrap.musl: init at 1.2.4 --- .../linux/minimal-bootstrap/default.nix | 6 ++ .../linux/minimal-bootstrap/musl/default.nix | 87 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index b8807eec0902..55900f86d21c 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -144,6 +144,11 @@ lib.makeScope mes = lib.recurseIntoAttrs (callPackage ./mes { }); mes-libc = callPackage ./mes/libc.nix { }; + musl = callPackage ./musl { + gcc = gcc46; + gawk = gawk-mes; + }; + stage0-posix = callPackage ./stage0-posix { }; inherit (self.stage0-posix) kaem m2libc mescc-tools mescc-tools-extra; @@ -180,6 +185,7 @@ lib.makeScope echo ${gzip.tests.get-version} echo ${heirloom.tests.get-version} echo ${mes.compiler.tests.get-version} + echo ${musl.tests.hello-world} echo ${tinycc-mes.compiler.tests.chain} echo ${xz.tests.get-version} mkdir ''${out} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix new file mode 100644 index 000000000000..c252d60328e9 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix @@ -0,0 +1,87 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, gcc +, binutils +, gnumake +, gnugrep +, gnused +, gawk +, gnutar +, gzip +}: +let + pname = "musl"; + version = "1.2.4"; + + src = fetchurl { + url = "https://musl.libc.org/releases/musl-${version}.tar.gz"; + hash = "sha256-ejXq4z1TcqfA2hGI3nmHJvaIJVE7euPr6XqqpSEU8Dk="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnused + gnugrep + gawk + gnutar + gzip + ]; + + 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 -static -B${result}/lib -I${result}/include -o test test.c + ./test + mkdir $out + ''; + + meta = with lib; { + description = "An efficient, small, quality libc implementation"; + homepage = "https://musl.libc.org"; + license = licenses.mit; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xzf ${src} + cd musl-${version} + + # Patch + # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix + sed -i 's|/bin/sh|${bash}/bin/bash|' \ + tools/*.sh + # patch popen/system to search in PATH instead of hardcoding /bin/sh + sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \ + src/stdio/popen.c src/process/system.c + sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\ + src/misc/wordexp.c + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} + + # Build + make + + # Install + make install +''