nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 89 lines 3.1 kB view raw
1# shellcheck shell=bash 2gappsWrapperArgs=() 3 4find_gio_modules() { 5 if [ -d "$1/lib/gio/modules" ] && [ -n "$(ls -A "$1/lib/gio/modules")" ] ; then 6 gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$1/lib/gio/modules") 7 fi 8} 9 10addEnvHooks "${targetOffset:?}" find_gio_modules 11 12gappsWrapperArgsHook() { 13 if [ -n "$GDK_PIXBUF_MODULE_FILE" ]; then 14 gappsWrapperArgs+=(--set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE") 15 fi 16 17 if [ -n "$GSETTINGS_SCHEMAS_PATH" ]; then 18 gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH") 19 fi 20 21 # Check for prefix as well 22 if [ -d "${prefix:?}/share" ]; then 23 gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$prefix/share") 24 fi 25 26 if [ -d "$prefix/lib/gio/modules" ] && [ -n "$(ls -A "$prefix/lib/gio/modules")" ]; then 27 gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$prefix/lib/gio/modules") 28 fi 29 30 for v in ${wrapPrefixVariables:-} GST_PLUGIN_SYSTEM_PATH_1_0 GI_TYPELIB_PATH GRL_PLUGIN_PATH; do 31 if [ -n "${!v:-}" ]; then 32 gappsWrapperArgs+=(--prefix "$v" : "${!v}") 33 fi 34 done 35} 36 37appendToVar preFixupPhases gappsWrapperArgsHook 38 39wrapGApp() { 40 local program="$1" 41 shift 1 42 wrapProgram "$program" "${gappsWrapperArgs[@]}" "$@" 43} 44 45# Note: $gappsWrapperArgs still gets defined even if ${dontWrapGApps-} is set. 46wrapGAppsHook() { 47 # guard against running multiple times (e.g. due to propagation) 48 [ -z "$wrapGAppsHookHasRun" ] || return 0 49 wrapGAppsHookHasRun=1 50 51 if [[ -z "${dontWrapGApps:-}" ]]; then 52 targetDirsThatExist=() 53 targetDirsRealPath=() 54 55 # wrap binaries 56 targetDirs=("${prefix}/bin" "${prefix}/libexec") 57 for targetDir in "${targetDirs[@]}"; do 58 if [[ -d "${targetDir}" ]]; then 59 targetDirsThatExist+=("${targetDir}") 60 targetDirsRealPath+=("$(realpath "${targetDir}")/") 61 find "${targetDir}" -type f -executable -print0 | 62 while IFS= read -r -d '' file; do 63 echo "Wrapping program '${file}'" 64 wrapGApp "${file}" 65 done 66 fi 67 done 68 69 # wrap links to binaries that point outside targetDirs 70 # Note: links to binaries within targetDirs do not need 71 # to be wrapped as the binaries have already been wrapped 72 if [[ ${#targetDirsThatExist[@]} -ne 0 ]]; then 73 find "${targetDirsThatExist[@]}" -type l -xtype f -executable -print0 | 74 while IFS= read -r -d '' linkPath; do 75 linkPathReal=$(realpath "${linkPath}") 76 for targetPath in "${targetDirsRealPath[@]}"; do 77 if [[ "$linkPathReal" == "$targetPath"* ]]; then 78 echo "Not wrapping link: '$linkPath' (already wrapped)" 79 continue 2 80 fi 81 done 82 echo "Wrapping link: '$linkPath'" 83 wrapGApp "${linkPath}" 84 done 85 fi 86 fi 87} 88 89fixupOutputHooks+=(wrapGAppsHook)