stahl/flake.nix
Markus Zoppelt fbec70e621 feat(ios): run Stahl in the iOS simulator
A spike for #69. ios/rust is a staticlib that hosts the app's own State, spec
and views on a Rune LayerHost, drawing onto the CAMetalLayer of a small UIKit
shell (ios/Shell). The shell drives it from a display link and forwards touches
and software-keyboard text. It opens the demo workspace, seeded into the app's
Documents on first launch, on fixture quotes.

`nix develop .#ios -c ios/build-sim.sh --run` builds Stahl.app with Xcode's
swiftc and clang, without an Xcode project, and installs and launches it on a
simulator. Since simctl can't tap, the shell plays taps, drags and typing from
STAHL_IOS_SCRIPT, for checking the app by hand or by an agent. The flake's
ios shell is the pinned toolchain with the iOS targets. The crate is its own
Cargo workspace, so the desktop build and its lockfile don't see it.

Not yet: a phone layout, a document picker, safe-area insets from Rune,
autosave on backgrounding, or a device build.
2026-11-07 14:23:41 +01:00

179 lines
5.4 KiB
Nix

{
description = "Stahl Capital — native desktop app for portfolio_rs, built on Rune, runs on macOS, Linux, and NixOS";
nixConfig = {
extra-substituters = [
"https://nix-community.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
# Rune needs a newer compiler than nixpkgs ships. rust-toolchain.toml
# is the single pin, shared with rustup and the release workflow.
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
isLinux = pkgs.stdenv.isLinux;
# Rune links xkbcommon and wayland. winit and wgpu dlopen the rest at
# runtime, so linking alone does not find them.
linuxRuntimeLibs = with pkgs; [
libxkbcommon
vulkan-loader
wayland
libx11
libxcursor
libxi
libxrandr
libxcb
];
commonArgs = {
# The app embeds its fonts and its mark.
src = pkgs.lib.cleanSourceWith {
src = ./.;
name = "source";
filter = path: type:
(craneLib.filterCargoSources path type)
|| (pkgs.lib.hasInfix "/assets/" path
&& (type == "directory" || builtins.match ".*\\.(ttf|png)" path != null));
};
strictDeps = true;
nativeBuildInputs = with pkgs;
[
pkg-config
# aws-lc-sys, behind the TLS stack, builds C with it.
cmake
]
++ pkgs.lib.optionals isLinux [
makeWrapper
];
buildInputs =
pkgs.lib.optionals isLinux linuxRuntimeLibs
# stdenv's default apple-sdk provides the frameworks on macOS.
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
libiconv
]);
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
stahl = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# Tests run in the `stahl-test` check.
doCheck = false;
postFixup = pkgs.lib.optionalString isLinux ''
wrapProgram $out/bin/stahl \
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath linuxRuntimeLibs}
'';
meta = with pkgs.lib; {
description = "Stahl Capital — native desktop app for portfolio_rs";
homepage = "https://github.com/MarkusZoppelt/stahl";
license = licenses.mit;
mainProgram = "stahl";
maintainers = [maintainers.MarkusZoppelt];
platforms = platforms.linux ++ platforms.darwin;
};
}
);
in {
packages = {
default = stahl;
stahl = stahl;
};
apps.default = flake-utils.lib.mkApp {
drv = stahl;
};
devShells =
{
default = craneLib.devShell {
inputsFrom = [stahl];
packages = with pkgs; [
cargo-watch
alejandra
];
LD_LIBRARY_PATH = pkgs.lib.optionalString isLinux (pkgs.lib.makeLibraryPath linuxRuntimeLibs);
};
}
// pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin {
# The iOS app (ios/build-sim.sh): the pinned toolchain with the iOS targets. Nix's
# clang only knows macOS, so iOS code compiles and links with Xcode's.
ios = pkgs.mkShellNoCC {
packages = [
(rustToolchain.override {
targets = ["aarch64-apple-ios" "aarch64-apple-ios-sim"];
})
pkgs.cmake
];
CC_aarch64_apple_ios = "/usr/bin/clang";
CC_aarch64_apple_ios_sim = "/usr/bin/clang";
CARGO_TARGET_AARCH64_APPLE_IOS_LINKER = "/usr/bin/clang";
CARGO_TARGET_AARCH64_APPLE_IOS_SIM_LINKER = "/usr/bin/clang";
};
};
checks = {
inherit stahl;
stahl-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
stahl-fmt = craneLib.cargoFmt commonArgs;
# Includes tests/e2e.rs: Rune's headless runtime needs no display or GPU.
stahl-test = craneLib.cargoTest (
commonArgs
// {
inherit cargoArtifacts;
}
);
};
formatter = pkgs.alejandra;
}
)
// {
overlays.default = final: prev: {
stahl = self.packages.${final.system}.stahl;
};
};
}