build(nix): package diffcore-web as its own derivation - #12
Open
jakob1379 wants to merge 1 commit into
Open
Conversation
`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`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nix buildnever produceddiffcore-web. Its bin target declaresrequired-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:
desktopandwebare mutually exclusive cargo features, enforced atcrates/diffcore-tauri/src/lib.rs:1:commands.rsswapstauri::Stateforcrate::state_shim::Stateunder#[cfg(not(feature = "desktop"))]. Since cargo features unify across a workspace build, one derivation physically cannot produce all three binaries — the existing comment indefault.nixsays exactly this.Approach
default.nixgains awebMode ? falseparameter rather than duplicating the sharedsrc/cargoLock/npmDeps/ npm-build machinery. WithwebMode = falsethe derivation is unchanged.Differences in web mode:
-p diffcore-tauri, so--no-default-featuresdoes not strip defaults from the rest of the workspace.cargoTestFlagsset to match.buildRustPackage's check phase does not inheritcargoBuildFlags, so it would otherwise runcargo testacross the workspace with default features, pullingdesktopback in without gtk present.atk,cairo,gdk-pixbuf,glib,gtk3,libsoup_3,pango,webkitgtk_4_1, pluswrapGAppsHook3andcopyDesktopItems. The web server is a plain axum binary.web.rsresolves the UI from../share/diffcore/uirelative to the binary.Exposed as
packages.diffcore-webandapps.web, sonix run .#webjoins.#cliand.#desktop.Verification
nix build .#diffcore-webexits 0 and produces:bin/diffcore-webonlyshare/diffcore/ui/index.htmlpresentldd bin/diffcore-webreports zero gtk or webkit libraries — the dependency split is real, not just declarednix build(default, desktop + CLI) is unchanged and still green.