Skip to content

feat(builder): nix.rust block for Rust external build dependencies#127

Merged
dlipicar merged 1 commit into
masterfrom
feat/rust-external-build-deps
Jun 16, 2026
Merged

feat(builder): nix.rust block for Rust external build dependencies#127
dlipicar merged 1 commit into
masterfrom
feat/rust-external-build-deps

Conversation

@dlipicar

Copy link
Copy Markdown
Contributor

What & why

The builder-driven Rust path (codegen.rust, #125) compiles a module's crate with a buildRustPackage call (lib/mkLogosModule.nix, the rustStaticLib binding) that passed only src/sourceRoot/cargoLock/doCheck — no nativeBuildInputs/buildInputs/env, and no metadata knob to add them (nix.packages.* is routed only to the C++ plugin link). So any Rust module whose crate or a transitive *-sys dependency needs a system build tool/library — pkg-config+openssl (reqwest native-tls), libsqlite3-sys (rusqlite), libclang (bindgen), protoc (prost) — failed in the nix sandbox. The only workaround was hand-rolling a buildRustPackage in the module's own flake, discarding the trivial-flake benefit of the builder path.

Change

A new nix.rust metadata block, mirroring nix.packages:

"nix": { "rust": {
  "packages": { "build": ["pkg-config"], "runtime": ["openssl"] },
  "env": { "OPENSSL_NO_VENDOR": "1" }
} }
  • packages.buildbuildRustPackage.nativeBuildInputs (host tools: pkg-config, protoc, rustPlatform.bindgenHook)
  • packages.runtimebuildRustPackage.buildInputs (link libs: openssl, sqlite, zstd)
  • envbuildRustPackage.env

Names resolve via the existing dotted-path getPkg. Empty by default → existing modules are unaffected. Also adds escape-hatch args rustExtraNativeBuildInputs / rustExtraBuildInputs / rustEnv to mkLogosModule for deps that can't be named by a nixpkgs attr path (arbitrary derivation / store-path env).

Files

  • lib/parseMetadata.nix — parse nix.rustnix_rust (safe defaults)
  • lib/mkLogosModule.nix — resolve via getPkg + inject into rustStaticLib; new flake args
  • docs/configuration.md — document the block (reqwest-native-tls + bindgen examples)
  • tests/test-parse-metadata.nix — unit assertions for nix_rust
  • tests/fixtures/rust-native-dep/ + tests/test-rust-native-dep.nix — flake check checks.<sys>.rust-native-dep

Verification

  • checks.<sys>.default — 256 pure-eval tests pass (incl. new nix_rust assertions).
  • checks.<sys>.rust-native-dep — a Rust cdylib module whose build.rs probes zlib via pkg-config builds with nix.rust and fails without it (negative run confirmed: The pkg-config command could not be found). This proves the block is what makes native deps reach the crate compile, and that the empty-nix.rust path still drives cargo normally — no regression for existing Rust modules.

🤖 Generated with Claude Code

Rust cdylib modules (codegen.rust) compile their crate via buildRustPackage in
mkLogosModule's `rustStaticLib`, which received no nativeBuildInputs/buildInputs/
env and offered no metadata knob to add them — so any crate (or transitive *-sys
dep) needing a system build tool/library (pkg-config + openssl for reqwest
native-tls, libsqlite3-sys, libclang for bindgen, protoc) failed in the nix
sandbox. The only workaround was hand-rolling a buildRustPackage in the module's
own flake, discarding the trivial-flake benefit.

Add a `nix.rust` metadata block that feeds the crate compile:
  nix.rust.packages.build   -> nativeBuildInputs (host tools)
  nix.rust.packages.runtime -> buildInputs       (link libs)
  nix.rust.env              -> buildRustPackage env

Names resolve via the existing dotted-path getPkg. Empty by default, so existing
modules are unaffected. Also adds programmatic escape-hatch args
rustExtraNativeBuildInputs / rustExtraBuildInputs / rustEnv to mkLogosModule.

Verified by a new fixture + flake check (checks.<sys>.rust-native-dep): a Rust
module whose build.rs probes zlib via pkg-config builds only with the nix.rust
block, and fails without it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

📊 Doc-test reports

The four ways to wrap a C library plus the two cross-language composition tours — each scaffolded into real modules, built against this commit, loaded in logoscore, and driven — rendered alongside the commands actually run and their output (updated each run, commit 187633d):

Pages can take a minute to update after the run finishes.

@dlipicar dlipicar merged commit f7452d9 into master Jun 16, 2026
4 checks passed
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