1{
2 stdenv,
3 lib,
4 libidn2,
5 libunistring,
6 runCommandLocal,
7 patchelf,
8}:
9# Construct a copy of libidn2.* where all (transitive) libc references (in .bin)
10# get replaced by a new one, so that there's no reference to bootstrap tools.
11runCommandLocal "${libidn2.pname}-${libidn2.version}"
12 {
13 outputs = [
14 "bin"
15 "dev"
16 "out"
17 ];
18 passthru = {
19 inherit (libidn2) out info devdoc; # no need to touch these store paths
20 };
21 inherit (libidn2) meta;
22 }
23 ''
24 cp -r '${libidn2.bin}' "$bin"
25 chmod +w "$bin"/bin/*
26 patchelf \
27 --set-interpreter '${stdenv.cc.bintools.dynamicLinker}' \
28 --set-rpath '${
29 lib.concatMapStringsSep ":" (p: lib.getLib p + "/lib") [
30 stdenv.cc.libc
31 libunistring
32 libidn2
33 ]
34 }' \
35 "$bin"/bin/*
36
37 cp -r '${libidn2.dev}' "$dev"
38 chmod +w "$dev"/nix-support/propagated-build-inputs
39 substituteInPlace "$dev"/nix-support/propagated-build-inputs \
40 --replace '${libidn2.bin}' "$bin"
41 substituteInPlace "$dev"/lib/pkgconfig/libidn2.pc \
42 --replace '${libidn2.dev}' "$dev"
43
44 ln -s '${libidn2.out}' "$out" # it's hard to be without any $out
45 ''