Skip to content

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

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

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

Conversation

@parasew

@parasew parasew commented Nov 22, 2026

Copy link
Copy Markdown

Summary

A Nix flake and a Makefile for building Stack Wallet locally: for testers, for anyone who wants to reproduce a build, and for people who want their own. 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).

This is a slimmer replacement for my draft #1482. It does not touch the release pipeline: build.yaml, the Dockerfile and the CI image are unchanged, and a build from this branch is not a release (see "Which build is for what" in docs/building/make.md).

What it adds

  • Flake (flake.nix, flake.lock, .envrc): Flutter, Go, rustup, sccache, CMake, Meson, Ninja, pkg-config, protoc and the Linux/macOS build dependencies, for Apple Silicon macOS and Linux. The pinned versions (two Rust toolchains, and the Xcode that dnix source builds need) are written down once, at the top of flake.nix, and exported to the Makefile. On Linux the shell drops mkShell's -rpath $out/lib, which would otherwise put the checkout path into every binary.
  • Make targets: build-macos, build-ios, build-linux, build-windows, build-android; bootstrap (enter the shell); check-reqs*, check-sdk-macos, diagnose-env-macos; clean, clean-app, clean-native; sccache-setup, cache-stats.
    • Without an active Nix shell make stops and says what to run; Windows (Git Bash) is the one exception and always uses the prebuilts.
    • VERSION and BUILD_NUM are required, BUILD_NUM may not be below the latest build_* tag, and both reach the shell through the environment instead of being interpolated into recipe text.
  • Requirements on macOS: bootstrap-nix (macOS and Linux; asks before running the downloaded installer as root), bootstrap-macos (adds a full Xcode), bootstrap-xcode, and the opt-in bootstrap-xcode-download (archive.org, SHA-1 and Apple signature checked; refuses to run in CI; aborts on a hash mismatch before extracting anything). check-sdk-macos demands the pinned Xcode for source builds and says how to install it.
  • bm/: plain-text cache benchmarks. bench.sh (cold/warm, --clean app|native|full, --sccache on|off, hit/miss counters), matrix.sh (six standard scenarios) and report.sh.
  • CI: a small make-check job in test.yaml (dry-runs, the Nix requirement and source-mode policy with the reason for each rejection, and a real run of require-version).
  • Docs: docs/building/make.md, linked from docs/building.md.

Changes to existing scripts

  • build_app.sh: EOF on the confirmation prompt aborts instead of looping; declining exits with $BUILD_APP_DECLINE_EXIT (default 0, unchanged; the Makefile sets 1 so make stops).
  • configure_campfire.sh, android and ios platform_config.sh: sed -i.bak, which works with BSD sed and the GNU sed the Nix shell puts first on PATH.
  • Linux: build_secure_storage_deps.sh writes a pkg-config file for the locally built libsecret (the tracked scripts/linux/pc/libsecret-1.pc hardcoded /usr/local and is removed), and build_secp256k1.sh provides the library coinlib's CMake install step expects without overwriting an existing one.

Verification

From fresh clones of the branch:

  • Apple Silicon Mac, nix develop: make build-macos from source (all four dnix packages built with Xcode 27.0, Stack Wallet.app 320 MB), make build-ios from source, and make build-macos PREBUILTS=1.
  • NixOS x86_64: make build-linux clean, rebuild (the bundled libsecp256k1.so has the same sha256 after the rebuild) and PREBUILTS=1; the executable-stack validation passes.
  • Hosted runners on my fork: Ubuntu 24.04 with Nix installed by make bootstrap-nix (prebuilts, and from source), macOS and iOS with Nix (prebuilts), and Windows (Git Bash, no Nix). These ran with a temporary fork-only workflow, so they are not part of this PR's CI.
  • Without a Nix shell the build targets refuse, on macOS, Linux and Ubuntu.
  • The make-check job was mutation-tested locally: 11 changes to the Makefile's policy each make it fail.

Limits

  • Android was not built again at this head; build-android is covered by dry-runs and the policy checks only.
  • Windows ran on a hosted runner, not on a Windows machine.
  • A Linux bundle built in the Nix shell has /nix/store as its ELF interpreter and in its RUNPATH: it runs where it was built, it is not for distribution. Distributable Linux builds stay on the CI image path.
  • The Nix shell provides Flutter 3.47.4, upstream CI uses 3.47.2 (nixpkgs never packaged 3.47.2).

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