Skip to content

About

Build, sign and install iOS apps on NixOS without a Mac (packages omarchy-apple-dev)

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

69 Commits

Folders and files

Repository files navigation

nix-apple-dev

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.

What Nix builds, what stays in $HOME

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.

Install

Choose one of these ways. The NixOS and home-manager modules can be used together.

home-manager module (per user, includes the SDK links)

# 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

NixOS module

# 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 cable

Do not set inputs.nixpkgs.follows. The tools are built and tested with this flake's nixos-unstable.

Commands only (any Linux with Nix)

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).

Set up the SDK (one time per host)

  1. 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).
  2. Add it to the Nix store, then delete the download: nix-store --add-fixed sha256 ~/Downloads/Xcode_27.xip
  3. apple-dev-setup This 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 list shows darwin.

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.

Sign and install

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.hello

With a free Apple ID: run xtool auth, then xtool dev run in the project directory.

React Native, Expo and One apps (CocoaPods)

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 T builds one target and its dependencies, --list prints the build order. Logs of failed compiles are in ios/build/xcbuild/failed/, the last failed command in last-failure.log.
  • Debug builds are incremental, as in Xcode; other configurations (Release) redo every step unless --incremental is given, and --clean makes any build redo every step. Each target keeps a record of its steps in xcbuild-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 in incremental mode (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.rb and cached in the build directory. A project is read again when its project.pbxproj has another mtime, size or inode than when it was read (older counts too: a file restored from a backup), when the content of dump-project.rb changed, or when the Ruby that runs it resolves to another path. --clean keeps that cache; rm -rf ios/build/xcbuild drops it.
  • What an incremental build doesn't notice: changes to the tools other than xcbuild.py and dump-project.rb (xcode_version.py, the stand-ins in bin/); 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 -p or rsync -t from 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. --clean covers 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 npx come 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; plutil comes with the Swift toolchain. Signing happens afterwards with sign-dev.sh.
  • Hermes: a pod's macOS hermesc is replaced by a link to the npm hermes-compiler Linux build of the same version (the macOS binary is kept as hermesc.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's install-toolchain.sh, win over the Nix packages.

Debug builds and the dev server

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) with ipconfig 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 include ifconfig, so that works only if the host has one on PATH; otherwise ip.txt is empty and the app looks for the dev server on localhost.
  • A host name other than localhost may need to be allowed by the dev server (Vite: server.allowedHosts). Plain http:// 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 used when DEBUG is defined, which makes clang instantiate all of them; TypeMetadataTrait<swift::Optional<T>> then recurses without bound, past any template depth limit. pkgs/swift.nix and pkgs/ios-sdk.nix change both copies of the header to mark them used only if SWIFT_CXX_INTEROP_USED_THUNKS is 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 with DEBUG defined. The test needs the SDK: nix build .#ios-sdk.tests.debug-cxx-interop.

Notes

  • apple-dev with 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 from PATH, and install-toolchain.sh is replaced: Nix builds everything it installs.
  • The toolchain links nixpkgs libraries. Two differ from Ubuntu: libedit.so.2 is nixpkgs' libedit.so.0 (same ABI), and lldb needs narrow ncurses with versioned symbols, which pkgs/swift.nix builds.
  • Upstream edits a writable toolchain for SwiftBuild. Here that edit is patches/swift-strings-encoding-defaults.patch.
  • patches/xtool-offline-sdk-build.patch lets xtool sdk build run 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 run scripts/swiftpm-lock.py .build/workspace-state.json > pkgs/locks/NAME.json.
  • actool builds against m9tdev/AssetKit at b8971f0, upstream's omarchy/mac-icon merged with upstream main. 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 Composer automatic-gradient fills (upstream #6). The 09875cc that 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-lease simulator package (with private simslim support) 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.

License

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.

About

Build, sign and install iOS apps on NixOS without a Mac (packages omarchy-apple-dev)

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages