some cleanup
This commit is contained in:
+40
-16
@@ -1,6 +1,11 @@
|
||||
{ pkgs, lib, config, inputs, ... }:
|
||||
<@if(eq(context.project.mobile,"expo"))>
|
||||
let
|
||||
avdName = "Pixel_5_API36";
|
||||
# Fixed console port, so scripts can address this emulator as emulator-5554 even when others run.
|
||||
emulatorSerial = "emulator-5554";
|
||||
# Apple's xcrun, for tools that need `xcrun simctl`, which the Nix SDK's xcrun lacks.
|
||||
systemXcrun = pkgs.runCommand "system-xcrun" { } "mkdir -p $out/bin && ln -s /usr/bin/xcrun $out/bin/xcrun";
|
||||
# Sets dev_dir to Xcode's developer dir. devenv points DEVELOPER_DIR at the Nix SDK,
|
||||
# which xcode-select would echo back, so it is unset for the lookup.
|
||||
xcodeDevDir = ''
|
||||
@@ -22,14 +27,14 @@ in
|
||||
pkgs.protoc-gen-connect-go
|
||||
pkgs.protoc-gen-es
|
||||
pkgs.cobra-cli
|
||||
];
|
||||
]<@if(eq(context.project.mobile,"expo"))> ++ lib.optionals pkgs.stdenv.isDarwin [ pkgs.cocoapods ]<@endif>;
|
||||
<@if(eq(context.project.mobile,"expo"))>
|
||||
android = {
|
||||
enable = true;
|
||||
emulator = {
|
||||
enable = true;
|
||||
};
|
||||
buildTools.version = ["34.0.0" "35.0.0" "36.0.0" ]; # add 36.0.0
|
||||
buildTools.version = [ "34.0.0" "35.0.0" "36.0.0" ];
|
||||
reactNative.enable = true;
|
||||
android-studio = {
|
||||
enable = false;
|
||||
@@ -43,12 +48,16 @@ in
|
||||
enterShell = lib.optionalString pkgs.stdenv.isLinux ''
|
||||
export LD_LIBRARY_PATH=$ANDROID_HOME/emulator/lib64:$LD_LIBRARY_PATH
|
||||
'' + lib.optionalString pkgs.stdenv.isDarwin ''
|
||||
ios-check || true
|
||||
# Re-check at most daily once the iOS requirements are met. SKIP_IOS_CHECK=1 turns this off.
|
||||
ios_check_ok="$DEVENV_STATE/ios-check-ok"
|
||||
if [ -z "''${SKIP_IOS_CHECK:-}" ] && [ -z "$(find "$ios_check_ok" -mtime -1 2>/dev/null)" ]; then
|
||||
if ios-check; then touch "$ios_check_ok"; else echo "Set SKIP_IOS_CHECK=1 to hide this." >&2; fi
|
||||
fi
|
||||
'';
|
||||
# Use a system image matching the host CPU (arm64 on Apple Silicon, x86_64 elsewhere).
|
||||
scripts.create-avd.exec = ''
|
||||
if ! avdmanager list avd -c | grep -qx "Pixel_5_API34"; then
|
||||
echo no | avdmanager create avd -n "Pixel_5_API34" -k "system-images;android-34;google_apis_playstore;${if pkgs.stdenv.hostPlatform.isAarch64 then "arm64-v8a" else "x86_64"}" -d "pixel_5"
|
||||
if ! avdmanager list avd -c | grep -qx "${avdName}"; then
|
||||
echo no | avdmanager create avd -n "${avdName}" -k "system-images;android-36;google_apis_playstore;${if pkgs.stdenv.hostPlatform.isAarch64 then "arm64-v8a" else "x86_64"}" -d "pixel_5"
|
||||
fi
|
||||
'';
|
||||
# macOS only: Nix can't provide Xcode, so report what the iOS build still needs.
|
||||
@@ -140,27 +149,42 @@ in
|
||||
exec = "create-avd";
|
||||
};
|
||||
emulator = {
|
||||
exec = "emulator -avd Pixel_5_API34";
|
||||
exec = "emulator -avd ${avdName} -port 5554";
|
||||
after = ["devenv:processes:createavd@completed"];
|
||||
};
|
||||
# One Metro bundler serves both apps, so iOS doesn't depend on the Android build.
|
||||
metro = {
|
||||
exec = lib.optionalString pkgs.stdenv.isDarwin ''
|
||||
# Expo's CLI calls `xcrun simctl` to talk to the iOS simulator.
|
||||
${xcodeDevDir}
|
||||
export DEVELOPER_DIR="$dev_dir" PATH="${systemXcrun}/bin:$PATH"
|
||||
'' + "exec bunx expo start --dev-client";
|
||||
cwd = "./apps/mobile";
|
||||
ready.http.get = { port = 8081; path = "/status"; };
|
||||
};
|
||||
expodev = {
|
||||
# Wait for the emulator to finish booting, otherwise expo tries to start a second copy of the AVD.
|
||||
exec = ''
|
||||
adb -e wait-for-device
|
||||
until [ "$(adb -e shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = 1 ]; do sleep 2; done
|
||||
bunx expo run:android
|
||||
# Wait for the emulator to boot, otherwise expo tries to start a second copy of the AVD.
|
||||
for _ in $(seq 150); do
|
||||
if [ "$(adb -s ${emulatorSerial} shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = 1 ]; then
|
||||
# Lets the emulator and USB-connected devices reach the API on the host at 127.0.0.1:8080.
|
||||
for device in $(adb devices | awk 'NR > 1 && $2 == "device" { print $1 }'); do
|
||||
adb -s "$device" reverse tcp:8080 tcp:8080
|
||||
done
|
||||
exec bunx expo run:android --no-bundler --device ${avdName}
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "The Android emulator didn't finish booting within 5 minutes, see the emulator log." >&2
|
||||
exit 1
|
||||
'';
|
||||
cwd = "./apps/mobile";
|
||||
after= ["devenv:processes:emulator@started"];
|
||||
restart = {
|
||||
on = "always";
|
||||
};
|
||||
after = [ "devenv:processes:emulator@started" "devenv:processes:metro" ];
|
||||
};
|
||||
# Reuses the Metro bundler started by expodev.
|
||||
expoios = lib.mkIf pkgs.stdenv.isDarwin {
|
||||
exec = "run-ios";
|
||||
cwd = "./apps/mobile";
|
||||
after = ["devenv:processes:expodev@started"];
|
||||
after = [ "devenv:processes:metro" ];
|
||||
};
|
||||
<@endif>
|
||||
sqlwatcher = {
|
||||
|
||||
Reference in New Issue
Block a user