Skip to content

build: Nix flake and make targets for reproducible local builds - #1545

Open
parasew wants to merge 3 commits into
cypherstack:stagingfrom
parasew:feat/make-nix-core
Open

parasew wants to merge 3 commits into
cypherstack:stagingfrom
parasew:feat/make-nix-core

Conversation

@parasew

@parasew parasew commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

One Nix flake and a Makefile for local builds of Stack Wallet: for testers, for reproducing a build and for building your own. Every make build needs Nix (Windows is the exception; Android also needs a JDK and the Android SDK). The four dnix packages are compiled from source (PREBUILTS=0, the default on Apple Silicon and Linux) or taken as verified prebuilts (PREBUILTS=1).

The release pipeline is untouched (build.yaml, Dockerfile, CI image), and a local build is not a release. This replaces my larger draft #1482.

Details: docs/building/make.md.

What it adds

  • flake.nix (+ lock, .envrc): the toolchain for Apple Silicon macOS and Linux. The two Rust versions and the Xcode version for dnix source builds are set once at its top.
  • Make targets: build-macos|ios|linux|windows|android; bootstrap-nix, bootstrap-macos, bootstrap-xcode, bootstrap-xcode-download (opt-in, SHA-1 and Apple signature checked); requirement checks; clean*; sccache-setup, cache-stats. Without a Nix shell make stops and says what to run. VERSION and BUILD_NUM are required and validated.
  • bm/: plain-text cache benchmarks (cold, warm, app or native clean, with and without sccache).
  • CI: a small make-check job in test.yaml.

Changes to existing files

  • build_app.sh: end of input at the confirmation prompt aborts instead of looping; the exit code on "no" can be set (default unchanged).
  • configure_campfire.sh, Android and iOS platform_config.sh: sed -i.bak, which works with BSD and GNU sed.
  • android/settings.gradle: Gradle 9 rejects Flutter's integration_test project inside the read-only Nix SDK, so such plugins are built from a copy under build/. No effect with a writable SDK.
  • Linux: build_secure_storage_deps.sh writes the pkg-config file for the local libsecret (the tracked one hardcoded /usr/local); build_secp256k1.sh provides the library coinlib's install step expects.
  • docs/building.md links the new page.

Linux and NixOS

  • Linux builds are x86_64 only; make says why on ARM.
  • The Nix Flutter engine does not search the bundle's lib folder (empty window), so build-linux adds $ORIGIN to its RUNPATH.
  • A Nix-built bundle is for the machine that built it. Outside NixOS it needs Mesa from Nix to start (command in make.md).
  • On NixOS, Google's Android SDK programs need an FHS environment; build-android uses the flake's android-fhs.

Verification

Hosted-runner checks used temporary fork-only workflows. Some checks ran on earlier states of this branch. Later changes to the Linux build are the constant compiler seed (below); with it, both Linux modes were built again on NixOS and Ubuntu, and the pushed commit was built from source on NixOS and starts.

Builds

App Host dnix modes
macOS, iOS Apple Silicon Mac (also Campfire and Stack Duo with prebuilts) source (Xcode 27.0), prebuilts
Linux NixOS; Ubuntu 24.04 runners source, prebuilts
Linux bare Ubuntu 24.04 container without systemd prebuilts
Android (3 APKs) NixOS with an unmodified Google SDK; Ubuntu 24.04 runner source, prebuilts
Android (3 APKs) Apple Silicon Mac prebuilts
Windows Windows 11 VM, Git Bash prebuilts

Reproducibility (two clean builds from fresh clones; same commit, version, paths, home directory and pub cache)

App The two builds ran on Identical files
Linux, both modes same NixOS machine; also two Ubuntu runners 244/244
Linux, both modes NixOS and an Ubuntu runner (different Nix versions) 244/244
macOS, both modes same Mac 363/363
macOS, prebuilts two hosted Macs 362/363
iOS, both modes same Mac 389–390/392
Android, prebuilts same Mac; same NixOS machine (same key) all APK contents; only the signing block differs
Windows, prebuilts same VM 224/243 (the rest differ in 4–30 bytes each)

To get the Linux result across machines, the Linux shell now sets a constant -frandom-seed: the default one comes from the shell's own store path and ended up in the libraries.

Running apps (new wallets without funds)

  • Linux app on NixOS: Monero, Wownero, Xelis, Epic, MimbleWimbleCoin and Litecoin synchronized; Firo showed a Spark address, Litecoin an MWEB address; FROST created a group config; Tor connected; a Salvium wallet was created.
  • Android release APK in an Android 16 emulator: Monero synchronized; a Salvium wallet was created; new Wownero, Xelis, Epic and MimbleWimbleCoin wallets showed their recovery phrases; Tor connected.
  • Linux on Ubuntu (virtual display, software rendering): starts with Mesa from the flake's nixpkgs.
  • macOS: Stack Wallet, Stack Duo and Campfire open their window (under test bundle ids). iOS simulator: a Campfire debug build starts.
  • Windows: the app starts and loads the three coin DLLs, which are byte-identical to the published ones.

Other

  • NixOS: flutter test 1205 passed, 8 skipped; the Linux bundle tests and the build-script tests pass.
  • bootstrap-nix and bootstrap-macos installed Nix on a fresh hosted Mac. bootstrap-xcode-download ran download, SHA-1, Apple signature check and extraction for real; its selection and licence steps ran with stubs.
  • bm/ on NixOS: rebuilding the native libraries took 642 s without sccache and 559 s with a filled cache.
  • The Makefile was tested with injection attempts, the release-number guard, missing Nix and clean*; make-check fails on deliberately broken Makefiles.

A Nix flake is the toolchain and a Makefile wraps scripts/build_app.sh and
`flutter build`. Every build needs Nix: the four dnix packages are either
compiled from source (PREBUILTS=0, the default on Apple Silicon and Linux) or
taken as verified prebuilts (PREBUILTS=1). Windows (Git Bash) has no Nix and
always uses the prebuilts.

Flake
- flake.nix, flake.lock and .envrc (`use flake`) provide Flutter, Go, rustup,
  sccache, CMake, Meson, Ninja, pkg-config, protoc and the Linux/macOS build
  dependencies for Apple Silicon macOS and Linux.
- On Linux the shell drops mkShell's `-rpath $out/lib` from NIX_LDFLAGS, which
  would otherwise put the checkout path into every binary's RUNPATH.
- The versions are written down once, at the top of flake.nix: the two Rust
  toolchains (installed by the shell on first entry) and the Xcode that dnix
  source builds need. The shell exports them as STACK_*_VERSION for the Makefile.

Makefile
- build-macos, build-ios, build-linux, build-windows, build-android.
- Without an active Nix shell make stops and says what to run; there is no
  escape hatch except Windows.
- VERSION and BUILD_NUM are required; BUILD_NUM may not be below the latest
  build_* tag. Both reach the shell through the environment, never by
  interpolation into the recipe text.
- bootstrap-nix installs Nix on macOS and on Linux (multi-user with systemd,
  else single-user; asks before running the downloaded installer as root) and
  enables the nix-command and flakes features.
- Requirements on macOS: bootstrap-macos (bootstrap-nix plus a full Xcode),
  bootstrap-xcode, the opt-in bootstrap-xcode-download (archive.org,
  SHA-1 and Apple signature checked, refuses CI, aborts on a mismatch before it
  extracts anything), check-reqs*, check-sdk-macos (also requires the pinned
  Xcode for source builds) and diagnose-env-macos.
- clean, clean-app, clean-native, sccache-setup and cache-stats.
- CONFIRM=1 answers the wallet-data prompt of build_app.sh; the Makefile also
  sets BUILD_APP_DECLINE_EXIT=1 so declining stops make.

Scripts
- build_app.sh: EOF on the confirmation prompt aborts instead of looping;
  declining exits with $BUILD_APP_DECLINE_EXIT (default 0, as before).
- configure_campfire.sh, android and ios platform_config.sh: `sed -i.bak` works
  with BSD sed and the GNU sed the Nix shell puts first on PATH.
- linux: build_secure_storage_deps.sh generates a pkg-config file for the
  locally built libsecret (the tracked one hardcoded /usr/local) and
  build_secp256k1.sh provides the library coinlib's CMake install step expects,
  without overwriting an existing one.

Benchmarks (bm/, plain text)
- bench.sh: cold/warm, --clean app|native|full, --sccache on|off (the cargo
  config is restored afterwards, also after a crash), sccache hit/miss counters;
  matrix.sh runs six standard scenarios; report.sh prints the table.

CI: a make-check job validates the Makefile (dry-runs, the Nix requirement and
the source-mode policy with the reason for each rejection, and a real run of
require-version). Docs: docs/building/make.md, including how Linux is built and why a Nix-built bundle
is for the machine that built it, not for distribution.
- Linux: add $ORIGIN to the RUNPATH of the Nix Flutter engine; without it the
  app window stays empty
- Linux: build-linux is x86_64 only and says why on ARM
- Linux shell: use a constant -frandom-seed, so that builds on different
  machines can produce identical bundles
- Android: build Flutter plugins from the read-only Nix SDK from a copy; on
  NixOS run the APK build inside the flake's android-fhs environment
- require-version rejects multi-line VERSION and BUILD_NUM values
- sccache-setup writes the cargo config that Flutter's build hooks read
- Xcode download: no sudo for a new writable target directory
- install_nix.sh enables flakes for single-user installs
- docs: shorter make.md with measured reproducibility and platform notes
- make-check covers the new rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant