@@ -17,6 +17,16 @@ let
1717 sha256 = "14igk6k00bnpfw660qhswagyhvr0gfqg4q55dxvaaq7ikfkrir71";
1818 };
1919
20+ # iconv tool, implemented by musl author.
21+ # Original: http://git.etalabs.net/cgit/noxcuse/plain/src/iconv.c?id=02d288d89683e99fd18fe9f54d4e731a6c474a4f
22+ # We use copy from Alpine which fixes error messages, see:
23+ # https://git.alpinelinux.org/cgit/aports/commit/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f
24+ iconv_c = fetchurl {
25+ name = "iconv.c";
26+ url = "https://git.alpinelinux.org/cgit/aports/plain/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f";
27+ sha256 = "1mzxnc2ncq8lw9x6n7p00fvfklc9p3wfv28m68j0dfz5l8q2k6pp";
28+ };
29+
2030in
2131stdenv.mkDerivation rec {
2232 name = "musl-${version}";
@@ -41,6 +51,13 @@ stdenv.mkDerivation rec {
4151 --replace -fno-asynchronous-unwind-tables ""
4252 '';
4353
54+ patches = [
55+ # Minor touchup to build system making dynamic linker symlink relative
56+ (fetchurl {
57+ url = https://raw.githubusercontent.com/openwrt/openwrt/87606e25afac6776d1bbc67ed284434ec5a832b4/toolchain/musl/patches/300-relative.patch;
58+ sha256 = "0hfadrycb60sm6hb6by4ycgaqc9sgrhh42k39v8xpmcvdzxrsq2n";
59+ })
60+ ];
4461 preConfigure = ''
4562 configureFlagsArray+=("--syslibdir=$out/lib")
4663 '';
@@ -58,6 +75,8 @@ stdenv.mkDerivation rec {
5875 dontDisableStatic = true;
5976 separateDebugInfo = true;
6077
78+ NIX_DONT_SET_RPATH = true;
79+
6180 postInstall = ''
6281 # Not sure why, but link in all but scsi directory as that's what uclibc/glibc do.
6382 # Apparently glibc provides scsi itself?
@@ -68,7 +87,7 @@ stdenv.mkDerivation rec {
6887 mkdir -p $out/bin
6988
7089 # Create 'ldd' symlink, builtin
71− ln -s $out/lib/libc.so $out/bin/ldd
90+ ln -rs $out/lib/libc.so $out/bin/ldd
7291
7392 # (impure) cc wrapper around musl for interactive usuage
7493 for i in musl-gcc musl-clang ld.musl-clang; do
@@ -77,6 +96,14 @@ stdenv.mkDerivation rec {
7796 moveToOutput lib/musl-gcc.specs $dev
7897 substituteInPlace $dev/bin/musl-gcc \
7998 --replace $out/lib/musl-gcc.specs $dev/lib/musl-gcc.specs
99+
100+ # provide 'iconv' utility, using just-built headers, libc/ldso
101+ $CC ${iconv_c} -o $out/bin/iconv \
102+ -I$dev/include \
103+ -L$out/lib -Wl,-rpath=$out/lib \
104+ -lc \
105+ -B $out/lib \
106+ -Wl,-dynamic-linker=$(ls $out/lib/ld-*)
80107 '' + lib.optionalString useBSDCompatHeaders ''
81108 install -D ${queue_h} $dev/include/sys/queue.h
82109 install -D ${cdefs_h} $dev/include/sys/cdefs.h