1{
2 lib,
3 stdenv,
4 writeShellScriptBin,
5}:
6{
7 versions ? [ ],
8 xcodeBaseDir ? "/Applications/Xcode.app",
9}:
10
11assert stdenv.hostPlatform.isDarwin;
12let
13 xcodebuildPath = "${xcodeBaseDir}/Contents/Developer/usr/bin/xcodebuild";
14
15 xcodebuildWrapper = writeShellScriptBin "xcodebuild" ''
16 currentVer="$(${xcodebuildPath} -version | awk 'NR==1{print $2}')"
17 wrapperVers=(${lib.concatStringsSep " " versions})
18
19 for ver in "''${wrapperVers[@]}"; do
20 if [[ "$currentVer" == "$ver" ]]; then
21 # here exec replaces the shell without creating a new process
22 # https://www.gnu.org/software/bash/manual/bash.html#index-exec
23 exec "${xcodebuildPath}" "$@"
24 fi
25 done
26
27 echo "The installed Xcode version ($currentVer) does not match any of the allowed versions: ${lib.concatStringsSep ", " versions}"
28 echo "Please update your local Xcode installation to match one of the allowed versions"
29 exit 1
30 '';
31in
32stdenv.mkDerivation {
33 name = "xcode-wrapper-impure";
34 # Fails in sandbox. Use `--option sandbox relaxed` or `--option sandbox false`.
35 __noChroot = true;
36 buildCommand = ''
37 mkdir -p $out/bin
38 cd $out/bin
39 ${
40 if versions == [ ] then
41 ''
42 ln -s "${xcodebuildPath}"
43 ''
44 else
45 ''
46 ln -s "${xcodebuildWrapper}/bin/xcode-select"
47 ''
48 }
49 ln -s /usr/bin/security
50 ln -s /usr/bin/codesign
51 ln -s /usr/bin/xcrun
52 ln -s /usr/bin/plutil
53 ln -s /usr/bin/clang
54 ln -s /usr/bin/lipo
55 ln -s /usr/bin/file
56 ln -s /usr/bin/rev
57 ln -s "${xcodeBaseDir}/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator"
58
59 cd ..
60 ln -s "${xcodeBaseDir}/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs"
61 '';
62}