Build iOS apps on NixOS, and install them on an iPhone. You do not need a Mac.
This flake packages the Linux iOS toolchain from
omarchy-apple-dev
for Nix: Swift 6.4, xtool, the iOS SDK from Xcode.xip, and pymobiledevice3.
For a Mac that runs iOS Simulators, the flake also packages sim-lease for
aarch64-darwin: a fixed pool of reusable simulators with host-wide leases and
an active-simulator cap. Its private simslim dependency reduces memory use
without exposing the upstream fleet-management CLI. See
Shared simulator leases.
| Part | Where it comes from |
|---|---|
| Swift 6.4 toolchain | swift.org Ubuntu 24.04 build, pinned by hash, patched for Nix (autoPatchelfHook, a host sysroot, clang config files) |
| xtool, OpenAppleMacrosServer, actool | built by Nix from source with nixpkgs' Swift (ordinary Nix binaries); SwiftPM dependencies pinned in pkgs/locks/ |
| pymobiledevice3 11.27, cryptography | built by Nix from python/uv.lock (uv2nix) |
| rcodesign | nixpkgs |
| ipsw 3.1.736 | built from source (newer than nixpkgs, whose version cannot sign in to Apple any more) |
| xtool's Linux linker toolset | release tarball, pinned by hash (xtool would download it) |
| upstream scripts | pinned revision, patched to call the tools above from PATH (patches/) |
iOS SDK (ios-sdk) |
built by Nix from your own Xcode_27.xip (a requireFile: Nix cannot download it). Only the SDK (1.2 GB) is kept; Xcode.app is never stored. |
Everything is in the Nix store. $HOME only has links to the SDK for SwiftPM.
The SDK is unfree (Apple's files): never push it to a public binary cache.
Choose one of these ways. The NixOS and home-manager modules can be used together.
# home-manager imports
nix-apple-dev.homeManagerModules.default
programs.apple-dev.enable = true;
programs.apple-dev.sdk.enable = true; # first: nix-store --add-fixed sha256 Xcode_27.xip# flake.nix
inputs.nix-apple-dev.url = "github:m9tdev/nix-apple-dev";
# in the host's modules list
nix-apple-dev.nixosModules.default
# host config
programs.apple-dev.enable = true;
programs.apple-dev.usb.enable = true; # usbmuxd, if an iPhone connects to this host with a cableDo not set inputs.nixpkgs.follows. The tools are built and tested with
this flake's nixos-unstable.
nix run github:m9tdev/nix-apple-dev # shell (or: nix run … -- CMD ARGS)
nix run github:m9tdev/nix-apple-dev#setup # SDK setup in $HOME (see below)
sudo nix run github:m9tdev/nix-apple-dev#usbmuxd # USB service; run again after each reboot#usbmuxd needs root because usbmuxd claims the iPhone's USB device. With
systemd, it starts the transient unit apple-dev-usbmuxd. Without systemd, it
runs in the foreground.
apple-dev is a small FHS environment (bubblewrap, so it needs unprivileged
user namespaces). It exists only because SwiftBuild runs some tools by fixed
path (/usr/bin/touch is compiled in; /bin/cp, /usr/bin/sed are in its
specs). The toolchain and the tools are ordinary Nix binaries. Nix builds do
not use bubblewrap.
Plain Swift code for Linux also builds outside apple-dev:
SDKROOT=$(nix build --print-out-paths github:m9tdev/nix-apple-dev#swift)/sysroot swiftc ….
SwiftPM packages with C targets need apple-dev (C files do not get SDKROOT).
- Get Xcode 27.0 (its Swift matches 6.4). Download it in a browser
(https://developer.apple.com/download/all/?q=Xcode), or run
nix run github:m9tdev/nix-apple-dev#ipsw -- download dev --more --output ~/Downloads(Apple ID + 2FA). - Add it to the Nix store, then delete the download:
nix-store --add-fixed sha256 ~/Downloads/Xcode_27.xip apple-dev-setupThis builds the SDK (about 2 minutes; xtool unpacks the xip to about 10 GB of temporary space) and registers it. At the end,swift sdk listshowsdarwin.
Another host does not need the xip: copy the built SDK there
(nix copy --to ssh://HOST $(nix build --print-out-paths github:m9tdev/nix-apple-dev#ios-sdk)),
then run apple-dev-setup on that host.
After nix-collect-garbage the xip can be gone; the SDK stays (setup makes it a
GC root). To build the SDK again (for example after an update of this flake),
add the xip to the store again.
With a paid account, an App Store Connect API key signs the app. You do not
need xtool auth.
# ~/.appstoreconnect/env (mode 600): ASC_KEY_ID, ASC_ISSUER_ID, ASC_KEY_PATH
apple-dev
set -a; . ~/.appstoreconnect/env; set +a
xtool new Hello && cd Hello && xtool dev build
provision-dev.py --bundle-id com.example.hello --udid <UDID>
sign-dev.sh xtool/Hello.app Hello-dev.ipa
pymobiledevice3 developer dvt pkill --bundle com.example.hello # a running copy blocks the reinstall
pymobiledevice3 apps install Hello-dev.ipa
pymobiledevice3 developer dvt launch com.example.helloWith a free Apple ID: run xtool auth, then xtool dev run in the project directory.
SwiftPM can't build React Native's native modules: many mix Swift with
ObjC++/C++ in one target. Here CocoaPods makes the usual Xcode workspace, and
apple-dev-xcbuild builds it the way xcodebuild would. It resolves build
settings from the projects and xcconfigs, writes Xcode's header maps,
compiles Swift (with C++ interop for Nitro modules) and C/ObjC/C++, runs the
pods' script phases, links with the SDK's lld, and bundles the app: Info.plist,
actool, ibtool, the JS bundle as Hermes bytecode, and the embedded frameworks.
apple-dev # the commands below run in here
cd my-app && npx one prebuild --platform ios --no-install # or: npx expo prebuild -p ios
(cd ios && apple-dev-pod install) # CocoaPods, with Linux stand-ins for xcrun & co.
apple-dev-xcbuild --workspace-dir ios --bundle-id com.example.app # Release, device
app=ios/build/xcbuild/Build/Products/Release-iphoneos/*.app
provision-dev.py --bundle-id com.example.app --udid <UDID>
sign-dev.sh $app app.ipa && pymobiledevice3 apps install app.ipa--target Tbuilds one target and its dependencies,--listprints the build order. Logs of failed compiles are inios/build/xcbuild/failed/, the last failed command inlast-failure.log.- Debug builds are incremental, as in Xcode; other configurations (Release)
redo every step unless
--incrementalis given, and--cleanmakes any build redo every step. Each target keeps a record of its steps inxcbuild-steps.json. An object, a target's Swift module, an archive, the link, or a script phase that declares its inputs and outputs (and isn't marked to run every build) is redone only when its command line, an input's content (headers from clang's depfiles, Swift's dependency files, the linker's dependency info) or the toolchain and SDK changed, or when an output is missing or not the file the step wrote. A Swift target inincrementalmode (SWIFT_COMPILATION_MODE) recompiles only the files the change affects. One build at a time uses a build directory; a second one waits. The lock is a file in that directory, so removing the directory during a build lets another build start beside it.rm -rf ios/build/xcbuild(with no build running) also gives a clean build. - The projects are read with
dump-project.rband cached in the build directory. A project is read again when itsproject.pbxprojhas another mtime, size or inode than when it was read (older counts too: a file restored from a backup), when the content ofdump-project.rbchanged, or when the Ruby that runs it resolves to another path.--cleankeeps that cache;rm -rf ios/build/xcbuilddrops it. - What an incremental build doesn't notice: changes to the tools other than
xcbuild.pyanddump-project.rb(xcode_version.py, the stand-ins inbin/); environment variables that the compilers or script phases read (CPATH, ...; build settings do count); a new header that shadows one found later in the search path; an SDK or a toolchain changed in place under the same path; a file replaced by one with the same size and the same mtime (cp -porrsync -tfrom a copy with an identical timestamp), since only a different mtime or size makes it hash the file; and a file edited during a build on a network file system (NFS, SMB) whose server clock runs more than about 20 ms behind this machine's, since the server sets the mtime.--cleancovers these. A header added to any target changes the all-headers header map that every target reads, so every target recompiles. - Release (the default) or
--configuration Debug, arm64 device only. In Release the JS bundle is built by the project's own bundle script phase, so the phone needs no dev server. - Pods as static libraries only: no
use_frameworks!. Framework targets, app extensions and Copy Files phases aren't supported; the build stops with an error naming them instead of leaving them out. - Node.js and
npxcome from the host: apple-dev doesn't include them. - macOS tools that pods and React Native call (
xcrun,xcodebuild -version,otool,lipo,ditto,codesign,ipconfig) have small Linux stand-ins;plutilcomes with the Swift toolchain. Signing happens afterwards withsign-dev.sh. - Hermes: a pod's macOS
hermescis replaced by a link to the npmhermes-compilerLinux build of the same version (the macOS binary is kept ashermesc.macos). Every build checks the versions again and redoes the link if it is missing or points elsewhere (a moved project). - If the Linux ibtool can't compile a launch storyboard, the app gets a plain
UILaunchScreen, and an icon set without images gives no icon, as in Xcode. - Old copies in
~/.local/bin(xtool, ipsw) or~/pymobile3-venv, from an earlier run of upstream'sinstall-toolchain.sh, win over the Nix packages.
A Debug build loads its JS from the project's dev server, so a JS change needs no native rebuild:
APPLE_DEV_DEV_SERVER_HOST=my-machine.example.net \
apple-dev-xcbuild --workspace-dir ios --bundle-id com.example.app --configuration Debug
npx one dev --host 0.0.0.0 --port 8081 # or: npx expo start / npx react-native start- React Native writes the dev server's host into the app (
ip.txt) withipconfig getifaddr en0. The stand-in prints$APPLE_DEV_DEV_SERVER_HOST, or else this machine's address on its default route. Set it when the phone reaches the machine by another name, such as a VPN host name. It must be a host name or an IPv4 address, without a scheme or port. - If the stand-in finds no address (no variable, no default route), React
Native falls back to
ifconfig. apple-dev doesn't includeifconfig, so that works only if the host has one onPATH; otherwiseip.txtis empty and the app looks for the dev server onlocalhost. - A host name other than
localhostmay need to be allowed by the dev server (Vite:server.allowedHosts). Plainhttp://to a host name needs an App Transport Security exception in the app's Info.plist. - Swift's C++ interop header marks its inline thunks
usedwhenDEBUGis defined, which makes clang instantiate all of them;TypeMetadataTrait<swift::Optional<T>>then recurses without bound, past any template depth limit.pkgs/swift.nixandpkgs/ios-sdk.nixchange both copies of the header to mark themusedonly ifSWIFT_CXX_INTEROP_USED_THUNKSis defined. The attribute only keeps the thunks visible to LLDB. This happens only with the Linux toolchain: Xcode 27.1 on macOS compiles the same header withDEBUGdefined. The test needs the SDK:nix build .#ios-sdk.tests.debug-cxx-interop.
apple-devwith no arguments opens a shell.apple-dev CMD ...runs one command. The Swift-built tools (xtool, the toolchain) run only inside it.- Patches are in
patches/. Upstream's scripts call the tools fromPATH, andinstall-toolchain.shis replaced: Nix builds everything it installs. - The toolchain links nixpkgs libraries. Two differ from Ubuntu:
libedit.so.2is nixpkgs'libedit.so.0(same ABI), and lldb needs narrow ncurses with versioned symbols, whichpkgs/swift.nixbuilds. - Upstream edits a writable toolchain for SwiftBuild. Here that edit is
patches/swift-strings-encoding-defaults.patch. patches/xtool-offline-sdk-build.patchletsxtool sdk buildrun offline (the toolset and the macro server come from Nix). Xcode.xip stores many files in Apple's compressed form (decmpfs), so the SDK must be unpacked by xtool, not by cpio.- Two Swift versions: apps need Swift 6.4 (it matches the Xcode 27 SDK), the swift.org build. The tools are built with nixpkgs' Swift 6.2.4.
- Update a SwiftPM lock: resolve the package inside
apple-dev, then runscripts/swiftpm-lock.py .build/workspace-state.json > pkgs/locks/NAME.json. actoolbuilds against m9tdev/AssetKit at b8971f0, upstream'somarchy/mac-iconmerged with upstreammain. It has the macOS Icon Composer layout (without it macOS shows the generic app icon for an.icon), the exact bitmap bytes-per-row (upstream #4: 29pt iOS app icons no longer render sheared) and Icon Composerautomatic-gradientfills (upstream #6). The09875ccthat omarchy-apple-dev pins lacks the macOS layout; back to upstream's pin once it moves to one that has it.- The Linux iOS toolchain is x86_64-linux only. The independent
sim-leasesimulator package (with privatesimslimsupport) is aarch64-darwin only; see Shared simulator leases. - Apple's Xcode licence allows its use only on Apple-branded computers. You decide if that matters for your use.
MIT, see LICENSE. Parts are derived from omarchy-apple-dev, xtool and nixpkgs (all MIT); NOTICE lists them. Xcode and the SDK built from it are Apple's.