youwee icon indicating copy to clipboard operation
youwee copied to clipboard

feat(build): add Nix devshell, FHS binary patching, Linux .deb packaging

Open usrbinkat opened this issue 7 months ago • 0 comments

Supersedes #45. Depends on #59.

Rebased on current develop, all pre-commit checks passing (biome, tsc, cargo check). Corrections from #45:

  • beforeBundleCommand moved from tauri.conf.json to tauri.linux.conf.json so Windows and macOS builds are unaffected
  • externalBin: [] retained on Linux to eliminate /usr/bin/yt-dlp file conflict with the system yt-dlp package (dpkg refuses to install both)
  • ffmpeg and yt-dlp declared as Recommends instead of Depends — .deb installs successfully without them present, uses them automatically when available via PATH-first resolution from #59

Verified: .deb builds, installs over existing v0.12.0 package without conflicts, and launches on Pop!_OS 24.04 with system yt-dlp (PPA 2026.03.17) and ffmpeg resolved via PATH.


Problem

Building Youwee inside a Nix devshell produces binaries with a Nix store dynamic linker (/nix/store/.../ld-linux-x86-64.so.2) and Nix store RPATH entries baked into the ELF binary. When this binary is packaged into a .deb and installed on a standard Ubuntu/Debian system, it crashes at launch because the Nix linker cannot find system libraries like libayatana-appindicator3.so.1.

The existing .deb bundles yt-dlp at /usr/bin/yt-dlp via externalBin, which conflicts with the yt-dlp apt package — dpkg refuses to install both.

There is no Nix flake or devshell configuration, so Linux contributors using Nix must manually discover and install all Tauri 2 system dependencies (GTK3, WebKitGTK 4.1, OpenSSL, libayatana-appindicator, pkg-config, etc.).

Solution

FHS binary portability (scripts/patch-fhs-binary.sh)

Called by tauri.linux.conf.json beforeBundleCommand after cargo build but before .deb/.rpm/.AppImage assembly:

  • Patches ELF interpreter from Nix store to standard FHS path (/lib64/ld-linux-x86-64.so.2)
  • Removes RPATH so the binary uses the system library search path
  • Multi-arch support: x86_64, aarch64, armv7l, i686 (via TAURI_ENV_ARCH)
  • Derives binary path dynamically from TAURI_ENV_TARGET_TRIPLE and TAURI_ENV_DEBUG
  • No-op when patchelf is not on PATH (macOS, Windows, CI without Nix)
  • Idempotent: skips if interpreter already points to FHS path
  • Fails loudly (exits non-zero, aborts tauri build) if patchelf is available but patching fails

Linux .deb packaging (tauri.linux.conf.json)

Defense in depth — three layers of binary resolution, each catching the one above failing:

  1. System PATH — user or fleet has deployed managed binaries (Nix, Homebrew, PPA, Ansible, etc.). Highest-trust source. PATH-first resolution from #59 makes this work automatically.
  2. App-managed download — user installed via Settings > Dependencies, or the app auto-downloaded Stable channel on first launch. Lives in app_data_dir/bin/.
  3. Bundled sidecar — ships inside the .dmg/.msi on macOS/Windows. On Linux, externalBin: [] removes the bundled sidecar to eliminate the /usr/bin/yt-dlp file conflict with the system package. Layers 1 and 2 provide coverage.

Implementation:

  • externalBin: [] on Linux — removes bundled yt-dlp from .deb, eliminating dpkg file conflict with the yt-dlp apt package
  • Recommends (not Depends) for ffmpeg and yt-dlp — apt installs them by default when available, succeeds even when they are not
  • No configuration required at any layer. Fleet operators who push system packages get theirs preferred. Home users get the app-managed auto-download on first launch.

Nix devshell (flake.nix, flake.lock, .envrc)

  • flake.nix consumes github:braincraftio/konductor frontend devshell via inputsFrom, providing Rust toolchain, Bun, Node.js, pkg-config, and all Tauri 2 system library dependencies (GTK3, WebKitGTK 4.1, OpenSSL, libayatana-appindicator, etc.)
  • Adds runtime packages on PATH: yt-dlp (video extraction), ffmpeg (post-processing), deno (yt-dlp YouTube JS extraction via --js-runtimes), glib-networking (GnuTLS backend for GIO — required by WebKitGTK for HTTPS)
  • Sets GIO_EXTRA_MODULES to ${pkgs.glib-networking}/lib/gio/modules:${pkgs.dconf.lib}/lib/gio/modules for WebKitGTK TLS support — without this, HTTPS image loads fail with "TLS support is not available"
  • flake.lock pinned to konductor rev 84a1bcd (includes pkgs.bun)
  • .envrc sources $HOME/.cargo/env for Rust toolchain and provides commented-out use flake for opt-in direnv integration

README updates

  • Documents optional system dependencies for Linux .deb users with PPA instructions
  • Documents nix develop → bun install → bun run tauri dev workflow
  • Updates Tauri prerequisites link from deprecated v1 to current v2
  • Tech stack clarifies yt-dlp is bundled on macOS/Windows, system packages optional on Linux

Test plan

  • [ ] nix develop enters devshell with bun, cargo, rustc, all Tauri deps
  • [ ] bun run tauri dev launches development build with working thumbnails and TLS
  • [ ] bun run tauri build -b deb produces .deb with FHS-patched binary
  • [ ] beforeBundleCommand output confirms interpreter patched from Nix store to /lib64/ld-linux-x86-64.so.2
  • [ ] .deb does not contain bundled yt-dlp binary (no /usr/bin/yt-dlp file conflict)
  • [ ] .deb declares Recommends: ffmpeg, yt-dlp (not Depends)
  • [ ] sudo apt install ./Youwee.deb succeeds without ffmpeg or yt-dlp pre-installed
  • [ ] sudo apt install ./Youwee.deb succeeds when system yt-dlp already installed via PPA
  • [ ] Installed app launches and uses app-managed yt-dlp download when system binary absent
  • [ ] Installed app prefers system yt-dlp/ffmpeg when present via PATH
  • [ ] macOS and Windows builds unaffected (beforeBundleCommand only in Linux platform config, tauri.conf.json unchanged)
  • [ ] Non-Nix Linux builds unaffected (patch script no-ops when patchelf absent)

usrbinkat avatar Apr 26 '26 19:04 usrbinkat