1{
2 stdenv,
3 lib,
4 composeXcodeWrapper,
5}:
6{
7 name,
8 app ? null,
9 bundleId ? null,
10 ...
11}@args:
12
13assert app != null -> bundleId != null;
14
15let
16 xcodewrapperArgs = builtins.intersectAttrs (builtins.functionArgs composeXcodeWrapper) args;
17
18 xcodewrapper = composeXcodeWrapper xcodewrapperArgs;
19in
20stdenv.mkDerivation {
21 name = lib.replaceStrings [ " " ] [ "" ] name;
22 buildCommand = ''
23 mkdir -p $out/bin
24 cat > $out/bin/run-test-simulator << "EOF"
25 #! ${stdenv.shell} -e
26
27 if [ "$1" = "" ]
28 then
29 # Show the user the possibile UDIDs and let him pick one, if none is provided as a command-line parameter
30 xcrun simctl list
31
32 echo "Please provide a UDID of a simulator:"
33 read udid
34 else
35 # If a parameter has been provided, consider that a device UDID and use that
36 udid="$1"
37 fi
38
39 # Open the simulator instance
40 open -a "$(readlink "${xcodewrapper}/bin/Simulator")" --args -CurrentDeviceUDID $udid
41
42 ${lib.optionalString (app != null) ''
43 # Copy the app and restore the write permissions
44 appTmpDir=$(mktemp -d -t appTmpDir)
45 cp -r "$(echo ${app}/*.app)" "$appTmpDir"
46 chmod -R 755 "$(echo $appTmpDir/*.app)"
47
48 # Wait for the simulator to start
49 echo "Press enter when the simulator is started..."
50 read
51
52 # Install the app
53 xcrun simctl install "$udid" "$(echo $appTmpDir/*.app)"
54
55 # Remove the app tempdir
56 rm -Rf $appTmpDir
57
58 # Launch the app in the simulator
59 xcrun simctl launch $udid "${bundleId}"
60 EOF
61
62 chmod +x $out/bin/run-test-simulator
63 ''}
64 '';
65}