From 0e3b8203010732d6036854904a33cd96e13ad50b Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Thu, 2 Nov 2023 18:30:35 -0700 Subject: [PATCH 01/20] qutebrowser: repair vandalism Our qutebrowser package has been vandalized by various commits, such as c9cc3a2e3eb4661b49176e0c62afd097793c9626 and ad0bbaf1d21f3b5da9c9cf68f0583d487c295782, which made erroneous assertions such as "since qutebrowser 3.0.0 the derivation is only building for qt6." This commit repairs the vandalism. --- .../networking/browsers/qutebrowser/default.nix | 9 +++++++-- pkgs/development/libraries/qt-5/5.15/default.nix | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/networking/browsers/qutebrowser/default.nix b/pkgs/applications/networking/browsers/qutebrowser/default.nix index 03b03724aeef19a..200f8e48c7e016d 100644 --- a/pkgs/applications/networking/browsers/qutebrowser/default.nix +++ b/pkgs/applications/networking/browsers/qutebrowser/default.nix @@ -15,6 +15,7 @@ }: let + isQt6 = lib.versions.major qtbase.version == "6"; pdfjs = let version = "3.9.179"; in @@ -50,10 +51,14 @@ python3.pkgs.buildPythonApplication { ]; propagatedBuildInputs = with python3.pkgs; ([ - pyyaml pyqt6-webengine jinja2 pygments + pyyaml (if isQt6 then pyqt6-webengine else pyqtwebengine) jinja2 pygments # scripts and userscripts libs tldextract beautifulsoup4 - readability-lxml pykeepass stem + readability-lxml pykeepass + ] ++ lib.optionals ((builtins.tryEval stem.outPath).success) [ + # error: stem-1.8.2 not supported for interpreter python3.11 + stem + ] ++ [ pynacl # extensive ad blocking adblock diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 8a859af37e9d56f..b8ad76854728f74 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -339,5 +339,6 @@ let finalScope = baseScope.overrideScope(final: prev: { qttranslations = bootstrapScope.qttranslations; + qutebrowser = final.callPackage ../../../../applications/networking/browsers/qutebrowser { }; }); in finalScope From 1048c9063b30f2826441dbd8a824370c7b646cc5 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 21 Aug 2023 14:38:53 -0700 Subject: [PATCH 02/20] lib.systems.inspect: add patternLogicalAnd --- lib/systems/inspect.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 022e459c3945ab1..073df78797c728b 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -100,6 +100,32 @@ rec { ]; }; + # given two patterns, return a pattern which is their logical AND. + # Since a pattern is a list-of-disjuncts, this needs to + patternLogicalAnd = pat1_: pat2_: + let + # patterns can be either a list or a (bare) singleton; turn + # them into singletons for uniform handling + pat1 = lib.toList pat1_; + pat2 = lib.toList pat2_; + in + lib.concatMap (attr1: + map (attr2: + lib.recursiveUpdateUntil + (path: subattr1: subattr2: + if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2 + then true + else throw '' + pattern conflict at path ${toString path}: + ${builtins.toJSON subattr1} + ${builtins.toJSON subattr2} + '') + attr1 + attr2 + ) + pat2) + pat1; + matchAnyAttrs = patterns: if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns else matchAttrs patterns; From 4ef828d5d426d052a686cb200f9c08f9f6718733 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:55:10 -0700 Subject: [PATCH 03/20] qt5.qtdeclarative: add postFixup if cross compiling --- .../libraries/qt-5/modules/qtdeclarative.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix b/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix index 892498da43b29de..3e2136f39bcd9a1 100644 --- a/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix +++ b/pkgs/development/libraries/qt-5/modules/qtdeclarative.nix @@ -1,4 +1,6 @@ -{ qtModule, lib, python3, qtbase, qtsvg }: +{ lib +, stdenv +, qtModule, python3, qtbase, qtsvg }: qtModule { pname = "qtdeclarative"; @@ -21,4 +23,10 @@ qtModule { "bin/qmlscene" "bin/qmltestrunner" ]; + postFixup = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + mv $dev/bin/qmlformat $bin/bin/qmlformat + mv $dev/bin/qmltyperegistrar $bin/bin/qmltyperegistrar + ln -s $bin/bin/qmlformat $dev/bin/qmlformat + ln -s $bin/bin/qmltyperegistrar $dev/bin/qmltyperegistrar + ''; } From 760d596e3358c74b60dbc4eae955fbacfbfa29ec Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:56:55 -0700 Subject: [PATCH 04/20] qt5.qtModule: reformat arguments --- pkgs/development/libraries/qt-5/qtModule.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/qtModule.nix b/pkgs/development/libraries/qt-5/qtModule.nix index 7d73e652b6ffb39..9e943a5f3aa0e45 100644 --- a/pkgs/development/libraries/qt-5/qtModule.nix +++ b/pkgs/development/libraries/qt-5/qtModule.nix @@ -1,4 +1,11 @@ -{ lib, mkDerivation, perl, qmake, patches, srcs }: +{ lib +, stdenv +, mkDerivation +, perl +, qmake +, patches +, srcs +}: let inherit (lib) licenses maintainers platforms; in From e42b9650e670513bfa8e4608b63d7d8969cfd83a Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:58:12 -0700 Subject: [PATCH 05/20] qt5.qtModule: add buildPackages.stdenv.cc to depsBuildBuild if cross compiling --- pkgs/development/libraries/qt-5/qtModule.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/development/libraries/qt-5/qtModule.nix b/pkgs/development/libraries/qt-5/qtModule.nix index 9e943a5f3aa0e45..e5d1e1f5422e955 100644 --- a/pkgs/development/libraries/qt-5/qtModule.nix +++ b/pkgs/development/libraries/qt-5/qtModule.nix @@ -1,5 +1,6 @@ { lib , stdenv +, buildPackages , mkDerivation , perl , qmake @@ -25,6 +26,9 @@ mkDerivation (args // { propagatedBuildInputs = (lib.warnIf (args ? qtInputs) "qt5.qtModule's qtInputs argument is deprecated" args.qtInputs or []) ++ (args.propagatedBuildInputs or []); +} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + depsBuildBuild = [ buildPackages.stdenv.cc ] ++ (args.depsBuildBuild or []); +} // { outputs = args.outputs or [ "out" "dev" ]; setOutputFlags = args.setOutputFlags or false; From 129b22f3af0e2ed30878f9ebeb05aafae25e7fca Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:59:25 -0700 Subject: [PATCH 06/20] qt5.qtModule: add explicit pkgsHostTarget.qt5.qtbase.dev to nativeBuildInputs if cross compiling --- pkgs/development/libraries/qt-5/qtModule.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/qtModule.nix b/pkgs/development/libraries/qt-5/qtModule.nix index e5d1e1f5422e955..54d24e46092f283 100644 --- a/pkgs/development/libraries/qt-5/qtModule.nix +++ b/pkgs/development/libraries/qt-5/qtModule.nix @@ -6,6 +6,7 @@ , qmake , patches , srcs +, pkgsHostTarget }: let inherit (lib) licenses maintainers platforms; in @@ -22,7 +23,12 @@ mkDerivation (args // { inherit pname version src; patches = (args.patches or []) ++ (patches.${pname} or []); - nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ perl qmake ]; + nativeBuildInputs = + (args.nativeBuildInputs or []) ++ [ + perl qmake + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + pkgsHostTarget.qt5.qtbase.dev + ]; propagatedBuildInputs = (lib.warnIf (args ? qtInputs) "qt5.qtModule's qtInputs argument is deprecated" args.qtInputs or []) ++ (args.propagatedBuildInputs or []); From 80c437cb3d035c74bff54a80f8300ef2f914ff2d Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:00:22 -0700 Subject: [PATCH 07/20] qt5.qtwebchannel: omit "bin" output when cross compiling --- pkgs/development/libraries/qt-5/modules/qtwebchannel.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix b/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix index 118a5d4f96f6904..e7d6be534409e61 100644 --- a/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix +++ b/pkgs/development/libraries/qt-5/modules/qtwebchannel.nix @@ -1,7 +1,12 @@ -{ qtModule, qtbase, qtdeclarative }: +{ lib +, stdenv +, qtModule +, qtbase +, qtdeclarative +}: qtModule { pname = "qtwebchannel"; propagatedBuildInputs = [ qtbase qtdeclarative ]; - outputs = [ "out" "dev" "bin" ]; + outputs = [ "out" "dev" ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ "bin" ]; } From 88568bb4fdcd665dc6f0c52705092daa6c45bb5c Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:07:12 -0700 Subject: [PATCH 08/20] qt5.qtwebengine: fix cross --- .../libraries/qt-5/modules/qtwebengine.nix | 117 ++++++++++++++---- 1 file changed, 90 insertions(+), 27 deletions(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix index 777430af0217fc0..58f90763a2452ea 100644 --- a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix +++ b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix @@ -1,8 +1,11 @@ { qtModule , qtdeclarative, qtquickcontrols, qtlocation, qtwebchannel -, bison, flex, git, gperf, ninja, pkg-config, python, which +, bison, flex, git, gperf, ninja, pkg-config, python, which, python3 , nodejs, qtbase, perl +, buildPackages +, pkgsBuildTarget +, pkgsBuildBuild , xorg, libXcursor, libXScrnSaver, libXrandr, libXtst , fontconfig, freetype, harfbuzz, icu, dbus, libdrm @@ -27,12 +30,45 @@ , pipewireSupport ? stdenv.isLinux , pipewire_0_2 , postPatch ? "" +, nspr +, lndir +, dbusSupport ? !stdenv.isDarwin, expat }: -qtModule { +let + # qtwebengine expects to find an executable in $PATH which runs on + # the build platform yet knows about the host `.pc` files. Most + # configury allows setting $PKG_CONFIG to point to an + # arbitrarily-named script which serves this purpose; however QT + # insists that it is named `pkg-config` with no target prefix. So + # we re-wrap the host platform's pkg-config. + pkg-config-wrapped-without-prefix = stdenv.mkDerivation { + name = "pkg-config-wrapper-without-target-prefix"; + dontUnpack = true; + dontBuild = true; + installPhase = '' + mkdir -p $out/bin + ln -s '${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config' $out/bin/pkg-config + ''; + }; + + qtPlatformCross = plat: with plat; + if isLinux + then "linux-generic-g++" + else throw "Please add a qtPlatformCross entry for ${plat.config}"; + +in + +qtModule ({ pname = "qtwebengine"; nativeBuildInputs = [ bison flex git gperf ninja pkg-config python which gn nodejs + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + perl + lndir (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtbase) + pkgsBuildBuild.pkg-config + (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtquickcontrols) + pkg-config-wrapped-without-prefix ] ++ lib.optional stdenv.isDarwin xcbuild; doCheck = true; outputs = [ "bin" "dev" "out" ]; @@ -108,16 +144,25 @@ qtModule { --replace "-Wl,-fatal_warnings" "" '') + postPatch; - env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isGNU [ - # with gcc8, -Wclass-memaccess became part of -Wall and this exceeds the logging limit - "-Wno-class-memaccess" - ] ++ lib.optionals (stdenv.hostPlatform.gcc.arch or "" == "sandybridge") [ - # it fails when compiled with -march=sandybridge https://github.com/NixOS/nixpkgs/pull/59148#discussion_r276696940 - # TODO: investigate and fix properly - "-march=westmere" - ] ++ lib.optionals stdenv.cc.isClang [ - "-Wno-elaborated-enum-base" - ]); + env = { + NIX_CFLAGS_COMPILE = + toString ( + lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "-w " + ] ++ lib.optionals stdenv.cc.isGNU [ + # with gcc8, -Wclass-memaccess became part of -Wall and this exceeds the logging limit + "-Wno-class-memaccess" + ] ++ lib.optionals (stdenv.hostPlatform.gcc.arch or "" == "sandybridge") [ + # it fails when compiled with -march=sandybridge https://github.com/NixOS/nixpkgs/pull/59148#discussion_r276696940 + # TODO: investigate and fix properly + "-march=westmere" + ] ++ lib.optionals stdenv.cc.isClang [ + "-Wno-elaborated-enum-base" + ]); + } // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + NIX_CFLAGS_LINK = "-Wl,--no-warn-search-mismatch"; + "NIX_CFLAGS_LINK_${buildPackages.stdenv.cc.suffixSalt}" = "-Wl,--no-warn-search-mismatch"; + }; preConfigure = '' export NINJAFLAGS=-j$NIX_BUILD_CORES @@ -125,10 +170,15 @@ qtModule { if [ -d "$PWD/tools/qmake" ]; then QMAKEPATH="$PWD/tools/qmake''${QMAKEPATH:+:}$QMAKEPATH" fi + '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' + export QMAKE_CC=$CC + export QMAKE_CXX=$CXX + export QMAKE_LINK=$CXX + export QMAKE_AR=$AR ''; qmakeFlags = [ "--" "-system-ffmpeg" ] - ++ lib.optional pipewireSupport "-webengine-webrtc-pipewire" + ++ lib.optional (pipewireSupport && stdenv.buildPlatform == stdenv.hostPlatform) "-webengine-webrtc-pipewire" ++ lib.optional enableProprietaryCodecs "-proprietary-codecs"; propagatedBuildInputs = [ @@ -226,7 +276,9 @@ qtModule { dontUseNinjaBuild = true; dontUseNinjaInstall = true; - postInstall = lib.optionalString stdenv.isLinux '' + postInstall = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + mkdir -p $out/libexec + '' + lib.optionalString stdenv.isLinux '' cat > $out/libexec/qt.conf < Date: Fri, 3 Nov 2023 22:14:31 -0700 Subject: [PATCH 09/20] qt5.qttranslations: disable if cross to prevent infinite recursion --- pkgs/development/libraries/qt-5/5.15/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index b8ad76854728f74..56b7f86ba6c4d3f 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -338,7 +338,12 @@ let }); finalScope = baseScope.overrideScope(final: prev: { - qttranslations = bootstrapScope.qttranslations; + # qttranslations causes eval-time infinite recursion when + # cross-compiling; disabled for now. + qttranslations = + if stdenv.buildPlatform == stdenv.hostPlatform + then bootstrapScope.qttranslations + else null; qutebrowser = final.callPackage ../../../../applications/networking/browsers/qutebrowser { }; }); in finalScope From 08b8c3eaf414f0bed6c9098f846a24eee9d4a9ae Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:14:43 -0700 Subject: [PATCH 10/20] qt5.qtbase: fix cross --- .../libraries/qt-5/modules/qtbase.nix | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index 9f0feaf94e58412..67e9bd5440d118b 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -29,13 +29,18 @@ , developerBuild ? false , decryptSslTraffic ? false , testers +, buildPackages }: let debugSymbols = debug || developerBuild; + qtPlatformCross = plat: with plat; + if isLinux + then "linux-generic-g++" + else throw "Please add a qtPlatformCross entry for ${plat.config}"; in -stdenv.mkDerivation (finalAttrs: { +stdenv.mkDerivation (finalAttrs: ({ pname = "qtbase"; inherit qtCompatVersion src version; debug = debugSymbols; @@ -83,6 +88,13 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ bison flex gperf lndir perl pkg-config which ] ++ lib.optionals stdenv.isDarwin [ xcbuild ]; + } // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + # `qtbase` expects to find `cc` (with no prefix) in the + # `$PATH`, so the following is needed even if + # `stdenv.buildPlatform.canExecute stdenv.hostPlatform` + depsBuildBuild = [ buildPackages.stdenv.cc ]; + } // { + propagatedNativeBuildInputs = [ lndir ]; # libQt5Core links calls CoreFoundation APIs that call into the system ICU. Binaries linked @@ -162,6 +174,13 @@ stdenv.mkDerivation (finalAttrs: { export MAKEFLAGS+=" -j$NIX_BUILD_CORES" ./bin/syncqt.pl -version $version + '' + lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + # QT's configure script will refuse to use pkg-config unless these two environment variables are set + export PKG_CONFIG_SYSROOT_DIR=/ + export PKG_CONFIG_LIBDIR=${lib.getLib pkg-config}/lib + echo "QMAKE_LFLAGS=''${LDFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf + echo "QMAKE_CFLAGS=''${CFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf + echo "QMAKE_CXXFLAGS=''${CXXFLAGS}" >> mkspecs/devices/${qtPlatformCross stdenv.hostPlatform}/qmake.conf ''; postConfigure = '' @@ -186,21 +205,34 @@ stdenv.mkDerivation (finalAttrs: { done ''; - env.NIX_CFLAGS_COMPILE = toString ([ - "-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields - ''-DNIXPKGS_QTCOMPOSE="${libX11.out}/share/X11/locale"'' - ''-DLIBRESOLV_SO="${stdenv.cc.libc.out}/lib/libresolv"'' - ''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"'' - ] ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"'' + env = { + NIX_CFLAGS_COMPILE = toString ([ + "-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "-Wno-warn=free-nonheap-object" + "-Wno-free-nonheap-object" + "-w" + ] ++ [ + ''-DNIXPKGS_QTCOMPOSE="${libX11.out}/share/X11/locale"'' + ''-DLIBRESOLV_SO="${stdenv.cc.libc.out}/lib/libresolv"'' + ''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"'' + ] ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"'' ++ lib.optional stdenv.isLinux "-DUSE_X11" ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-darwin") [ # ignore "is only available on macOS 10.12.2 or newer" in obj-c code "-Wno-error=unguarded-availability" ] ++ lib.optionals withGtk3 [ - ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"'' - ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"'' - ] ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC"); + ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"'' + ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"'' + ] ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC"); + } // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + NIX_CFLAGS_COMPILE_FOR_BUILD = toString ([ + "-Wno-warn=free-nonheap-object" + "-Wno-free-nonheap-object" + "-w" + ]); + }; prefixKey = "-prefix "; @@ -209,6 +241,9 @@ stdenv.mkDerivation (finalAttrs: { # To prevent these failures, we need to override PostgreSQL detection. PSQL_LIBS = lib.optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq"; + } // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + configurePlatforms = [ ]; + } // { # TODO Remove obsolete and useless flags once the build will be totally mastered configureFlags = [ "-plugindir $(out)/$(qtPluginPrefix)" @@ -235,11 +270,16 @@ stdenv.mkDerivation (finalAttrs: { "-L" "${icu.out}/lib" "-I" "${icu.dev}/include" "-pch" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-device ${qtPlatformCross stdenv.hostPlatform}" + "-device-option CROSS_COMPILE=${stdenv.cc.targetPrefix}" ] ++ lib.optional debugSymbols "-debug" ++ lib.optionals developerBuild [ "-developer-build" "-no-warnings-are-errors" + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "-no-warnings-are-errors" ] ++ (if (!stdenv.hostPlatform.isx86_64) then [ "-no-sse2" ] else [ @@ -381,4 +421,4 @@ stdenv.mkDerivation (finalAttrs: { platforms = platforms.unix; }; -}) +})) From c8c7a452bb35fb1030d7270f490c89e4bc65c614 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:20:23 -0700 Subject: [PATCH 11/20] qt5.pyqtwebengine: fix cross --- .../python-modules/pyqtwebengine/default.nix | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pkgs/development/python-modules/pyqtwebengine/default.nix b/pkgs/development/python-modules/pyqtwebengine/default.nix index 7ad39633b7e51e5..71abe839a7893e1 100644 --- a/pkgs/development/python-modules/pyqtwebengine/default.nix +++ b/pkgs/development/python-modules/pyqtwebengine/default.nix @@ -1,13 +1,14 @@ { lib, stdenv, pythonPackages, fetchPypi, pkg-config -, qmake, qtbase, qtsvg, qtwebengine +, qmake, qtbase, qtsvg, qtwebengine, qtwebchannel, qtdeclarative , wrapQtAppsHook , darwin +, buildPackages }: let inherit (pythonPackages) buildPythonPackage python isPy27 pyqt5 sip pyqt-builder; inherit (darwin) autoSignDarwinBinariesHook; -in buildPythonPackage rec { +in buildPythonPackage (rec { pname = "PyQtWebEngine"; version = "5.15.4"; format = "pyproject"; @@ -29,12 +30,18 @@ in buildPythonPackage rec { nativeBuildInputs = [ pkg-config qmake + ] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ sip + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + buildPackages.python3Packages.sip + ] ++ [ qtbase qtsvg qtwebengine pyqt-builder pythonPackages.setuptools + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + qtdeclarative ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook ]; @@ -44,6 +51,9 @@ in buildPythonPackage rec { qtbase qtsvg qtwebengine + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + qtwebchannel + qtdeclarative ]; propagatedBuildInputs = [ pyqt5 ]; @@ -71,6 +81,13 @@ in buildPythonPackage rec { description = "Python bindings for Qt5"; homepage = "http://www.riverbankcomputing.co.uk"; license = licenses.gpl3; - platforms = lib.lists.intersectLists qtwebengine.meta.platforms platforms.mesaPlatforms; + hydraPlatforms = lib.lists.intersectLists qtwebengine.meta.platforms platforms.mesaPlatforms; }; -} +} // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + # TODO: figure out why the env hooks aren't adding these inclusions automatically + env.NIX_CFLAGS_COMPILE = + lib.concatStringsSep " " [ + "-I${lib.getDev qtbase}/include/QtPrintSupport/" + "-I${lib.getDev qtwebchannel}/include/QtWebChannel/" + ]; +}) From dc61c9062709546b1feec1e4ae1aaeefe32b031d Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:25:17 -0700 Subject: [PATCH 12/20] pyqt5: fix cross --- pkgs/development/python-modules/pyqt/5.x.nix | 55 ++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/pkgs/development/python-modules/pyqt/5.x.nix b/pkgs/development/python-modules/pyqt/5.x.nix index 12d2ea182af0290..c514b9f8358437d 100644 --- a/pkgs/development/python-modules/pyqt/5.x.nix +++ b/pkgs/development/python-modules/pyqt/5.x.nix @@ -12,6 +12,7 @@ , pyqt5_sip , pyqt-builder , libsForQt5 +, enableVerbose ? true , withConnectivity ? false , withMultimedia ? false , withWebKit ? false @@ -19,6 +20,9 @@ , withLocation ? false , withSerialPort ? false , withTools ? false +, pkgsBuildTarget +, buildPackages +, dbusSupport ? !stdenv.isDarwin }: buildPythonPackage rec { @@ -45,6 +49,7 @@ buildPythonPackage rec { # be more verbose '' cat >> pyproject.toml < PyQt_PrintDialog + # QT_NO_PRINTER => PyQt_Printer + # QT_NO_PRINTPREVIEWDIALOG => PyQt_PrintPreviewDialog + # QT_NO_PRINTPREVIEWWIDGET => PyQt_PrintPreviewWidget + # QT_NO_SSL => PyQt_SSL + # QT_SHARED || QT_DLL => shared (otherwise static) + # QT_NO_PROCESS => PyQt_Process + # QT_NO_FPU || Q_PROCESSOR_ARM || Q_OS_WINCE => PyQt_qreal_double + # sizeof (qreal) != sizeof (double) => PyQt_qreal_double + # !Q_COMPILER_CONSTEXPR !Q_COMPILER_UNIFORM_INIT => PyQt_CONSTEXPR + # QT_NO_ACCESSIBILITY => PyQt_Accessibility + # QT_NO_OPENGL => PyQt_OpenGL PyQt_Desktop_OpenGL + # defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_ES_3) => PyQt_Desktop_OpenGL + # QT_NO_RAWFONT => PyQt_RawFont + # QT_NO_SESSIONMANAGER => PyQt_SessionManager + # + + lib.optionalString (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) '' + rm config-tests/cfgtest_QtCore.cpp + rm config-tests/cfgtest_QtGui.cpp + rm config-tests/cfgtest_QtNetwork.cpp + rm config-tests/cfgtest_QtPrintSupport.cpp ''; enableParallelBuilding = true; @@ -68,16 +104,27 @@ buildPythonPackage rec { export MAKEFLAGS+="''${enableParallelBuilding:+-j$NIX_BUILD_CORES}" ''; + # tons of warnings from subpackages, no point in playing whack-a-mole + env = lib.optionalAttrs (!enableVerbose) { + NIX_CFLAGS_COMPILE = "-w"; + }; + outputs = [ "out" "dev" ]; dontWrapQtApps = true; - nativeBuildInputs = with libsForQt5; [ + nativeBuildInputs = [ pkg-config - qmake + ] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ + libsForQt5.qmake + ] ++ [ setuptools lndir sip + ] ++ (with pkgsBuildTarget.targetPackages.libsForQt5; [ + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + qmake + ] ++ [ qtbase qtsvg qtdeclarative @@ -90,11 +137,13 @@ buildPythonPackage rec { ++ lib.optional withLocation qtlocation ++ lib.optional withSerialPort qtserialport ++ lib.optional withTools qttools - ; + ); buildInputs = with libsForQt5; [ dbus + ] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ qtbase + ] ++ [ qtsvg qtdeclarative pyqt-builder From 228288885b9dc7e33812ab8feac461259f5752df Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 4 Nov 2023 00:57:23 -0700 Subject: [PATCH 13/20] jasper: mark broken if cross --- pkgs/by-name/ja/jasper/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/ja/jasper/package.nix b/pkgs/by-name/ja/jasper/package.nix index 4e10eaa80ad83be..23171c71fbecbb1 100644 --- a/pkgs/by-name/ja/jasper/package.nix +++ b/pkgs/by-name/ja/jasper/package.nix @@ -48,5 +48,8 @@ stdenv.mkDerivation (finalAttrs: { license = lib.licenses.mit; maintainers = with lib.maintainers; [ AndersonTorres ]; platforms = lib.platforms.unix; + + # The value of __STDC_VERSION__ cannot be automatically determined when cross-compiling. + broken = stdenv.buildPlatform != stdenv.hostPlatform; }; }) From de70669d022c29311eb259f5c2fa4e72efd3d171 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 4 Nov 2023 00:58:04 -0700 Subject: [PATCH 14/20] qt5.qtimageformats: do not try to use broken libraries --- .../libraries/qt-5/modules/qtimageformats.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/qt-5/modules/qtimageformats.nix b/pkgs/development/libraries/qt-5/modules/qtimageformats.nix index f099fc6799b50f0..4775bb0b0383f6f 100644 --- a/pkgs/development/libraries/qt-5/modules/qtimageformats.nix +++ b/pkgs/development/libraries/qt-5/modules/qtimageformats.nix @@ -1,4 +1,6 @@ -{ qtModule +{ lib +, stdenv +, qtModule , qtbase , libwebp , jasper @@ -8,5 +10,11 @@ qtModule { pname = "qtimageformats"; - propagatedBuildInputs = [ qtbase libwebp jasper libmng libtiff ]; + propagatedBuildInputs = [ + qtbase libwebp + ] ++ lib.optionals (!jasper.meta.broken) [ + jasper + ] ++ [ + libmng libtiff + ]; } From 930a63167bf45527558e3ffa927d6724d9877e33 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:53:31 -0700 Subject: [PATCH 15/20] qt5.qmake-hook: move libs to depsTargetTargetPropagated --- pkgs/development/libraries/qt-5/5.15/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 56b7f86ba6c4d3f..df60188800ab8f0 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -313,7 +313,9 @@ let qmake = callPackage ({ qtbase }: makeSetupHook { name = "qmake-hook"; - propagatedBuildInputs = [ qtbase.dev ]; + ${if stdenv.buildPlatform == stdenv.hostPlatform + then "propagatedBuildInputs" + else "depsTargetTargetPropagated"} = [ qtbase.dev ]; substitutions = { inherit debug; fix_qmake_libtool = ../hooks/fix-qmake-libtool.sh; From 1a3bd5bb7e8fff781c2d6e08e68a640e7bf6328a Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 21:53:31 -0700 Subject: [PATCH 16/20] qt5.qmake-hook: move libs to depsTargetTargetPropagated --- pkgs/development/libraries/qt-5/5.15/default.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index df60188800ab8f0..c8ac8aea9e59416 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -313,9 +313,7 @@ let qmake = callPackage ({ qtbase }: makeSetupHook { name = "qmake-hook"; - ${if stdenv.buildPlatform == stdenv.hostPlatform - then "propagatedBuildInputs" - else "depsTargetTargetPropagated"} = [ qtbase.dev ]; + depsTargetTargetPropagated = [ qtbase.dev ]; substitutions = { inherit debug; fix_qmake_libtool = ../hooks/fix-qmake-libtool.sh; From 61bbe3170805d509f6ed0ff9ef58f7cfe0375696 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Fri, 3 Nov 2023 22:14:43 -0700 Subject: [PATCH 17/20] qt5.qtbase: ignore hook propagated from buildPlatform by comparing stdenvs The main headache with cross-compiling QT is that our QT derivations go bananas with propagatedInputs. Unfortunately this means that both buildPackages.qtbase and hostPackages.qtbase get propagated into the dependencies of every cross-compiled builds, which triggers the hook check. Previously in https://github.com/NixOS/nixpkgs/pull/227900 I simply disabled the check outright for cross-compiled builds. This is a more refined solution, where we skip the hook if it propagates across a platform change. --- .../libraries/qt-5/hooks/qtbase-setup-hook.sh | 10 ++++++++++ pkgs/development/libraries/qt-5/modules/qtbase.nix | 1 + 2 files changed, 11 insertions(+) diff --git a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh index 1b57d676e1fc5da..ccd7592dfd37efe 100644 --- a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh +++ b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh @@ -1,3 +1,13 @@ +if [[ "x$stdenv" != "x@qtbase_stdenv@" ]]; then + echo "skipping qtbase-setup-hook.sh because of mismatch:" + echo " stdenv of current derivation: $stdenv" + echo " stdenv of qtbase.dev dependency: @qtbase_stdenv@" + echo " qtbase = @dev@" + return +fi + +echo "running qtbase-setup-hook.sh with hostOffset=$hostOffset targetOffset=$targetOffset: @out@" + if [[ -n "${__nix_qtbase-}" ]]; then # Throw an error if a different version of Qt was already set up. if [[ "$__nix_qtbase" != "@dev@" ]]; then diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix index 67e9bd5440d118b..3e51ffa5792ea45 100644 --- a/pkgs/development/libraries/qt-5/modules/qtbase.nix +++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix @@ -206,6 +206,7 @@ stdenv.mkDerivation (finalAttrs: ({ ''; env = { + qtbase_stdenv = stdenv.outPath; NIX_CFLAGS_COMPILE = toString ([ "-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ From d0ac44b20969f525d5f1074c823c40b875b86920 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 10 Mar 2023 20:01:27 +0200 Subject: [PATCH 18/20] qt5.wrapQtAppsHook: move libs to depsTargetTargetPropagated https://github.com/NixOS/nixpkgs/blob/master/doc/builders/special/makesetuphook.section.md --- pkgs/development/libraries/qt-5/5.15/default.nix | 9 ++++++--- pkgs/top-level/all-packages.nix | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index c8ac8aea9e59416..79b7ba1a79fc73f 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -11,6 +11,7 @@ Check for any minor version changes. , lib, stdenv, fetchurl, fetchgit, fetchpatch, fetchFromGitHub, makeSetupHook, makeWrapper , bison, cups ? null, harfbuzz, libGL, perl, python3 , gstreamer, gst-plugins-base, gtk3, dconf +, buildPackages , darwin # options @@ -320,11 +321,13 @@ let }; } ../hooks/qmake-hook.sh) { }; - wrapQtAppsHook = callPackage ({ makeBinaryWrapper, qtbase, qtwayland }: makeSetupHook { + wrapQtAppsHook = callPackage ({ makeBinaryWrapper, qtbase, qtwayland }: makeSetupHook ({ name = "wrap-qt5-apps-hook"; - propagatedBuildInputs = [ qtbase.dev makeBinaryWrapper ] + propagatedBuildInputs = [ buildPackages.makeBinaryWrapper ]; + depsTargetTargetPropagated = [ qtbase.dev ] ++ lib.optional stdenv.isLinux qtwayland.dev; - } ../hooks/wrap-qt-apps-hook.sh) { }; + }) + ../hooks/wrap-qt-apps-hook.sh) { }; }; baseScope = makeScopeWithSplicing' { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index af609d1e8a3ad6b..6d88b572739b737 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -24670,6 +24670,7 @@ with pkgs; inherit (__splicedPackages) makeScopeWithSplicing' generateSplicesForMkScope lib fetchurl fetchpatch fetchgit fetchFromGitHub makeSetupHook makeWrapper bison cups dconf harfbuzz libGL perl gtk3 python3 + buildPackages darwin; inherit (__splicedPackages.gst_all_1) gstreamer gst-plugins-base; inherit config; From e766731a14e57241441f6a881b3b6ce0c1e0078a Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 4 Nov 2023 15:31:19 -0700 Subject: [PATCH 19/20] qutebrowser: take python3 from buildPackages --- pkgs/applications/networking/browsers/qutebrowser/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/networking/browsers/qutebrowser/default.nix b/pkgs/applications/networking/browsers/qutebrowser/default.nix index 200f8e48c7e016d..62bed5a34f0e640 100644 --- a/pkgs/applications/networking/browsers/qutebrowser/default.nix +++ b/pkgs/applications/networking/browsers/qutebrowser/default.nix @@ -12,6 +12,7 @@ , widevine-cdm , enableVulkan ? stdenv.isLinux , vulkan-loader +, buildPackages }: let @@ -85,7 +86,7 @@ python3.pkgs.buildPythonApplication { runHook preInstall make -f misc/Makefile \ - PYTHON=${python3}/bin/python3 \ + PYTHON=${buildPackages.python3}/bin/python3 \ PREFIX=. \ DESTDIR="$out" \ DATAROOTDIR=/share \ From d2012567322fe9a96c1cf1ff5d65a8a234c58e99 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 4 Nov 2023 14:55:44 -0700 Subject: [PATCH 20/20] test.cross.sanity: add qt5.qutebrowser, firefox --- pkgs/test/cross/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index f844fc2b8ec5547..9f8209de17ed294 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -151,6 +151,10 @@ let # lots of interesting corner cases. Only expected to work for # x86_64-linux buildPlatform. pkgs.pkgsMusl.pkgsCross.gnu64.hello + + # Two web browsers -- exercises almost the entire packageset + pkgs.pkgsCross.aarch64-multiplatform.qt5.qutebrowser + pkgs.pkgsCross.aarch64-multiplatform.firefox ]; in {