1if [[ -z "${__nix_wrapQtAppsHook-}" ]]; then
2__nix_wrapQtAppsHook=1 # Don't run this hook more than once.
3
4# Inherit arguments given in mkDerivation
5qtWrapperArgs=( ${qtWrapperArgs-} )
6
7qtHostPathSeen=()
8
9qtUnseenHostPath() {
10 for pkg in "${qtHostPathSeen[@]}"
11 do
12 if [ "${pkg:?}" == "$1" ]
13 then
14 return 1
15 fi
16 done
17
18 qtHostPathSeen+=("$1")
19 return 0
20}
21
22qtHostPathHook() {
23 qtUnseenHostPath "$1" || return 0
24
25 local pluginDir="$1/${qtPluginPrefix:?}"
26 if [ -d "$pluginDir" ]
27 then
28 qtWrapperArgs+=(--prefix QT_PLUGIN_PATH : "$pluginDir")
29 fi
30
31 local qmlDir="$1/${qtQmlPrefix:?}"
32 if [ -d "$qmlDir" ]
33 then
34 qtWrapperArgs+=(--prefix NIXPKGS_QT5_QML_IMPORT_PATH : "$qmlDir")
35 fi
36}
37addEnvHooks "$targetOffset" qtHostPathHook
38
39makeQtWrapper() {
40 local original="$1"
41 local wrapper="$2"
42 shift 2
43 makeWrapper "$original" "$wrapper" "${qtWrapperArgs[@]}" "$@"
44}
45
46wrapQtApp() {
47 local program="$1"
48 shift 1
49 wrapProgram "$program" "${qtWrapperArgs[@]}" "$@"
50}
51
52qtOwnPathsHook() {
53 local xdgDataDir="${!outputBin}/share"
54 if [ -d "$xdgDataDir" ]
55 then
56 qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$xdgDataDir")
57 fi
58
59 local xdgConfigDir="${!outputBin}/etc/xdg"
60 if [ -d "$xdgConfigDir" ]
61 then
62 qtWrapperArgs+=(--prefix XDG_CONFIG_DIRS : "$xdgConfigDir")
63 fi
64
65 qtHostPathHook "${!outputBin}"
66}
67
68appendToVar preFixupPhases qtOwnPathsHook
69
70# Note: $qtWrapperArgs still gets defined even if ${dontWrapQtApps-} is set.
71wrapQtAppsHook() {
72 # skip this hook when requested
73 [ -z "${dontWrapQtApps-}" ] || return 0
74
75 # guard against running multiple times (e.g. due to propagation)
76 [ -z "$wrapQtAppsHookHasRun" ] || return 0
77 wrapQtAppsHookHasRun=1
78
79 local targetDirs=( "$prefix/bin" "$prefix/sbin" "$prefix/libexec" "$prefix/Applications" "$prefix/"*.app )
80 echo "wrapping Qt applications in ${targetDirs[@]}"
81
82 for targetDir in "${targetDirs[@]}"
83 do
84 [ -d "$targetDir" ] || continue
85
86 find "$targetDir" ! -type d -executable -print0 | while IFS= read -r -d '' file
87 do
88 isELF "$file" || isMachO "$file" || continue
89
90 if [ -h "$file" ]
91 then
92 target="$(readlink -e "$file")"
93 echo "wrapping $file -> $target"
94 rm "$file"
95 makeQtWrapper "$target" "$file"
96 elif [ -f "$file" ]
97 then
98 echo "wrapping $file"
99 wrapQtApp "$file"
100 fi
101 done
102 done
103}
104
105fixupOutputHooks+=(wrapQtAppsHook)
106
107fi