API Documentation
The flk library exposes Rust APIs for programmatic access to flake generation and parsing.
Generating Documentation
Build the API documentation locally:
cargo doc --no-deps --open
Or with all features and dependencies:
cargo doc --all-features --open
Module Overview
flk::flake
Core flake functionality:
-
flk::flake::generator- Template loading and flake generationgenerate_flake(project_type)- Generate profile content for a project typegenerate_helper_module()- Generate the.flk/default.nixloadergenerate_pins()- Generate empty pins file
-
flk::flake::parsers- Nix file parsing and modificationpackages- Parse/modifypackages = [ ... ];sectionsenv- Parse/modifyenvVars = { ... };sectionscommands- Parse/modify shell hook commandsoverlays- Parse/modifypins.nixfor version pinningflake- Parse top-level flake structureutils- Profile resolution and parsing helpers
-
flk::flake::interfaces- Data structuresFlakeConfig- Complete flake configurationProfile- Single profile with packages, commands, env varsPackage- Package entry with optional versionEnvVar- Environment variable key-value pair
-
flk::flake::nix_render- Safe Nix syntax renderingnix_string(s)- Escape string for Nix double-quoted stringsnix_attr_key(s)- Format attribute key (quote if needed)
flk::utils
Utility functions:
flk::utils::backup- Lockfile backup managementflk::utils::visual- Spinner and progress display
Example Usage
#![allow(unused)]
fn main() {
use flk::flake::generator::generate_flake;
use flk::flake::parsers::packages::parse_packages_section;
// Generate a Rust profile template
let profile_content = generate_flake("rust")?;
// Parse packages from an existing profile
let content = std::fs::read_to_string(".flk/profiles/rust.nix")?;
let section = parse_packages_section(&content)?;
// Add a package (returns new content directly)
let new_content = section.add_package(&content, "ripgrep", None);
std::fs::write(".flk/profiles/rust.nix", new_content)?;
}
Contributing to the API
When contributing:
- Document all public items with
///doc comments - Include
# Arguments,# Returns, and# Errorssections where applicable - Add examples in doc comments for non-obvious behavior
- Run
cargo doc --no-depsbefore submitting to check for warnings - Keep internal/unstable functions prefixed with underscore (
_parse_*)