diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-12-06 19:57:55 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-02-08 13:48:30 +0000 |
commit | bf3aadfdd39aa197e18bade671fab6726349ffa4 (patch) | |
tree | 698567af766ed441d757b57a7b21e68d4a342a2b /nixpkgs/pkgs/development/libraries/qt-6/hooks | |
parent | f4afc5a01d9539ce09e47494e679c51f80723d07 (diff) | |
parent | 99665eb45f58d959d2cb9e49ddb960c79d596f33 (diff) | |
download | nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.gz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.bz2 nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.lz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.xz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.zst nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.zip |
Merge commit '99665eb45f58d959d2cb9e49ddb960c79d596f33'
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/qt-6/hooks')
-rw-r--r-- | nixpkgs/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh | 43 | ||||
-rw-r--r-- | nixpkgs/pkgs/development/libraries/qt-6/hooks/wrap-qt-apps-hook.sh | 110 |
2 files changed, 153 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh b/nixpkgs/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh new file mode 100644 index 000000000000..0ae969e8f8fc --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh @@ -0,0 +1,43 @@ +if [[ -n "${__nix_qtbase-}" ]]; then + # Throw an error if a different version of Qt was already set up. + if [[ "$__nix_qtbase" != "@dev@" ]]; then + echo >&2 "Error: detected mismatched Qt dependencies:" + echo >&2 " @dev@" + echo >&2 " $__nix_qtbase" + exit 1 + fi +else # Only set up Qt once. +__nix_qtbase="@dev@" + +qtPluginPrefix=@qtPluginPrefix@ +qtQmlPrefix=@qtQmlPrefix@ + +# Disable debug symbols if qtbase was built without debugging. +# This stops -dev paths from leaking into other outputs. +if [ -z "@debug@" ]; then + NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-DQT_NO_DEBUG" +fi + +# Integration with CMake: +# Set the CMake build type corresponding to how qtbase was built. +if [ -n "@debug@" ]; then + cmakeBuildType="Debug" +else + cmakeBuildType="Release" +fi + +qtPreHook() { + # Check that wrapQtAppsHook is used, or it is explicitly disabled. + if [[ -z "$__nix_wrapQtAppsHook" && -z "$dontWrapQtApps" ]]; then + echo >&2 "Error: wrapQtAppsHook is not used, and dontWrapQtApps is not set." + exit 1 + fi +} +prePhases+=" qtPreHook" + +addQtModulePrefix () { + addToSearchPath QT_ADDITIONAL_PACKAGES_PREFIX_PATH $1 +} +addEnvHooks "$hostOffset" addQtModulePrefix + +fi diff --git a/nixpkgs/pkgs/development/libraries/qt-6/hooks/wrap-qt-apps-hook.sh b/nixpkgs/pkgs/development/libraries/qt-6/hooks/wrap-qt-apps-hook.sh new file mode 100644 index 000000000000..b669da3d058c --- /dev/null +++ b/nixpkgs/pkgs/development/libraries/qt-6/hooks/wrap-qt-apps-hook.sh @@ -0,0 +1,110 @@ +if [[ -z "${__nix_wrapQtAppsHook-}" ]]; then +__nix_wrapQtAppsHook=1 # Don't run this hook more than once. + +# Inherit arguments given in mkDerivation +qtWrapperArgs=( ${qtWrapperArgs-} ) + +qtHostPathSeen=() + +qtUnseenHostPath() { + for pkg in "${qtHostPathSeen[@]}" + do + if [ "${pkg:?}" == "$1" ] + then + return 1 + fi + done + + qtHostPathSeen+=("$1") + return 0 +} + +qtHostPathHook() { + qtUnseenHostPath "$1" || return 0 + + if ! [ -v qtPluginPrefix ] + then + echo "wrapQtAppsHook qtHostPathHook: qtPluginPrefix is unset. hint: add qt6.qtbase to buildInputs" + fi + + local pluginDir="$1/${qtPluginPrefix:?}" + if [ -d "$pluginDir" ] + then + qtWrapperArgs+=(--prefix QT_PLUGIN_PATH : "$pluginDir") + fi + + local qmlDir="$1/${qtQmlPrefix:?}" + if [ -d "$qmlDir" ] + then + qtWrapperArgs+=(--prefix QML2_IMPORT_PATH : "$qmlDir") + fi +} +addEnvHooks "$targetOffset" qtHostPathHook + +makeQtWrapper() { + local original="$1" + local wrapper="$2" + shift 2 + makeWrapper "$original" "$wrapper" "${qtWrapperArgs[@]}" "$@" +} + +wrapQtApp() { + local program="$1" + shift 1 + wrapProgram "$program" "${qtWrapperArgs[@]}" "$@" +} + +qtOwnPathsHook() { + local xdgDataDir="${!outputBin}/share" + if [ -d "$xdgDataDir" ] + then + qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$xdgDataDir") + fi + + local xdgConfigDir="${!outputBin}/etc/xdg" + if [ -d "$xdgConfigDir" ] + then + qtWrapperArgs+=(--prefix XDG_CONFIG_DIRS : "$xdgConfigDir") + fi + + qtHostPathHook "${!outputBin}" +} + +preFixupPhases+=" qtOwnPathsHook" + +# Note: $qtWrapperArgs still gets defined even if ${dontWrapQtApps-} is set. +wrapQtAppsHook() { + # skip this hook when requested + [ -z "${dontWrapQtApps-}" ] || return 0 + + # guard against running multiple times (e.g. due to propagation) + [ -z "$wrapQtAppsHookHasRun" ] || return 0 + wrapQtAppsHookHasRun=1 + + local targetDirs=( "$prefix/bin" "$prefix/sbin" "$prefix/libexec" "$prefix/Applications" "$prefix/"*.app ) + echo "wrapping Qt applications in ${targetDirs[@]}" + + for targetDir in "${targetDirs[@]}" + do + [ -d "$targetDir" ] || continue + + find "$targetDir" ! -type d -executable -print0 | while IFS= read -r -d '' file + do + if [ -f "$file" ] + then + echo "wrapping $file" + wrapQtApp "$file" + elif [ -h "$file" ] + then + target="$(readlink -e "$file")" + echo "wrapping $file -> $target" + rm "$file" + makeQtWrapper "$target" "$file" + fi + done + done +} + +fixupOutputHooks+=(wrapQtAppsHook) + +fi |