Skip to content

build(nix): package diffcore-web as its own derivation - #12

Open
jakob1379 wants to merge 1 commit into
jamesaphoenix:mainfrom
jakob1379:t3code/package-web
Open

build(nix): package diffcore-web as its own derivation#12
jakob1379 wants to merge 1 commit into
jamesaphoenix:mainfrom
jakob1379:t3code/package-web

Conversation

@jakob1379

Copy link
Copy Markdown
Contributor

nix build never produced diffcore-web. Its bin target declares required-features = ["web"], and cargo skips targets whose required features are unmet without erroring — so the binary was silently absent rather than failing.

It cannot simply be added to the existing derivation: desktop and web are mutually exclusive cargo features, enforced at crates/diffcore-tauri/src/lib.rs:1:

#[cfg(all(feature = "desktop", feature = "web"))]
compile_error!("features `desktop` and `web` are mutually exclusive: the web dispatcher constructs the shim State, tauri commands need the real one");

commands.rs swaps tauri::State for crate::state_shim::State under #[cfg(not(feature = "desktop"))]. Since cargo features unify across a workspace build, one derivation physically cannot produce all three binaries — the existing comment in default.nix says exactly this.

Approach

default.nix gains a webMode ? false parameter rather than duplicating the shared src / cargoLock / npmDeps / npm-build machinery. With webMode = false the derivation is unchanged.

Differences in web mode:

  • Build flags scoped with -p diffcore-tauri, so --no-default-features does not strip defaults from the rest of the workspace.
  • cargoTestFlags set to match. buildRustPackage's check phase does not inherit cargoBuildFlags, so it would otherwise run cargo test across the workspace with default features, pulling desktop back in without gtk present.
  • Drops the GUI stackatk, cairo, gdk-pixbuf, glib, gtk3, libsoup_3, pango, webkitgtk_4_1, plus wrapGAppsHook3 and copyDesktopItems. The web server is a plain axum binary.
  • Keeps the npm build, because web.rs resolves the UI from ../share/diffcore/ui relative to the binary.
  • No desktop item or icons.

Exposed as packages.diffcore-web and apps.web, so nix run .#web joins .#cli and .#desktop.

Verification

nix build .#diffcore-web exits 0 and produces:

  • bin/diffcore-web only
  • share/diffcore/ui/index.html present
  • ldd bin/diffcore-web reports zero gtk or webkit libraries — the dependency split is real, not just declared

nix build (default, desktop + CLI) is unchanged and still green.

`desktop` and `web` are mutually exclusive cargo features (lib.rs enforces it
with compile_error!), and features unify across a workspace build, so a single
derivation cannot produce all three binaries. diffcore-web was silently absent
from `nix build` because its bin target declares required-features = ["web"],
which cargo skips without erroring.

Parameterize default.nix with `webMode` rather than duplicating the shared
src/cargoLock/npm machinery. The web server is a plain axum binary, so it drops
the gtk/webkit stack, wrapGAppsHook3 and copyDesktopItems; it keeps the npm
build because web.rs resolves the UI from ../share/diffcore/ui.

--no-default-features is scoped with `-p diffcore-tauri` so it does not strip
defaults from the rest of the workspace. cargoTestFlags has to be set to match:
buildRustPackage's check phase does not inherit cargoBuildFlags, so it would
otherwise test the workspace with default features and pull `desktop` back in
without gtk present.

Exposed as packages.diffcore-web and apps.web (`nix run .#web`).
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