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