feat(builder): nix.rust block for Rust external build dependencies#127
Merged
Conversation
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>
📊 Doc-test reportsThe 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 Pages can take a minute to update after the run finishes. |
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.
What & why
The builder-driven Rust path (
codegen.rust, #125) compiles a module's crate with abuildRustPackagecall (lib/mkLogosModule.nix, therustStaticLibbinding) that passed onlysrc/sourceRoot/cargoLock/doCheck— nonativeBuildInputs/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*-sysdependency needs a system build tool/library —pkg-config+openssl(reqwestnative-tls),libsqlite3-sys(rusqlite), libclang (bindgen), protoc (prost) — failed in the nix sandbox. The only workaround was hand-rolling abuildRustPackagein the module's own flake, discarding the trivial-flake benefit of the builder path.Change
A new
nix.rustmetadata block, mirroringnix.packages:packages.build→buildRustPackage.nativeBuildInputs(host tools: pkg-config, protoc,rustPlatform.bindgenHook)packages.runtime→buildRustPackage.buildInputs(link libs: openssl, sqlite, zstd)env→buildRustPackage.envNames resolve via the existing dotted-path
getPkg. Empty by default → existing modules are unaffected. Also adds escape-hatch argsrustExtraNativeBuildInputs/rustExtraBuildInputs/rustEnvtomkLogosModulefor deps that can't be named by a nixpkgs attr path (arbitrary derivation / store-path env).Files
lib/parseMetadata.nix— parsenix.rust→nix_rust(safe defaults)lib/mkLogosModule.nix— resolve viagetPkg+ inject intorustStaticLib; new flake argsdocs/configuration.md— document the block (reqwest-native-tls + bindgen examples)tests/test-parse-metadata.nix— unit assertions fornix_rusttests/fixtures/rust-native-dep/+tests/test-rust-native-dep.nix— flake checkchecks.<sys>.rust-native-depVerification
checks.<sys>.default— 256 pure-eval tests pass (incl. newnix_rustassertions).checks.<sys>.rust-native-dep— a Rust cdylib module whosebuild.rsprobes zlib via pkg-config builds withnix.rustand 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.rustpath still drives cargo normally — no regression for existing Rust modules.🤖 Generated with Claude Code