hex/nix/package.nix
Dax 687ea32d65
Bump Rune to 1899e64: overlays pace frames with the swap chain on Windows (#1832)
* Bump Rune to 1899e64: overlays pace frames with the swap chain on Windows

Windows HUD memory grew and the app could hang after dictation because the
overlay presented frames without waiting for swap chain room after Rune #844;
Rune #985 makes an overlay's frames wait for room in its swap chain, as a
window's do.

nix: vendor each Cargo source in its own directory. Rune's tiny-skia-path is a
path dependency inside Rune (a Git crate at 0.11.4 here), the same name and
version as resvg's from crates.io, and cargo's directory source keys a crate by
name and version alone.

Goldens: Rune's text drawing changed over the 152 commits since d6715352.

* Review: patch accesskit_macos, and make the nix vendor split name what breaks

Rune #975 put accesskit_macos in its [patch.crates-io], so Hex patches it too
(Rune's README asks consumers to); it is the fifth and last crate Rune patches.

The vendor script override now checks each fragment it rewrites and names the
missing one, its comment says crates.io goes to registry/ and Git sources to
git/, nixfmt formats the file, and check-nix-git-pins.py's docstring says the
hashes reach importCargoLock through the cargoDeps override.

* linux: keep Hex running when the window can't start

Rune r399 makes App::run print a startup error and exit 1 on native targets
instead of panicking, so a Linux Hex with no display died, the next launch
became a fresh instance, and Check Linux's single-instance exercise saw
`hex start` hang and `hex app --hidden` reset.

run_app now returns Rune's try_run error and run_window reports it and waits,
as it did for the panic (#979).

* macos, windows: take rune's startup error instead of exiting

Rune r399 prints a startup error and exits the process from `run` on
native targets, which skipped Hex's own stop: macOS's drain (workers,
event-log flush, a recording kept for the next launch) and Windows' GPU
draw-marker disarm, so the launch that failed before drawing was read as
a crash while drawing. Both apps take `try_run`'s error now, log it, and
stop the way Quit does; Windows also reports it from `hex app`. The
Linux window already took the error (#979).

* macos: a launch whose window never started exits 1

Taking Rune's try_run error lets the app stop through the drain, but
process_exit::finish ends with _exit(0), so a failed GUI launch reported
success. finish_with takes the code; the window's failure exits 1 while a
normal quit keeps 0.

* docs: overlays wait for swap-chain room on windows since rune #985

Rune #985 makes every overlay's frames wait for room in its swap chain, so
the notes that said only a window waits and that the HUD's 60 Hz timer worked
around a suspected cause were stale. The timer is a cap on top of the slot
wait now. The macOS and Windows startup-error comments cited #979, which is
the Linux window issue; they describe Rune r399 instead.

* windows: a failed start keeps the GPU draw marker

disarm() means a frame reached the screen or Hex quit cleanly; a start that
never drew is neither, so it keeps the marker and the next launch falls back to
the high-performance GPU.

* docs: say what was measured about overlay pacing

* docs: say what stays bounded on windows, not what shrinks

The meetings map and the dictation map described the fix as memory that no
longer grows, and as Rune holding a frame's slot and skipping it. Rune #985
defers the frame until its swap chain has room, then draws it, which bounds
the frames in flight; the growth itself hasn't been re-measured on Windows
with the fix.
2026-11-14 20:40:20 -05:00

264 lines
7.5 KiB
Nix

{
lib,
rustPlatform,
pkg-config,
cmake,
python3,
shaderc,
vulkan-headers,
vulkan-loader,
spirv-headers,
openblas,
alsa-lib,
alsa-plugins,
pipewire,
libva,
ffmpeg-headless,
openssl,
libxkbcommon,
wayland,
fontconfig,
freetype,
curl,
util-linux,
wl-clipboard,
wtype,
makeWrapper,
autoAddDriverRunpath,
symlinkJoin,
libx11,
libxcb,
libxcursor,
libxrandr,
libxi,
mkShell,
rust-analyzer,
rustfmt,
clippy,
}:
let
buildEnv = {
OPENSSL_NO_VENDOR = "1";
BLA_VENDOR = "OpenBLAS";
};
runtimeEnv = {
LD_LIBRARY_PATH = lib.makeLibraryPath [
vulkan-loader
openblas
alsa-lib
wayland
libxkbcommon
fontconfig
# Linux Annotate dlopens libpipewire-0.3, libva and libva-drm. libva finds VA-API
# drivers through its built-in /run/opengl-driver path or LIBVA_DRIVERS_PATH.
pipewire
libva
];
ALSA_PLUGIN_DIR = symlinkJoin {
name = "hex-alsa-plugins";
paths = [
"${pipewire}/lib/alsa-lib"
"${alsa-plugins}/lib/alsa-lib"
];
};
};
runtimePackages = [
curl
wl-clipboard
wtype
# Annotate runs ffmpeg and ffprobe; the headless build includes libx264.
ffmpeg-headless
];
# Every Git dependency Cargo.lock pins, with the revision its output hash was
# computed from. scripts/check-nix-git-pins.py fails a pull request that bumps
# one without the other, before Nix reports a hash mismatch.
cargoGitDependencies = {
"transcribe-rs-0.3.11" = {
rev = "e37c66b6df43af51fde8dec34f98a07aaf09564c";
hash = "sha256-MJJiug3LfbKsuHcL2+LJk95+j5kk/MWzb5ihdBlHLmE=";
};
"rune-0.0.1" = {
rev = "1899e648a3a09bcca8a59b44deb9957302a73f04";
hash = "sha256-6B+veHICwhZTWdwNwA48xSXZPfNHbh+DmRr03w6dPC0=";
};
"transcribe-cpp-sys-0.4.1" = {
rev = "bcb639faa4c74a2300ba19e30360cb2355b1663a";
hash = "sha256-1VztJ0VhPTjAuk4J0NT9KapDOqplegpHOqHsTpfHXWc=";
};
};
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "hex";
version = (builtins.fromTOML (builtins.readFile ../Cargo.toml)).package.version;
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
../Cargo.toml
../Cargo.lock
../.cargo
../build.rs
../crates
../src
../tests
../native
../resources
../assets
../packaging
# The Labs registry's published copy: a Rust test compares it to the registry.
../site/src/labs.json
../macos/HexMicrophoneDriver/Info.plist
# Built in: a 2.3.1 install moves itself into this installer's layout.
../.github/release/install-linux.sh
];
};
# nixpkgs' vendor directory keeps every crate in one place, keyed by name and
# version, so it cannot hold two copies from different sources. Rune's
# `vendor/tiny-skia-path` is a path dependency inside Rune (a Git crate here)
# at 0.11.4, the same name and version as resvg's from crates.io, so this
# vendors crates.io's crates in `registry/` and every Git source's crates in
# `git/`, and points each source at its own directory: Cargo tells them apart
# by source. The script is importCargoLock's, rewritten; each fragment below
# must still be in it (the guard says which is gone), so a nixpkgs change
# fails loudly here instead of vendoring something wrong.
cargoDeps =
(rustPlatform.importCargoLock {
lockFile = ../Cargo.lock;
outputHashes = builtins.mapAttrs (_: dependency: dependency.hash) cargoGitDependencies;
}).overrideAttrs
(old: {
buildCommand =
let
# importCargoLock's script, and what this override turns it into.
fragments = [
{
what = "the single vendored-sources config";
from = ''
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "cargo-vendor-dir"'';
to = ''
[source.crates-io]
replace-with = "registry-vendor-dir"
[source.registry-vendor-dir]
directory = "cargo-vendor-dir/registry"
[source.git-vendor-dir]
directory = "cargo-vendor-dir/git"'';
}
{
what = "the one-directory crate link";
from = ''ln -s "$crate" $out/$(basename "$crate" | cut -c 34-)'';
to = ''
dest=$(basename "$crate" | cut -c 34-)
if [ -e "$crate/.cargo-config" ]; then
mkdir -p $out/git
ln -s "$crate" $out/git/$dest
else
mkdir -p $out/registry
ln -s "$crate" $out/registry/$dest
fi'';
}
{
what = "the Git source config append";
from = ''cat "$crate/.cargo-config" >> $out/.cargo/config.toml'';
to = ''sed 's/replace-with = "vendored-sources"/replace-with = "git-vendor-dir"/' "$crate/.cargo-config" >> $out/.cargo/config.toml'';
}
];
missing = builtins.filter (fragment: !(lib.hasInfix fragment.from old.buildCommand)) fragments;
in
if missing != [ ] then
throw (
"nix/package.nix: importCargoLock's vendor script changed; re-apply the split into "
+ "a registry and a Git vendor directory. Missing: "
+ lib.concatMapStringsSep ", " (fragment: fragment.what) missing
)
else
lib.replaceStrings (map (fragment: fragment.from) fragments) (map (
fragment: fragment.to
) fragments) old.buildCommand;
});
nativeBuildInputs = [
pkg-config
cmake
python3
shaderc
makeWrapper
autoAddDriverRunpath
];
buildInputs = [
vulkan-headers
vulkan-loader
spirv-headers
openblas
alsa-lib
openssl
libxkbcommon
wayland
fontconfig
freetype
libx11
libxcb
libxcursor
libxrandr
libxi
];
# OpenCode HTTP requests run through curl, including in the tests; the
# 2.3.1 adoption test runs the Linux installer, which needs flock.
nativeCheckInputs = [
curl
util-linux
];
dontUseCmakeConfigure = true;
env = buildEnv;
# Desktop and installed-model tests are #[ignore]; run the remaining suite.
doCheck = true;
preCheck = ''
export HOME="$TMPDIR/hex-test-home"
mkdir -p "$HOME"
'';
postInstall = ''
install -Dm644 ${../packaging/anomaly.hex.desktop} $out/share/applications/anomaly.hex.desktop
mkdir -p $out/share/icons
cp -R ${../packaging/linux/icons/hicolor} $out/share/icons/hicolor
substituteInPlace $out/share/applications/anomaly.hex.desktop \
--replace-fail '@HEX_BIN@' "$out/bin/hex"
'';
postFixup = ''
wrapProgram $out/bin/hex \
--prefix PATH : ${lib.makeBinPath runtimePackages} \
--prefix LD_LIBRARY_PATH : ${runtimeEnv.LD_LIBRARY_PATH} \
--set ALSA_PLUGIN_DIR ${runtimeEnv.ALSA_PLUGIN_DIR}
'';
passthru.devShell = mkShell {
inputsFrom = [ finalAttrs.finalPackage ];
env = buildEnv // runtimeEnv;
packages = runtimePackages ++ [
rust-analyzer
rustfmt
clippy
];
};
meta = {
description = "Local-first voice dictation (Linux beta)";
homepage = "https://anoma.ly/hex/";
license = lib.licenses.mit;
mainProgram = "hex";
platforms = [
"x86_64-linux"
"aarch64-linux"
];
};
})