pkgsStatic.netbsd: fix nbtool_config.h conflicts

In pkgsStatic, /all/ build inputs are propagated. This means that
netbsd.compat was propagated, along with its setup hook, which broke
static glib builds because glib defines a function with the same name
as one in nbtool_config.h, and nbtool_config.h was being automatically
included in every C file processed by the compiler, in any transitive
dependent of netbsd.compat's setup hook.

To fix this, rather than forcing nbtool_config.h to be included for
_every_ C file in a derivation that depends on netbsd.compat, modify
the NetBSD-specific mkDerivation to detect files that need the header,
and patch it in there where appropriate. That way, only files that
are part of NetBSD will be affected, not all transitive dependents.

+11 -2
-1
pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh
··· 3 3 4 4 export NIX_LDFLAGS${role_post}+=" -lnbcompat" 5 5 export NIX_CFLAGS_COMPILE${role_post}+=" -DHAVE_NBTOOL_CONFIG_H" 6 - export NIX_CFLAGS_COMPILE${role_post}+=" -include nbtool_config.h"
+11 -1
pkgs/os-specific/bsd/netbsd/default.nix
··· 120 120 } // lib.optionalAttrs (attrs.headersOnly or false) { 121 121 installPhase = "includesPhase"; 122 122 dontBuild = true; 123 - } // attrs)); 123 + } // attrs // { 124 + postPatch = lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' 125 + # Files that use NetBSD-specific macros need to have nbtool_config.h 126 + # included ahead of them on non-NetBSD platforms. 127 + set +e 128 + grep -Zlr "^__RCSID 129 + ^__BEGIN_DECLS" | xargs -0r grep -FLZ nbtool_config.h | 130 + xargs -0tr sed -i '0,/^#/s//#include <nbtool_config.h>\n\0/' 131 + set -e 132 + '' + attrs.postPatch or ""; 133 + })); 124 134 125 135 ## 126 136 ## START BOOTSTRAPPING