Skip to content

Instantly share code, notes, and snippets.

@shift
Created February 8, 2026 17:07
Show Gist options
  • Select an option

  • Save shift/3f8feb1b5f67dddf5cfbfe2d76d54de8 to your computer and use it in GitHub Desktop.

Select an option

Save shift/3f8feb1b5f67dddf5cfbfe2d76d54de8 to your computer and use it in GitHub Desktop.
{
description = "Rust Agentic Environment (Nightly + Diagnostics Tracking)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# REQUIRED: The overlay to get the Nightly compiler
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
# Apply the overlay to nixpkgs
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# ---------------------------------------------------------------------
# NIGHTLY TOOLCHAIN
# We need this specific version to access -Z flags.
# We include 'rust-src' for rust-analyzer support.
# ---------------------------------------------------------------------
rustToolchain = pkgs.rust-bin.nightly.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
};
# ---------------------------------------------------------------------
# 1. AGENT-CHECK (The Diagnostic Tracker)
# ---------------------------------------------------------------------
# -Z track-diagnostics: Debugs where the error was created.
# --message-format short: Keeps it readable for the Agent.
agentCheck = pkgs.writeShellScriptBin "agent-check" ''
echo "πŸ¦€ [Check] Verifying Syntax (Nightly Diagnostics)..."
${rustToolchain}/bin/cargo check \
-Z track-diagnostics \
--message-format short \
--color never \
--quiet
'';
# ---------------------------------------------------------------------
# 2. AGENT-LINT (Nightly Clippy)
# ---------------------------------------------------------------------
agentLint = pkgs.writeShellScriptBin "agent-lint" ''
echo "🧹 [Lint] Running Nightly Clippy..."
${rustToolchain}/bin/cargo clippy \
--message-format short \
--color never \
-- \
-D warnings \
-D clippy::unwrap_used \
-D unsafe_code
'';
# ---------------------------------------------------------------------
# 3. AGENT-AUDIT (Security)
# ---------------------------------------------------------------------
agentAudit = pkgs.writeShellScriptBin "agent-audit" ''
echo "πŸ”’ [Audit] Scanning dependencies..."
${pkgs.cargo-audit}/bin/cargo-audit --color never
'';
# ---------------------------------------------------------------------
# AGENT CONTEXT
# ---------------------------------------------------------------------
agentContext = ''
# Rust Agent Protocol (Nightly Edition)
## πŸŒ™ NIGHTLY TOOLCHAIN ACTIVE
You are using the **Nightly** compiler.
- Syntax check uses \`-Z track-diagnostics\`.
- If the compiler outputs internal path traces, focus on the "created at" location to understand the *root cause* of the error.
## 🚨 STRICT GUARDRAILS
1. **NO \`Cargo.toml\` EDITS:** Use \`cargo add\`.
2. **NO UNWRAPS:** Panics are banned.
3. **NO UNSAFE:** Unsafe code is banned.
## πŸ›  COMMANDS
| Command | Purpose | Output Style |
| :--- | :--- | :--- |
| \`agent-check\` | **Deep Diagnostic Check.** | \`file:line:col: error\` + Diagnostic Trace |
| \`agent-lint\` | **Security/Perf Check.** | Short format. |
| \`agent-audit\` | **CVE Scan.** | Database output. |
'';
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
rustToolchain # The Nightly Compiler
pkgs.cargo-audit
pkgs.pkg-config
pkgs.openssl
# Agent Scripts
agentCheck
agentLint
agentAudit
];
shellHook = ''
echo "πŸŒ™ Initializing Rust Nightly Environment..."
echo " (Enabled: -Z track-diagnostics)"
echo "${agentContext}" > AGENT_CONTEXT.md
# Configure sparse registry for speed
mkdir -p .cargo
echo '[registry]' > .cargo/config.toml
echo 'default = "sparse"' >> .cargo/config.toml
if [ ! -f Cargo.toml ]; then
cargo init --quiet
cargo add tokio --features full --quiet
cargo add anyhow --quiet
fi
'';
};
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment