+47
-8
@@ -1,5 +1,14 @@
|
||||
{ pkgs, lib, config, inputs, ... }:
|
||||
|
||||
<@if(eq(context.project.mobile,"expo"))>
|
||||
let
|
||||
# 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 = ''
|
||||
dev_dir="$(/usr/bin/env -u DEVELOPER_DIR /usr/bin/xcode-select -p 2>/dev/null)"
|
||||
[ -x "$dev_dir/usr/bin/simctl" ] || dev_dir=/Applications/Xcode.app/Contents/Developer
|
||||
'';
|
||||
in
|
||||
<@endif>
|
||||
{
|
||||
packages = [
|
||||
pkgs.bun
|
||||
@@ -33,6 +42,8 @@
|
||||
# The emulator's bundled libs are only needed on Linux; macOS uses DYLD paths.
|
||||
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
|
||||
'';
|
||||
# Use a system image matching the host CPU (arm64 on Apple Silicon, x86_64 elsewhere).
|
||||
scripts.create-avd.exec = ''
|
||||
@@ -40,16 +51,39 @@
|
||||
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"
|
||||
fi
|
||||
'';
|
||||
# macOS only: run on the iOS simulator when Xcode with a simulator is installed.
|
||||
# macOS only: Nix can't provide Xcode, so report what the iOS build still needs.
|
||||
scripts.ios-check = lib.mkIf pkgs.stdenv.isDarwin {
|
||||
exec = ''
|
||||
${xcodeDevDir}
|
||||
export DEVELOPER_DIR="$dev_dir"
|
||||
problems=""
|
||||
missing() { problems+=" - $1"$'\n'; }
|
||||
if [ ! -x "$dev_dir/usr/bin/simctl" ]; then
|
||||
missing "Xcode is not installed. Install it from the App Store: https://apps.apple.com/app/xcode/id497799835"
|
||||
else
|
||||
if ! /usr/bin/xcodebuild -license check >/dev/null 2>&1 || ! /usr/bin/xcodebuild -checkFirstLaunchStatus >/dev/null 2>&1; then
|
||||
missing "Xcode setup is incomplete (license or first-launch components). Run: sudo xcodebuild -runFirstLaunch"
|
||||
fi
|
||||
if ! /usr/bin/xcrun simctl list runtimes 2>/dev/null | grep -q '^iOS '; then
|
||||
missing "No iOS simulator runtime is installed. Run: xcodebuild -downloadPlatform iOS"
|
||||
elif ! /usr/bin/xcrun simctl list devices available 2>/dev/null | grep -q iPhone; then
|
||||
missing "No iPhone simulator exists. Create one in Xcode > Window > Devices and Simulators"
|
||||
fi
|
||||
fi
|
||||
if [ -n "$problems" ]; then
|
||||
printf 'iOS simulator builds are disabled until this is fixed:\n%s' "$problems" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
};
|
||||
# macOS only: run on the iOS simulator when ios-check passes.
|
||||
scripts.run-ios = lib.mkIf pkgs.stdenv.isDarwin {
|
||||
exec = ''
|
||||
# devenv points DEVELOPER_DIR at the Nix SDK, which xcode-select would echo back.
|
||||
dev_dir="$(/usr/bin/env -u DEVELOPER_DIR /usr/bin/xcode-select -p 2>/dev/null)"
|
||||
[ -x "$dev_dir/usr/bin/simctl" ] || dev_dir=/Applications/Xcode.app/Contents/Developer
|
||||
if ! DEVELOPER_DIR="$dev_dir" /usr/bin/xcrun simctl list devices available 2>/dev/null | grep -q iPhone; then
|
||||
echo "No Xcode iOS simulator found, skipping iOS."
|
||||
if ! ios-check; then
|
||||
echo "Skipping iOS."
|
||||
exit 0
|
||||
fi
|
||||
${xcodeDevDir}
|
||||
# devenv's Nix Apple SDK, xcrun and compiler wrappers break xcodebuild, so build in a clean env.
|
||||
exec /usr/bin/env -i HOME="$HOME" USER="$USER" TERM="$TERM" LANG=en_US.UTF-8 \
|
||||
DEVELOPER_DIR="$dev_dir" \
|
||||
@@ -110,7 +144,12 @@
|
||||
after = ["devenv:processes:createavd@completed"];
|
||||
};
|
||||
expodev = {
|
||||
exec = "bunx expo run:android";
|
||||
# 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
|
||||
'';
|
||||
cwd = "./apps/mobile";
|
||||
after= ["devenv:processes:emulator@started"];
|
||||
restart = {
|
||||
|
||||
Reference in New Issue
Block a user