From afb3563bdcdd0654ebcabd2046b0c82ef19a2783 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak <pavol@rusnak.io>
Date: Thu, 3 Jun 2021 20:26:32 +0200
Subject: [PATCH 1/2] qt5: don't use dontUseXcbuild in qtwebengine

dontUseXcbuild was dropped in 0534ceac816cb708434b126e38e98b925516498a
---
 pkgs/development/libraries/qt-5/modules/qtwebengine.nix | 1 -
 1 file changed, 1 deletion(-)

diff --git a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
index 729c5f388f99..e60ae2082f4a 100644
--- a/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtwebengine.nix
@@ -220,7 +220,6 @@ qtModule {
 
   dontUseNinjaBuild = true;
   dontUseNinjaInstall = true;
-  dontUseXcbuild = true;
 
   postInstall = lib.optionalString stdenv.isLinux ''
     cat > $out/libexec/qt.conf <<EOF

From ce14ca10a66aef508dce88c2806e7ac0d00a9ebd Mon Sep 17 00:00:00 2001
From: Pavol Rusnak <pavol@rusnak.io>
Date: Thu, 3 Jun 2021 20:21:38 +0200
Subject: [PATCH 2/2] qt5: use xcbuild on darwin, cleanup

---
 .../libraries/qt-5/modules/qtbase.nix           | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix
index 0d0bef342b02..4291390c72ca 100644
--- a/pkgs/development/libraries/qt-5/modules/qtbase.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix
@@ -5,7 +5,7 @@
   coreutils, bison, flex, gdb, gperf, lndir, perl, pkg-config, python3,
   which,
   # darwin support
-  darwin, libiconv,
+  darwin, libiconv, xcbuild,
 
   dbus, fontconfig, freetype, glib, harfbuzz, icu, libX11, libXcomposite,
   libXcursor, libXext, libXi, libXrender, libinput, libjpeg, libpng,
@@ -90,7 +90,8 @@ stdenv.mkDerivation {
     ++ lib.optional (postgresql != null) postgresql;
 
   nativeBuildInputs =
-    [ bison flex gperf lndir perl pkg-config which ];
+    [ bison flex gperf lndir perl pkg-config which ]
+    ++ lib.optionals stdenv.isDarwin [ xcbuild ];
 
   propagatedNativeBuildInputs = [ lndir ];
 
@@ -131,22 +132,16 @@ stdenv.mkDerivation {
       then
         ''
           sed -i \
-              -e 's|! /usr/bin/xcode-select --print-path >/dev/null 2>&1;|false;|' \
-              -e 's|! /usr/bin/xcrun -find xcodebuild >/dev/null 2>&1;|false;|' \
-              -e 's|sysroot=$(/usr/bin/xcodebuild -sdk $sdk -version Path 2>/dev/null)|sysroot=/nonsense|' \
-              -e 's|sysroot=$(/usr/bin/xcrun --sdk $sdk --show-sdk-path 2>/dev/null)|sysroot=/nonsense|' \
+              -e 's|/usr/bin/xcode-select|xcode-select|' \
+              -e 's|/usr/bin/xcrun|xcrun|' \
+              -e 's|/usr/bin/xcodebuild|xcodebuild|' \
               -e 's|QMAKE_CONF_COMPILER=`getXQMakeConf QMAKE_CXX`|QMAKE_CXX="clang++"\nQMAKE_CONF_COMPILER="clang++"|' \
-              -e 's|XCRUN=`/usr/bin/xcrun -sdk macosx clang -v 2>&1`|XCRUN="clang -v 2>&1"|' \
-              -e 's#sdk_val=$(/usr/bin/xcrun -sdk $sdk -find $(echo $val | cut -d \x27 \x27 -f 1))##' \
-              -e 's#val=$(echo $sdk_val $(echo $val | cut -s -d \x27 \x27 -f 2-))##' \
               ./configure
               substituteInPlace ./mkspecs/common/mac.conf \
                   --replace "/System/Library/Frameworks/OpenGL.framework/" "${darwin.apple_sdk.frameworks.OpenGL}/Library/Frameworks/OpenGL.framework/"
               substituteInPlace ./mkspecs/common/mac.conf \
                   --replace "/System/Library/Frameworks/AGL.framework/" "${darwin.apple_sdk.frameworks.AGL}/Library/Frameworks/AGL.framework/"
         ''
-        # Note on the above: \x27 is a way if including a single-quote
-        # character in the sed string arguments.
       else
         lib.optionalString libGLSupported
           ''