ekala-project/corepkgs / .agents/skills/rust
rust
VerifiedPackage a Rust crate for corepkgs. Use when writing or editing a buildRustPackage derivation — covers cargoHash, cargoBuildFlags, checkFlags, shell completions, and cross-compilation.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 2.8 KB |
SKILL.md
View on GitHub---
name: rust
description: Package a Rust crate for corepkgs. Use when writing or editing a buildRustPackage derivation — covers cargoHash, cargoBuildFlags, checkFlags, shell completions, and cross-compilation.
---
# Rust Packages
Rust packages live in `pkgs/<name>/default.nix` using `rustPlatform.buildRustPackage`.
## Minimal Example
```nix
{
lib,
rustPlatform,
fetchFromGitHub,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "example";
version = "1.0.0";
src = fetchFromGitHub {
owner = "example";
repo = "example";
tag = "v${finalAttrs.version}";
hash = "sha256-...";
};
cargoHash = "sha256-...";
meta = {
description = "Example Rust tool";
license = lib.licenses.mit;
mainProgram = "example";
};
})
```
## Essential Attributes
- `cargoHash` — SRI hash of vendored Cargo dependencies. Set to `lib.fakeHash` to get the correct value from the build error.
- `cargoBuildFlags` — extra flags passed to `cargo build` (e.g., `[ "--package" "foo" "--bin" "foo" ]` for workspaces)
- `cargoTestFlags` — extra flags passed to `cargo test`
- `checkFlags` — flags appended to the test command. Use `--skip` to disable specific tests:
```nix
checkFlags = [
"--skip=tests::network_test"
"--skip=tests::flaky_timing"
];
```
## Auto-Generated Tests
`buildRustPackage` automatically provides `passthru.tests.build` — a variant that re-runs with `doCheck = true`. User-supplied `passthru.tests` entries merge alongside it.
## Native Dependencies
Rust crates that link C libraries need explicit inputs:
```nix
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl zlib ];
```
## Shell Completions
```nix
nativeBuildInputs = [ installShellFiles ];
postInstall = ''
installShellCompletion --cmd example \
--bash <($out/bin/example completions bash) \
--fish <($out/bin/example completions fish) \
--zsh <($out/bin/example completions zsh)
'';
```
Guard with build platform check when cross-compiling:
```nix
postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ''
installShellCompletion ...
'';
```
## Complete Example
```nix
{
lib,
rustPlatform,
fetchFromGitHub,
pkg-config,
erlang,
git,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "gleam";
version = "1.18.1";
src = fetchFromGitHub {
owner = "gleam-lang";
repo = "gleam";
tag = "v${finalAttrs.version}";
hash = "sha256-...";
};
cargoHash = "sha256-...";
nativeBuildInputs = [ pkg-config erlang ];
nativeCheckInputs = [ git ];
checkFlags = [
"--skip=tests::all_files_have_copyright_notice"
"--skip=tests::echo::"
];
meta = {
description = "Statically typed language for the Erlang VM";
homepage = "https://gleam.run/";
license = lib.licenses.asl20;
mainProgram = "gleam";
};
})
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |