nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# For compatibility, convert makeWrapperArgs to an array unless we are using
2# structured attributes. That is, we ensure that makeWrapperArgs is always an
3# array.
4# See https://github.com/NixOS/nixpkgs/blob/858f4db3048c5be3527e183470e93c1a72c5727c/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh#L1-L3
5# and https://github.com/NixOS/nixpkgs/pull/313005#issuecomment-2175482920
6if [[ -z $__structuredAttrs ]]; then
7 makeWrapperArgs=( ${makeWrapperArgs-} )
8fi
9
10# First argument is the executable you want to wrap,
11# the second is the destination for the wrapper.
12wrapDotnetProgram() {
13 local -r dotnetRuntime=@dotnetRuntime@
14 local -r wrapperPath=@wrapperPath@
15
16 local -r dotnetFromEnvScript='dotnetFromEnv() {
17 local dotnetPath
18 if command -v dotnet 2>&1 >/dev/null; then
19 dotnetPath=$(which dotnet) && \
20 dotnetPath=$(realpath "$dotnetPath") && \
21 dotnetPath=$(dirname "$dotnetPath") && \
22 export DOTNET_ROOT="$dotnetPath"
23 fi
24}
25dotnetFromEnv'
26
27 if [[ -n $__structuredAttrs ]]; then
28 local -r dotnetRuntimeDepsArray=( "${dotnetRuntimeDeps[@]}" )
29 else
30 local -r dotnetRuntimeDepsArray=($dotnetRuntimeDeps)
31 fi
32
33 local dotnetRuntimeDepsFlags=()
34 if (( ${#dotnetRuntimeDepsArray[@]} > 0 )); then
35 local libraryPathArray=("${dotnetRuntimeDepsArray[@]/%//lib}")
36 local OLDIFS="$IFS" IFS=':'
37 dotnetRuntimeDepsFlags+=("--suffix" "LD_LIBRARY_PATH" ":" "${libraryPathArray[*]}")
38 IFS="$OLDIFS"
39 fi
40
41 local dotnetRootFlagsArray=()
42 if [[ -z ${dotnetSelfContainedBuild-} ]]; then
43 if [[ -n ${useDotnetFromEnv-} ]]; then
44 # if dotnet CLI is available, set DOTNET_ROOT based on it. Otherwise set to default .NET runtime
45 dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$wrapperPath")
46 dotnetRootFlagsArray+=("--run" "$dotnetFromEnvScript")
47 if [[ -n $dotnetRuntime ]]; then
48 dotnetRootFlagsArray+=("--set-default" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
49 dotnetRootFlagsArray+=("--suffix" "PATH" ":" "$dotnetRuntime/bin")
50 fi
51 elif [[ -n $dotnetRuntime ]]; then
52 dotnetRootFlagsArray+=("--set" "DOTNET_ROOT" "$dotnetRuntime/share/dotnet")
53 dotnetRootFlagsArray+=("--prefix" "PATH" ":" "$dotnetRuntime/bin")
54 fi
55 fi
56
57 makeWrapper "$1" "$2" \
58 "${dotnetRuntimeDepsFlags[@]}" \
59 "${dotnetRootFlagsArray[@]}" \
60 "${gappsWrapperArgs[@]}" \
61 "${makeWrapperArgs[@]}"
62
63 echo "installed wrapper to "$2""
64}
65
66dotnetFixupHook() {
67 local -r dotnetInstallPath="${dotnetInstallPath-$out/lib/$pname}"
68
69 local executable executableBasename
70
71 # check if dotnetExecutables is declared (including empty values, in which case we generate no executables)
72 if declare -p dotnetExecutables &>/dev/null; then
73 if [[ -n $__structuredAttrs ]]; then
74 local dotnetExecutablesArray=( "${dotnetExecutables[@]}" )
75 else
76 local dotnetExecutablesArray=($dotnetExecutables)
77 fi
78 for executable in "${dotnetExecutablesArray[@]}"; do
79 executableBasename=$(basename "$executable")
80
81 local path="$dotnetInstallPath/$executable"
82
83 if test -x "$path"; then
84 wrapDotnetProgram "$path" "$out/bin/$executableBasename"
85 else
86 echo "Specified binary \"$executable\" is either not an executable or does not exist!"
87 echo "Looked in $path"
88 exit 1
89 fi
90 done
91 else
92 while IFS= read -d '' executable; do
93 executableBasename=$(basename "$executable")
94 wrapDotnetProgram "$executable" "$out/bin/$executableBasename" \;
95 done < <(find "$dotnetInstallPath" ! -name "*.dll" -executable -type f -print0)
96 fi
97}
98
99if [[ -z "${dontFixup-}" && -z "${dontDotnetFixup-}" ]]; then
100 appendToVar preFixupPhases dotnetFixupHook
101fi