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.
Library and documentation tests do not require NetworkManager. Environmental tests must use the isolated Docker harness or an explicit opt-in.
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/docs; environmental tests stay ignored
docker compose run --build --rm test-integration # isolated NM settings/agent/WireGuard/wired lifecycle
docker compose run --build --rm test-wifi-integration # CI-equivalent virtual WiFi tests (Linux)Integration tests are #[ignore] so normal test commands never touch the host
NetworkManager. The WiFi harness requires two mac80211_hwsim radios:
sudo modprobe mac80211_hwsim radios=2
docker compose run --build --rm test-wifi-integration
sudo modprobe -r mac80211_hwsimFor a deliberately selected local NetworkManager, the NM-only opt-in is:
NMRS_REQUIRE_NETWORKMANAGER=1 \
cargo test --test integration_test --all-features \
networkmanager_ -- --ignored --test-threads=1Those tests create, update, and delete saved profiles; exercise a real NetworkManager-to-agent secret exchange; and activate a native WireGuard connection. The Docker harness additionally creates an isolated veth pair and validates wired DHCP activation. Once a capability flag is set, missing facilities, timeouts, and unexpected errors must fail rather than skip.
- 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.