nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 119 lines 3.5 kB view raw
1{ 2 lib, 3 buildPlatform, 4 hostPlatform, 5 fetchurl, 6 bash, 7 tinycc, 8 gnumake, 9 gnupatch, 10 gnused, 11 gnugrep, 12 gnutar, 13 gzip, 14}: 15 16let 17 inherit (import ./common.nix { inherit lib; }) pname meta; 18 version = "1.1.24"; 19 20 src = fetchurl { 21 url = "https://musl.libc.org/releases/musl-${version}.tar.gz"; 22 hash = "sha256-E3DJqBKyzyp9koAlEMygBYzDfmanvt1wBR8KNAFQIqM="; 23 }; 24 25 # Thanks to the live-bootstrap project! 26 # See https://github.com/fosslinux/live-bootstrap/blob/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24/musl-1.1.24.sh 27 liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24"; 28 patches = [ 29 (fetchurl { 30 url = "${liveBootstrap}/patches/avoid_set_thread_area.patch"; 31 hash = "sha256-TsbBZXk4/KMZG9EKi7cF+sullVXrxlizLNH0UHGXsPs="; 32 }) 33 (fetchurl { 34 url = "${liveBootstrap}/patches/avoid_sys_clone.patch"; 35 hash = "sha256-/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4="; 36 }) 37 (fetchurl { 38 url = "${liveBootstrap}/patches/fenv.patch"; 39 hash = "sha256-vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI="; 40 }) 41 (fetchurl { 42 url = "${liveBootstrap}/patches/makefile.patch"; 43 hash = "sha256-03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw="; 44 }) 45 (fetchurl { 46 url = "${liveBootstrap}/patches/musl_weak_symbols.patch"; 47 hash = "sha256-/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0="; 48 }) 49 (fetchurl { 50 url = "${liveBootstrap}/patches/set_thread_area.patch"; 51 hash = "sha256-RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0="; 52 }) 53 (fetchurl { 54 url = "${liveBootstrap}/patches/sigsetjmp.patch"; 55 hash = "sha256-wd2Aev1zPJXy3q933aiup5p1IMKzVJBquAyl3gbK4PU="; 56 }) 57 # FIXME: this patch causes the build to fail 58 # (fetchurl { 59 # url = "${liveBootstrap}/patches/stdio_flush_on_exit.patch"; 60 # hash = "sha256-/z5ze3h3QTysay8nRvyvwPv3pmTcKptdkBIaMCoeLDg="; 61 # }) 62 # HACK: always flush stdio immediately 63 ./always-flush.patch 64 (fetchurl { 65 url = "${liveBootstrap}/patches/va_list.patch"; 66 hash = "sha256-UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg="; 67 }) 68 ]; 69in 70bash.runCommand "${pname}-${version}" 71 { 72 inherit pname version meta; 73 74 nativeBuildInputs = [ 75 tinycc.compiler 76 gnumake 77 gnupatch 78 gnused 79 gnugrep 80 gnutar 81 gzip 82 ]; 83 } 84 '' 85 # Unpack 86 tar xzf ${src} 87 cd musl-${version} 88 89 # Patch 90 ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} 91 # tcc does not support complex types 92 rm -rf src/complex 93 # Configure fails without this 94 mkdir -p /dev 95 # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix 96 sed -i 's|/bin/sh|${bash}/bin/bash|' \ 97 tools/*.sh 98 chmod 755 tools/*.sh 99 # patch popen/system to search in PATH instead of hardcoding /bin/sh 100 sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \ 101 src/stdio/popen.c src/process/system.c 102 sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\ 103 src/misc/wordexp.c 104 105 # Configure 106 bash ./configure \ 107 --prefix=$out \ 108 --build=${buildPlatform.config} \ 109 --host=${hostPlatform.config} \ 110 --disable-shared \ 111 CC=tcc 112 113 # Build 114 make AR="tcc -ar" RANLIB=true CFLAGS="-DSYSCALL_NO_TLS" 115 116 # Install 117 make install 118 cp ${tinycc.libs}/lib/libtcc1.a $out/lib 119 ''