arch-toolkit
Complete Rust toolkit for Arch Linux package management. Provides a unified API for interacting with Arch Linux package management, including AUR (Arch User Repository) operations, dependency resolution, package index queries, installation command building, news feeds, and security advisories.
Features
Current Features
-
AUR Operations (
aurfeature, enabled by default)- Package search via AUR RPC v5
- Detailed package information retrieval
- Package comments fetching and parsing
- PKGBUILD content retrieval
- Automatic rate limiting with exponential backoff
- Configurable retry policies with per-operation control
- Optional caching layer (memory and disk)
-
Dependency Management (
depsfeature)- Parse dependencies from PKGBUILD files (single-line and multi-line arrays)
- Parse dependencies from .SRCINFO files
- Parse dependency specifications with version constraints
- Parse pacman output for dependencies and conflicts
- Fetch .SRCINFO from AUR (requires
aurfeature) - Dependency resolution for official, AUR, and local packages
- Reverse dependency analysis for safe package removal
- Version comparison using pacman-compatible algorithm
- Package querying (installed, upgradable, versions)
- Source determination (official, AUR, local)
-
Package Index Queries (
indexfeature)- Installed package queries (
pacman -Qq) with optional caching - Explicit package tracking (all explicit or leaf-only packages)
- Official repository search (substring and optional fuzzy matching)
- Official index fetching (from
pacman -Slor the Arch Packages API) - Index persistence (save/load the official index as JSON)
- Sync and async APIs (async via
tokio::spawn_blocking)
- Installed package queries (
-
Install Command Building (
installfeature)- Pacman install/remove/update command construction (build, never execute)
- AUR helper commands with paru/yay detection and preference
- Privilege tool detection (sudo/doas) and command wrapping
- Batch planning: split mixed target lists between pacman and an AUR helper
- Removal cascade modes (
-R,-Rs,-Rns) - Strict package-name validation and POSIX shell quoting
-
News & Security Advisories (
newsfeature)- Arch Linux news RSS fetching with date normalization
- Security advisory Atom feed with severity and package extraction
- Pure parse functions (testable offline against recorded feeds)
- Cutoff-date filtering for incremental fetches
-
Build-Preflight Analysis (
sandboxfeature)- Compare a PKGBUILD/.SRCINFO's dependencies against the host
- Per-category deltas (depends, makedepends, checkdepends, optdepends)
- Installed-version and version-constraint checking
- Missing-package and ready-to-build reporting
Installation
Add arch-toolkit to your Cargo.toml:
[]
= "0.3"
Feature Flags
aur(default): AUR search, package info, comments, and PKGBUILD fetchingdeps: Dependency parsing from PKGBUILD, .SRCINFO, and pacman outputindex: Package database queries (installed, explicit, official repositories) and index persistenceinstall: Installation command building (pacman, AUR helpers, batch planning; enablesdeps)news: Arch news RSS and security advisoriessandbox: Build-preflight dependency analysis (enablesdeps)fuzzy-search: Fuzzy matching for official index search (used withindex)cache-disk: Enable disk-based caching for persistence across restarts
To disable default features:
= { = "0.3", = false, = ["aur"] }
To enable dependency parsing:
= { = "0.3", = ["deps"] }
To enable disk caching:
= { = "0.3", = ["cache-disk"] }
To enable package index queries:
= { = "0.3", = ["index"] }
Quick Start
Basic Usage
use *;
async
Custom Configuration
use ArchClient;
use Duration;
let client = builder
.timeout
.user_agent
.max_retries
.build?;
Or configure via environment variables (perfect for CI/CD):
let client = builder
.from_env // Load configuration from environment
.build?;
Retry Policy Configuration
use ArchClient;
use RetryPolicy;
let retry_policy = RetryPolicy ;
let client = builder
.retry_policy
.build?;
Caching
Enable caching to reduce network requests:
use ArchClient;
use CacheConfigBuilder;
use Duration;
let cache_config = new
.enable_search
.search_ttl // 5 minutes
.enable_info
.info_ttl // 15 minutes
.enable_comments
.comments_ttl // 10 minutes
.memory_cache_size
.build;
let client = builder
.cache_config
.build?;
With disk caching (requires cache-disk feature):
let cache_config = new
.enable_search
.search_ttl
.enable_disk_cache // Persist across restarts
.build;
Fetch Comments
let comments = client.aur.comments.await?;
for comment in comments.iter.take
Fetch PKGBUILD
let pkgbuild = client.aur.pkgbuild.await?;
println!;
Dependency Parsing and Resolution
Parse dependencies from PKGBUILD or .SRCINFO files:
use ;
// Parse PKGBUILD
let pkgbuild = r"depends=('glibc' 'python>=3.10')";
let = parse_pkgbuild_deps;
// Parse .SRCINFO
let srcinfo = r"depends = glibc\ndepends = python>=3.10";
let = parse_srcinfo_deps;
Dependency Resolution
Resolve dependencies for packages:
use ;
let resolver = new;
let packages = vec!;
let result = resolver.resolve?;
println!;
for dep in result.dependencies
Reverse Dependency Analysis
Find all packages that depend on packages being removed:
use ;
let analyzer = new;
let packages = vec!;
let report = analyzer.analyze?;
println!;
Version Comparison
Compare package versions:
use ;
// Compare versions
use Ordering;
assert_eq!;
// Check if version satisfies requirement
assert!;
assert!;
Package Querying
Query installed and upgradable packages:
use ;
// Get installed packages
let installed = get_installed_packages?;
println!;
// Get upgradable packages
let upgradable = get_upgradable_packages?;
println!;
// Get installed version
if let Ok = get_installed_version
// Get available version
if let Some = get_available_version
Source Determination
Determine where a package comes from:
use ;
use HashSet;
let installed = get_installed_packages?;
let = determine_dependency_source;
println!;
if is_system_package
Package Index Queries
Query installed packages and search official repositories (requires index feature):
use ;
use Path;
// Query installed packages
let installed = get_installed_packages?;
if is_installed
// Load a cached official index, falling back to a fresh fetch
let path = new;
let index = load_from_disk.or_else?;
// Search the official index
for result in search_official
// Persist the index for the next session
save_to_disk?;
Install Command Building
Build (never execute) pacman and AUR helper commands (requires install feature):
use ;
use ;
use PackageRef;
// Plan a mixed batch: official packages via pacman, AUR packages via paru/yay
let targets = vec!;
let plan = build_batch_install?;
for command in &plan.commands
// Removal with cascade control
let remove = with_privilege;
println!; // sudo pacman -Rns --noconfirm -- old-package
News and Security Advisories
Fetch Arch news and advisories (requires news feature):
use ;
let client = new;
// Latest news, dates normalized to YYYY-MM-DD
for item in fetch_arch_news.await?
// Advisories since a date, with severity and affected packages
for advisory in fetch_security_advisories.await?
Build-Preflight Analysis
Check what an AUR package would need before building (requires sandbox feature):
use ;
use analyze_pkgbuild;
let installed = get_installed_packages.unwrap_or_default;
let provided = get_provided_packages;
let info = analyze_pkgbuild;
if !info.is_ready_to_build
Health Checks
Monitor AUR service status:
// Quick health check
let is_healthy = client.health_check.await?;
// Detailed status with latency
let status = client.health_status.await?;
println!;
Examples
See the examples/ directory for comprehensive examples:
examples/aur_example.rs: Complete AUR operations demonstrationexamples/with_caching.rs: Caching layer usageexamples/env_config.rs: Environment variable configurationexamples/health_check.rs: Health check functionalityexamples/pkgbuild_example.rs: PKGBUILD dependency parsingexamples/srcinfo_example.rs: .SRCINFO parsing and fetchingexamples/deps_example.rs: Comprehensive dependency module examplesexamples/parse_example.rs: Dependency specification parsingexamples/query_example.rs: Package querying examplesexamples/resolve_example.rs: Dependency resolution examplesexamples/reverse_example.rs: Reverse dependency analysis examplesexamples/source_example.rs: Source determination examplesexamples/version_example.rs: Version comparison examplesexamples/index_example.rs: Package index queries and persistence examplesexamples/install_example.rs: Install command building and batch planning examplesexamples/news_example.rs: Arch news and security advisory examplesexamples/sandbox_example.rs: Build-preflight dependency analysis examples
Run examples with:
API Documentation
Full API documentation is available at docs.rs/arch-toolkit or build locally:
Rate Limiting
arch-toolkit automatically implements rate limiting for archlinux.org requests:
- Minimum 200ms delay between requests
- Exponential backoff on failures
- Serialized requests (one at a time) to prevent overwhelming the server
- Configurable retry policies
Error Handling
All operations return Result<T, ArchToolkitError>. Common error types:
ArchToolkitError::Network: HTTP request failuresArchToolkitError::Parse: JSON/HTML parsing errorsArchToolkitError::InvalidInput: Invalid parameters or URLsArchToolkitError::Timeout: Request timeoutArchToolkitError::EmptyInput: Empty input provided (with input validation)ArchToolkitError::InvalidPackageName: Invalid package name format
Input validation is enabled by default and validates package names and search queries against Arch Linux standards.
Requirements
- Rust 1.91 or later (edition 2024,
Duration::from_mins) - Tokio runtime (for async operations)
License
MIT