From a40b4f51905af2c73e2e7f9068952bcb618b88c9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 10 Feb 2026 00:46:43 +0100 Subject: [PATCH] Add combined rustdoc package with cross-crate linking NCI's doc-merge doesn't support rustdoc's sharded search index format (Rust 1.78+), so we build all workspace crates together in a single cargo doc invocation. This enables cross-crate linking and produces a custom index page with rustdoc-matching theme support. --- dev/flake-module.nix | 113 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/dev/flake-module.nix b/dev/flake-module.nix index 384a2d8..449a560 100644 --- a/dev/flake-module.nix +++ b/dev/flake-module.nix @@ -56,6 +56,119 @@ ''}"; }; + # Combined rustdoc for all crates with cross-linking. + # NOTE: nci.outputs.nix-bindings.docs uses doc-merge which doesn't support + # rustdoc's new sharded search index format (Rust 1.78+). + # See https://github.com/90-008/nix-cargo-integration/issues/198 + # Instead, we build all workspace crates together so rustdoc can link them. + packages.docs = + let + # Use nix-bindings-flake (has most transitive deps) as base + base = config.nci.outputs.nix-bindings-flake.packages.release; + crates = [ + "nix-bindings-bdwgc-sys" + "nix-bindings-util-sys" + "nix-bindings-util" + "nix-bindings-store-sys" + "nix-bindings-store" + "nix-bindings-expr-sys" + "nix-bindings-expr" + "nix-bindings-fetchers-sys" + "nix-bindings-fetchers" + "nix-bindings-flake-sys" + "nix-bindings-flake" + ]; + packageFlags = pkgs.lib.concatMapStringsSep " " (c: "-p ${c}") crates; + in + (base.extendModules { + modules = [ + { + mkDerivation = { + # Build docs for all crates together (enabling cross-crate linking) + buildPhase = pkgs.lib.mkForce '' + cargo doc $cargoBuildFlags --no-deps --profile $cargoBuildProfile ${packageFlags} + ''; + checkPhase = pkgs.lib.mkForce ":"; + installPhase = pkgs.lib.mkForce '' + mv target/$CARGO_BUILD_TARGET/doc $out + + # Find rustdoc assets (have hashes in filenames) + find_asset() { + local pattern="$1" + local matches=($out/static.files/$pattern) + if [[ ''${#matches[@]} -ne 1 || ! -e "''${matches[0]}" ]]; then + echo "Expected exactly one match for $pattern, found: ''${matches[*]}" >&2 + exit 1 + fi + basename "''${matches[0]}" + } + rustdoc_css=$(find_asset 'rustdoc-*.css') + normalize_css=$(find_asset 'normalize-*.css') + storage_js=$(find_asset 'storage-*.js') + + cat > $out/index.html < + + + + nix-bindings-rust + + + + + + +

nix-bindings-rust

+

Rust bindings for the Nix C API

+

Crates

+ +
+

Low-level bindings

+

+ These -sys crates provide raw FFI bindings generated by + bindgen. + They expose the C API directly without safety wrappers. + Most users should prefer the high-level crates above. +

+ +
+ + + EOF + ''; + }; + } + ]; + }).config.public; + devShells.default = pkgs.mkShell { name = "nix-bindings-devshell"; strictDeps = true;