This document outlines how to set up your React Native development environment using Nix flakes for reproducibility and isolation.
This was tested on an Arch Linux system with AMD CPU and GPU. There are likely problems with NVIDIA GPUs.
Compatibility with Microsoft WSL2 is not guaranteed, but should work withoud major issues, except for the emulator.
- Nix installed: https://nixos.org/download.html
- Git: Required for cloning the repository.
- KVM (for emulator, if enabled): Ensure KVM is enabled and your user is in the
kvmgroup for optimal emulator performance:sudo usermod -aG kvm $USER && newgrp kvm # (or log out/in) kvm-ok # Verify KVM acceleration
- GPU Drivers (for emulator, if enabled): For hardware-accelerated emulator (AMD/Intel), ensure host Vulkan drivers are working:
If not, install
vulkaninfo | grep -i "device name" # Should show your GPU
vulkan-radeon(AMD) orvulkan-intel(Intel) on your host system and reboot.
-
Clone the Project:
git clone <your-fork-url> cd <your-fork-name>
-
Enter the Development Shell:
If you have
npmoryarninstalled, use the defined scripts:- For Physical Device Only (default):
npm run nix # or yarn nix - For Emulator Development (explicitly enable):
npm run nix-emulator # or yarn nix-emulator
If you do not have
npm/yarninstalled, execute the commands manually:- For Physical Device Only (default):
nix develop --extra-experimental-features nix-command --extra-experimental-features flakes
- For Emulator Development (explicitly enable):
nix develop .#emulator --extra-experimental-features nix-command --extra-experimental-features flakes
The first time, this will download and set up all required tools, which can take considerable time. Subsequent entries will be much faster. You will also see a message about "Setting up writable Android SDK..." which only happens once.
- For Physical Device Only (default):
Once inside the nix develop shell, all tools are available.
Open a new terminal or run in the background:
npm start- Connect Device: Enable USB debugging on your Android device and connect it via USB.
- Verify Device:
adb devices
- Mirror Screen (Optional):
scrcpy # Mirrors screen, provides control scrcpy -s <device_serial> # If multiple devices connected
- Run App:
npx run android
-
Launch Emulator:
emulator -avd ReactNative_API35 -gpu host -no-metrics -no-audio
- Use
-gpu swiftshader_indirectif hardware acceleration (-gpu host) fails.
- Use
-
Verify Emulator:
adb devices
-
Run App: Launches the the emulater automatically, if it is not already running.
npx run android