nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPlatform,
4 hostPlatform,
5 fetchurl,
6 bash,
7 gcc,
8 binutils,
9 gnumake,
10 gnugrep,
11 gnused,
12 gnutar,
13 gzip,
14}:
15let
16 inherit (import ./common.nix { inherit lib; }) pname meta;
17 version = "1.2.4";
18
19 src = fetchurl {
20 url = "https://musl.libc.org/releases/musl-${version}.tar.gz";
21 hash = "sha256-ejXq4z1TcqfA2hGI3nmHJvaIJVE7euPr6XqqpSEU8Dk=";
22 };
23in
24bash.runCommand "${pname}-${version}"
25 {
26 inherit pname version meta;
27
28 nativeBuildInputs = [
29 gcc
30 binutils
31 gnumake
32 gnused
33 gnugrep
34 gnutar
35 gzip
36 ];
37
38 passthru.tests.hello-world =
39 result:
40 bash.runCommand "${pname}-simple-program-${version}"
41 {
42 nativeBuildInputs = [
43 gcc
44 binutils
45 result
46 ];
47 }
48 ''
49 cat <<EOF >> test.c
50 #include <stdio.h>
51 int main() {
52 printf("Hello World!\n");
53 return 0;
54 }
55 EOF
56 musl-gcc -o test test.c
57 ./test
58 mkdir $out
59 '';
60 }
61 ''
62 # Unpack
63 tar xzf ${src}
64 cd musl-${version}
65
66 # Patch
67 # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix
68 sed -i 's|/bin/sh|${bash}/bin/bash|' \
69 tools/*.sh
70 # patch popen/system to search in PATH instead of hardcoding /bin/sh
71 sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
72 src/stdio/popen.c src/process/system.c
73 sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
74 src/misc/wordexp.c
75
76 # Configure
77 bash ./configure \
78 --prefix=$out \
79 --build=${buildPlatform.config} \
80 --host=${hostPlatform.config} \
81 --syslibdir=$out/lib \
82 --enable-wrapper
83
84 # Build
85 make -j $NIX_BUILD_CORES
86
87 # Install
88 make -j $NIX_BUILD_CORES install
89 sed -i 's|/bin/sh|${bash}/bin/bash|' $out/bin/*
90 ln -s ../lib/libc.so $out/bin/ldd
91 ''