cargo2nix

Generate Cargo.nix files for per-crate Rust derivations in Nix Flakes workflows.

21|Updated Jan 5, 2024
One-click install
npx skills add https://github.com/olafkfreund/nixos_config --skill cargo2nix
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cargo2nix
Source: https://github.com/olafkfreund/nixos_config/tree/main/.gemini/skills/cargo2nix
Command: npx skills add https://github.com/olafkfreund/nixos_config --skill cargo2nix

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

cargo2nix helps Rust projects achieve reproducible builds by generating Cargo.nix files that describe per-crate derivations, enabling fine-grained caching and flexible toolchain control.

Core Features & Use Cases

  • Per-crate derivations for selective rebuilding and sharing dependencies across projects.
  • Workspace and multi-binary support with cross-compilation and development shells.
  • Easy integration with Flakes and cargo workflows to keep Cargo.nix in sync with Cargo.lock.

Quick Start

  • Generate Cargo.nix for your project with: nix run github:cargo2nix/cargo2nix
  • Update after changing Cargo.lock: cargo update; nix run github:cargo2nix/cargo2nix; git add Cargo.lock Cargo.nix

Frequently Asked Questions about cargo2nix

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate per-crate Nix derivations for a Rust project?▼

Generate per-crate Nix derivations by running cargo2nix to produce a Cargo.nix file, enabling fine-grained caching and deterministic builds for your Rust workspace.

What is the best way to keep Cargo.nix in sync with Cargo.lock in Flakes workflows?▼

Keep Cargo.nix in sync with Cargo.lock by running cargo update, executing cargo2nix, then git adding both Cargo.lock and Cargo.nix to persist updated derivation definitions.

Does cargo2nix support cross-compilation and multi-binary Rust projects?▼

Yes, cargo2nix supports cross-compilation and multi-binary projects, generating derivations across workspace crates with cross-target builds and development shells within Flakes-based workflows.

Do I need a Nix environment to use cargo2nix for Rust packaging?▼

Yes, you need a Nix-based environment and cargo2nix tooling to produce deterministic derivations, as the workflow relies on Flakes integration for reproducible Rust project packaging.

Why use per-crate derivations instead of building an entire Rust workspace at once?▼

Per-crate derivations enable selective rebuilding and allow sharing dependencies across projects, providing fine-grained caching and flexible toolchain control for reproducible Rust builds.

When should I avoid using cargo2nix for Rust builds?▼

Avoid cargo2nix if your project does not use Nix or Flakes, as generating Cargo.nix for per-crate derivations requires a Nix-based environment to produce deterministic outputs.