···155155156156#### Package using Meson needs to run binaries for the host platform during build. {#cross-meson-runs-host-code}
157157158158-Add `mesonEmulatorHook` cross conditionally to `nativeBuildInputs`.
158158+Add `mesonEmulatorHook` to `nativeBuildInputs` conditionally on if the target binaries can be executed.
159159160160e.g.
161161162162```
163163nativeBuildInputs = [
164164 meson
165165-] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
165165+] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
166166 mesonEmulatorHook
167167];
168168```
···2727# it may be worth thinking about using multiple derivation outputs
2828# In that case its about 6MB which could be separated
29293030-stdenv.mkDerivation rec {
3030+stdenv.mkDerivation (finalAttrs: {
3131 pname = "gobject-introspection";
3232 version = "1.72.0";
3333···3737 outputBin = "dev";
38383939 src = fetchurl {
4040- url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
4040+ url = "mirror://gnome/sources/gobject-introspection/${lib.versions.majorMinor finalAttrs.version}/gobject-introspection-${finalAttrs.version}.tar.xz";
4141 sha256 = "Av6OWQhh2I+DBg3TnNpcyqYLLaHSHQ+VSZMBsYa+qrw=";
4242 };
4343···6868 docbook-xsl-nons
6969 docbook_xml_dtd_45
7070 python3
7171- setupHook # move .gir files
7171+ finalAttrs.setupHook # move .gir files
7272 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ gobject-introspection-unwrapped ];
73737474 buildInputs = [
···105105106106 postInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
107107 cp -r ${buildPackages.gobject-introspection-unwrapped.devdoc} $devdoc
108108+ # these are uncompiled c and header files which aren't installed when cross-compiling because
109109+ # code that installs them is in tests/meson.build which is only run when not cross-compiling
110110+ # pygobject3 needs them
111111+ cp -r ${buildPackages.gobject-introspection-unwrapped.dev}/share/gobject-introspection-1.0/tests $dev/share/gobject-introspection-1.0/tests
108112 '';
109113110114 preCheck = ''
···120124 rm $out/lib/libregress-1.0${stdenv.targetPlatform.extensions.sharedLibrary}
121125 '';
122126127127+ # when cross-compiling and using the wrapper then when a package looks up the g_ir_X
128128+ # variable with pkg-config they'll get the host version which can't be run
129129+ # switch the variables to use g_ir_X from path instead of an absolute path
130130+ postFixup = lib.optionalString (!lib.hasSuffix "wrapped" finalAttrs.pname) ''
131131+ find "''${!outputDev}/lib/pkgconfig" -name '*.pc' | while read pc; do
132132+ substituteInPlace "$pc" \
133133+ --replace '=''${bindir}/g-ir' '=g-ir'
134134+ done
135135+ '';
136136+123137 setupHook = ./setup-hook.sh;
124138125139 passthru = {
126140 updateScript = gnome.updateScript {
127127- packageName = pname;
141141+ packageName = "gobject-introspection";
128142 versionPolicy = "odd-unstable";
129143 };
130144 };
···144158 automatically provide bindings to call into the C library.
145159 '';
146160 };
147147-}
161161+})
···121121 ];
122122123123 buildInputs = [
124124+ gobject-introspection
124125 gst-plugins-base
125126 orc
126126- # gobject-introspection has to be in both nativeBuildInputs and
127127- # buildInputs. The build tries to link against libgirepository-1.0.so
128128- gobject-introspection
129127 json-glib
130128 ldacbt
131129 libass
···294292 # `applemedia/videotexturecache.h` requires `gst/gl/gl.h`,
295293 # but its meson build system does not declare the dependency.
296294 "-Dapplemedia=disabled"
297297- ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
298298- "-Dintrospection=disabled"
299295 ] ++ (if enableGplPlugins then [
300296 "-Dgpl=enabled"
301297 ] else [
···66, expat
77, pam
88, meson
99+, mesonEmulatorHook
910, ninja
1011, perl
1112, rsync
···2324, useSystemd ? stdenv.isLinux
2425, systemd
2526, elogind
2626-# needed until gobject-introspection does cross-compile (https://github.com/NixOS/nixpkgs/pull/88222)
2727-, withIntrospection ? (stdenv.buildPlatform == stdenv.hostPlatform)
2828-# cross build fails on polkit-1-scan (https://github.com/NixOS/nixpkgs/pull/152704)
2929-, withGtkDoc ? (stdenv.buildPlatform == stdenv.hostPlatform)
3027# A few tests currently fail on musl (polkitunixusertest, polkitunixgrouptest, polkitidentitytest segfault).
3128# Not yet investigated; it may be due to the "Make netgroup support optional"
3229# patch not updating the tests correctly yet, or doing something wrong,
···8885 })
8986 ];
90878888+ depsBuildBuild = [
8989+ pkg-config
9090+ ];
9191+9192 nativeBuildInputs = [
9293 glib
9394 gtk-doc
···9798 ninja
9899 perl
99100 rsync
100100- (python3.withPackages (pp: with pp; [
101101+ gobject-introspection
102102+ (python3.pythonForBuild.withPackages (pp: with pp; [
101103 dbus-python
102104 (python-dbusmock.overridePythonAttrs (attrs: {
103105 # Avoid dependency cycle.
···109111 libxslt
110112 docbook-xsl-nons
111113 docbook_xml_dtd_412
114114+ ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
115115+ mesonEmulatorHook
112116 ];
113117114118 buildInputs = [
119119+ gobject-introspection
115120 expat
116121 pam
117122 spidermonkey_78
123123+ dbus
118124 ] ++ lib.optionals stdenv.isLinux [
119125 # On Linux, fall back to elogind when systemd support is off.
120126 (if useSystemd then systemd else elogind)
121121- ] ++ lib.optionals withIntrospection [
122122- gobject-introspection
123127 ];
124128125129 propagatedBuildInputs = [
···136140 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
137141 "-Dpolkitd_user=polkituser" #TODO? <nixos> config.ids.uids.polkituser
138142 "-Dos_type=redhat" # only affects PAM includes
139139- "-Dintrospection=${lib.boolToString withIntrospection}"
140143 "-Dtests=${lib.boolToString doCheck}"
141141- "-Dgtk_doc=${lib.boolToString withGtkDoc}"
142144 "-Dman=true"
143145 ] ++ lib.optionals stdenv.isLinux [
144146 "-Dsession_tracking=${if useSystemd then "libsystemd-login" else "libelogind"}"
+22-10
pkgs/development/libraries/tracker/default.nix
···2525, json-glib
2626, systemd
2727, dbus
2828+, writeText
2829}:
29303031stdenv.mkDerivation rec {
···4647 patchShebangs utils/data-generators/cc/generate
4748 '';
48495050+ depsBuildBuild = [
5151+ pkg-config
5252+ ];
5353+4954 nativeBuildInputs = [
5055 meson
5156 ninja
···5863 gobject-introspection
5964 docbook-xsl-nons
6065 docbook_xml_dtd_45
6161- python3 # for data-generators
6262- systemd # used for checks to install systemd user service
6363- dbus # used for checks and pkg-config to install dbus service/s
6464- ] ++ checkInputs; # gi is in the main meson.build and checked regardless of
6565- # whether tests are enabled
6666+ (python3.pythonForBuild.withPackages (p: [ p.pygobject3 ]))
6767+ ];
66686769 buildInputs = [
7070+ gobject-introspection
6871 glib
6972 libxml2
7073 sqlite
···7477 libuuid
7578 json-glib
7679 libstemmer
7777- ];
7878-7979- checkInputs = with python3.pkgs; [
8080- pygobject3
8080+ dbus
8181+ systemd
8182 ];
82838384 mesonFlags = [
8485 "-Ddocs=true"
8585- ];
8686+ ] ++ (
8787+ let
8888+ # https://gitlab.gnome.org/GNOME/tracker/-/blob/master/meson.build#L159
8989+ crossFile = writeText "cross-file.conf" ''
9090+ [properties]
9191+ sqlite3_has_fts5 = '${lib.boolToString (lib.hasInfix "-DSQLITE_ENABLE_FTS3" sqlite.NIX_CFLAGS_COMPILE)}'
9292+ '';
9393+ in
9494+ [
9595+ "--cross-file=${crossFile}"
9696+ ]
9797+ );
86988799 doCheck = true;
88100
+14-1
pkgs/development/python-modules/pygobject/3.nix
···1212, ninja
1313, isPy3k
1414, gnome
1515+, python
1516}:
16171718buildPythonPackage rec {
···2930 sha256 = "HzS192JN415E61p+tCg1MoW9AwBNVRMaX39/qbkPPMk=";
3031 };
31323333+ depsBuildBuild = [
3434+ pkg-config
3535+ ];
3636+3237 nativeBuildInputs = [
3338 pkg-config
3439 meson
···3742 ];
38433944 buildInputs = [
4545+ # # .so files link to these
4646+ gobject-introspection
4047 glib
4141- gobject-introspection
4248 ] ++ lib.optionals stdenv.isDarwin [
4349 ncurses
4450 ];
···4652 propagatedBuildInputs = [
4753 pycairo
4854 cairo
5555+ ];
5656+5757+ mesonFlags = [
5858+ # This is only used for figuring out what version of Python is in
5959+ # use, and related stuff like figuring out what the install prefix
6060+ # should be, but it does need to be able to execute Python code.
6161+ "-Dpython=${python.pythonForBuild.interpreter}"
4962 ];
50635164 passthru = {
+21-4
pkgs/tools/networking/networkmanager/default.nix
···3434, iputils
3535, kmod
3636, jansson
3737+, elfutils
3738, gtk-doc
3839, libxslt
3940, docbook_xsl
···4344, openconnect
4445, curl
4546, meson
4747+, mesonEmulatorHook
4648, ninja
4749, libpsl
4850, mobile-broadband-provider-info
4951, runtimeShell
5252+, buildPackages
5053}:
51545255let
5353- pythonForDocs = python3.withPackages (pkgs: with pkgs; [ pygobject3 ]);
5656+ pythonForDocs = python3.pythonForBuild.withPackages (pkgs: with pkgs; [ pygobject3 ]);
5457in
5558stdenv.mkDerivation rec {
5659 pname = "networkmanager";
···102105 "-Ddhcpcanon=no"
103106104107 # Miscellaneous
105105- "-Ddocs=true"
108108+ # almost cross-compiles, however fails with
109109+ # ** (process:9234): WARNING **: Failed to load shared library '/nix/store/...-networkmanager-aarch64-unknown-linux-gnu-1.38.2/lib/libnm.so.0' referenced by the typelib: /nix/store/...-networkmanager-aarch64-unknown-linux-gnu-1.38.2/lib/libnm.so.0: cannot open shared object file: No such file or directory
110110+ "-Ddocs=${lib.boolToString (stdenv.buildPlatform == stdenv.hostPlatform)}"
106111 # We don't use firewalld in NixOS
107112 "-Dfirewalld_zone=false"
108113 "-Dtests=no"
···138143 ];
139144140145 buildInputs = [
146146+ gobject-introspection
141147 systemd
142148 libselinux
143149 audit
···150156 mobile-broadband-provider-info
151157 bluez5
152158 dnsmasq
153153- gobject-introspection
154159 modemmanager
155160 readline
156161 newt
157162 libsoup
158163 jansson
164164+ dbus # used to get directory paths with pkg-config during configuration
159165 ];
160166161167 propagatedBuildInputs = [ gnutls libgcrypt ];
···167173 pkg-config
168174 vala
169175 gobject-introspection
170170- dbus
176176+ elfutils # used to find jansson soname
171177 # Docs
172178 gtk-doc
173179 libxslt
···176182 docbook_xml_dtd_42
177183 docbook_xml_dtd_43
178184 pythonForDocs
185185+ ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
186186+ mesonEmulatorHook
179187 ];
180188181189 doCheck = false; # requires /sys, the net
···183191 postPatch = ''
184192 patchShebangs ./tools
185193 patchShebangs libnm/generate-setting-docs.py
194194+195195+ # TODO: submit upstream
196196+ substituteInPlace meson.build \
197197+ --replace "'vala', req" "'vala', native: false, req"
186198 '';
187199188200 preBuild = ''
···192204 # We are using a symlink that will be overridden during installation.
193205 mkdir -p ${placeholder "out"}/lib
194206 ln -s $PWD/src/libnm-client-impl/libnm.so.0 ${placeholder "out"}/lib/libnm.so.0
207207+ '';
208208+209209+ postFixup = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
210210+ cp -r ${buildPackages.networkmanager.devdoc} $devdoc
211211+ cp -r ${buildPackages.networkmanager.man} $man
195212 '';
196213197214 passthru = {
+3-3
pkgs/top-level/all-packages.nix
···41484148 # example of an error which this fixes
41494149 # [Errno 8] Exec format error: './gdk3-scan'
41504150 mesonEmulatorHook =
41514151- if (stdenv.buildPlatform != stdenv.targetPlatform) then
41514151+ if (!stdenv.buildPlatform.canExecute stdenv.targetPlatform) then
41524152 makeSetupHook
41534153 {
41544154 name = "mesonEmulatorHook";
···41594159 '';
41604160 };
41614161 } ../development/tools/build-managers/meson/emulator-hook.sh
41624162- else throw "mesonEmulatorHook has to be in a cross conditional i.e. (stdenv.buildPlatform != stdenv.hostPlatform)";
41624162+ else throw "mesonEmulatorHook has to be in a conditional to check if the target binaries can be executed i.e. (!stdenv.buildPlatform.canExecute stdenv.hostPlatform)";
4163416341644164 meson-tools = callPackage ../misc/meson-tools { };
41654165···1794317943 gns3-gui = gns3Packages.guiStable;
1794417944 gns3-server = gns3Packages.serverStable;
17945179451794617946- gobject-introspection = if (stdenv.hostPlatform != stdenv.targetPlatform)
1794617946+ gobject-introspection = if (!stdenv.hostPlatform.canExecute stdenv.targetPlatform)
1794717947 then callPackage ../development/libraries/gobject-introspection/wrapper.nix { } else gobject-introspection-unwrapped;
17948179481794917949 gobject-introspection-unwrapped = callPackage ../development/libraries/gobject-introspection {