Bazel rules for Rocq/Coq theorem proving with hermetic toolchain support via Nix.
Nix is required for the Rocq toolchain. The toolchain uses nixpkgs to provide hermetic Coq installations across all platforms.
# Install Nix (multi-user installation, recommended)
sh <(curl -L https://nixos.org/nix/install)
# Restart your terminal, or source the nix profile:
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
# Verify installation
nix --version# Install Nix (multi-user installation)
sh <(curl -L https://nixos.org/nix/install) --daemon
# Restart your terminal or start a new shell
# Verify installation
nix --version# In WSL2 Ubuntu/Debian:
sh <(curl -L https://nixos.org/nix/install) --no-daemon
# Verify installation
nix --version# Test that Coq can be fetched from nixpkgs
nix-shell -p coq --run "coqc --version"- Hermetic Toolchains: Coq toolchain provided via nixpkgs for reproducible builds
- Cross-Platform: Linux (x86_64, aarch64), macOS (x86_64, aarch64)
- Multiple Coq Versions: 8.20, 8.19, 8.18, 8.17, 8.16
- Bazel 8 bzlmod: Modern module system support
- Rocq Platform Integration: Provides equivalent tools to Rocq Platform
- coq-of-rust Support: Planned integration for Rust-to-Coq translation
- Reproducible: Pinned nixpkgs commit for deterministic builds
bazel_dep(name = "rules_rocq_rust", version = "0.1.0")
# Override to fetch from GitHub (not yet in BCR)
git_override(
module_name = "rules_rocq_rust",
remote = "https://github.com/pulseengine/rules_rocq_rust.git",
commit = "<latest-commit>",
)
# Configure Rocq toolchain
rocq = use_extension("@rules_rocq_rust//rocq:extensions.bzl", "rocq")
rocq.toolchain(
version = "8.20", # Coq version
strategy = "nix", # Hermetic nix-based installation
)
use_repo(rocq, "rocq_toolchains")
register_toolchains("@rocq_toolchains//:all")(* proofs/example.v *)
Theorem plus_comm : forall n m : nat, n + m = m + n.
Proof.
intros n m.
induction n as [| n' IHn'].
- simpl. rewrite Nat.add_0_r. reflexivity.
- simpl. rewrite IHn'. rewrite Nat.add_succ_r. reflexivity.
Qed.load("@rules_rocq_rust//rocq:defs.bzl", "rocq_library", "rocq_proof_test")
rocq_library(
name = "example_proofs",
srcs = ["example.v"],
)
rocq_proof_test(
name = "example_test",
srcs = ["example.v"],
deps = [":example_proofs"],
)# Build proofs
bazel build //proofs:example_proofs
# Run proof tests
bazel test //proofs:example_testOn the first build, Bazel will:
- Fetch the pinned nixpkgs repository (~200MB download)
- Use nix to fetch/build Coq from nixpkgs cache (~100MB)
- Cache everything in
~/.cache/bazel/
This takes 5-10 minutes depending on your internet connection.
After initial setup:
- Toolchain is cached locally
- No nix invocation needed
- Builds are fast and hermetic
| Platform | Architecture | Status |
|---|---|---|
| Linux | x86_64 | ✅ Supported |
| Linux | aarch64 | ✅ Supported |
| macOS | x86_64 (Intel) | ✅ Supported |
| macOS | aarch64 (Apple Silicon) | ✅ Supported |
| Windows | x86_64 |
Available Coq versions via nixpkgs:
| Version | nixpkgs attribute | Status |
|---|---|---|
| 8.20 | coq_8_20 |
✅ Default |
| 8.19 | coq_8_19 |
✅ Supported |
| 8.18 | coq_8_18 |
✅ Supported |
| 8.17 | coq_8_17 |
✅ Supported |
| 8.16 | coq_8_16 |
✅ Supported |
| latest | coq |
✅ Supported |
To use a specific version:
rocq.toolchain(
version = "8.19", # Use Coq 8.19
strategy = "nix",
)See the proofs/ directory for example usage:
# Build example proofs
bazel build //proofs:all
# Test proofs compile
bazel test //proofs:...The toolchain is managed via nixpkgs, providing hermetic Coq installations:
- Pinned nixpkgs: Reproducible builds with fixed commit
- Multiple versions: Switch Coq versions via
versionattribute - Cross-platform: Same configuration works on Linux and macOS
While we use nixpkgs instead of Rocq Platform binaries, the toolchain provides equivalent functionality:
- Coq compiler and tools
- Standard library
- Documentation generator
coq-of-rust integration is planned for future releases. The rocq_library rule can compile Coq files generated by coq-of-rust.
The nix toolchain provides:
| Tool | Description |
|---|---|
coqc |
Coq compiler |
coqtop |
Interactive toplevel |
coqdoc |
Documentation generator |
coqchk |
Proof checker |
| Standard Library | lib/coq/theories/ |
Nix is not installed or not in PATH. See Installing Nix.
The nix daemon isn't running:
# macOS/Linux with systemd
sudo systemctl start nix-daemon
# macOS without systemd
sudo launchctl start org.nixos.nix-daemonThe first build downloads nixpkgs and Coq. This is normal and only happens once. Subsequent builds use the cached toolchain.
The nixpkgs commit hash may have changed. Update the hash in MODULE.bazel or wait for a rules_rocq_rust update.
# Verify rules load correctly
bazel query //rocq/...
# Build all targets
bazel build //...To update the pinned nixpkgs version:
- Find a recent commit from NixOS/nixpkgs
- Compute SHA256:
nix-prefetch-url --unpack https://github.com/NixOS/nixpkgs/archive/<commit>.tar.gz - Update MODULE.bazel with new commit and sha256
Apache License 2.0 - See LICENSE file
- nixpkgs - Nix packages collection
- rules_nixpkgs - Nix integration for Bazel
- Rocq Prover - The Rocq/Coq theorem prover