Context for AI agents working in this repository.
nmrs is a Rust library for managing network connections via NetworkManager over D-Bus.
nmrs/src/
lib.rs — public API surface, re-exports from api/
api/
network_manager.rs — main entry point (NetworkManager struct)
models/ — public types, enums, errors, traits
builders/ — connection settings constructors (wifi, vpn, bluetooth)
core/ — internal business logic (connection, scanning, VPN, state waiting)
dbus/ — raw D-Bus proxy calls (NM, devices, access points)
monitoring/ — real-time D-Bus signal subscriptions
types/ — constants, device type registry
util/ — validation, cert handling, helpers
lib.rs re-exports commonly used types at the crate root for convenience.
Internal modules (core, dbus, monitoring, types, util) are not part of the public API.
Requires a running NetworkManager instance (or use the provided Dockerfile).
cargo check # quick compile check
cargo fmt --all -- --check # formatting (default rustfmt, no config file)
cargo clippy --all-targets --all-features -- -D warnings # lints (warnings are errors in CI)
cargo test -p nmrs --lib --all-features # unit tests only
cargo test --doc --all-features --workspace # doc tests
cargo test --all-features --workspace # unit + integration (needs NM + wifi hardware)
cargo test --test integration_test --all-features # integration onlyIntegration tests require wifi hardware or mac80211_hwsim:
sudo modprobe mac80211_hwsim radios=2
cargo test --test integration_test --all-features
sudo modprobe -r mac80211_hwsim- Edition 2024, resolver 3, stable Rust (MSRV: 1.90.0)
- Workspace lints in root
Cargo.toml:unused = "warn", clippy allowstoo_many_argumentsandtype_complexity - CI runs: format, clippy, lib tests, doc tests, semver-checks (
cargo-semver-checksfornmrs), cross-compile for aarch64
- Error handling: all public fallible operations return
nmrs::Result<T>(alias forResult<T, ConnectionError>). UseConnectionErrorvariants, not raw strings. - Builder pattern: config structs use
with_*builder methods returningSelfwith#[must_use]. SeeWireGuardConfig,OpenVpnConfig,EapOptions. #[non_exhaustive]on all public structs and enums.- Doc comments on all public items with examples where practical. Doc examples use
nmrs::paths (crate root re-exports). - No
unwrap()in library code — return errors via?orConnectionError.unwrap_or_else()is allowed if the error is expected and there is a fallback value. Document this with a comment.
- Tests: unit tests live in
#[cfg(test)] mod testswithin the module or inapi/models/tests.rs. Integration tests innmrs/tests/. Assert behavior, not implementation.
Follow Conventional Commits:
type(#issue): description
Examples: fix(#24): handle missing DNS in VPN config, feat: add OpenVPN proxy support.
Atomic commits — one logical change per commit.
Keep a Changelog format in nmrs/CHANGELOG.md.
Sections: Added, Changed, Fixed. Link PRs/issues in parentheses.
- The
VpnCredentialstype is deprecated — preferWireGuardConfigfor new WireGuard code.