Modular NixOS-style configuration library. https://docs.rs/module
  • Rust 99.6%
  • Shell 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
threadexio fb7156ee64
Some checks failed
CI / check (push) Has been cancelled
CI / test (push) Has been cancelled
CI / doc (push) Has been cancelled
CI / miri (push) Has been cancelled
chore: bump version to v0.4.0
2026-06-24 14:54:11 +03:00
.github/workflows ci: check that examples build correctly 2025-05-27 15:57:27 +03:00
assets docs: make the title a path for rendering without the font 2025-05-22 01:58:00 +03:00
examples refactor: major rewrite (see description) 2026-06-18 21:58:44 +03:00
module chore: bump version to v0.4.0 2026-06-24 14:54:11 +03:00
module-derive chore: add msrv & cleanup manifests 2026-06-19 11:57:50 +03:00
module-util chore: bump version to v0.4.0 2026-06-24 14:54:11 +03:00
.gitignore chore: add .gitignore 2025-05-16 00:39:17 +03:00
Cargo.lock chore: bump version to v0.4.0 2026-06-24 14:54:11 +03:00
Cargo.toml chore: bump version to v0.4.0 2026-06-24 14:54:11 +03:00
LICENSE chore: add license 2025-05-10 13:19:57 +03:00
README.md docs: mention the module-util crate 2025-05-27 15:38:06 +03:00
rust-toolchain.toml chore: add msrv & cleanup manifests 2026-06-19 11:57:50 +03:00


logo


logo

Modular NixOS-style configuration crate.

version-badge tests-badge docs-badge license-badge



A crate that provides:

  • A standard interface for merging data.

  • Strategies for merging that data.

The above can be used to build a module system akin to that of NixOS. With this crate you can easily build modular and composable configuration for your application.

An overview of module

The Merge trait

The core functionality of module is provided by the Merge trait, it is the lowest-level building block of this crate and provides the interface for merging data. A value is called "mergeable" if it can be merged with the Merge trait. A collection of such values is typically referred to as a "module".

Strategies

Upon the Merge trait build wrappers like Overridable and NoMerge which provide the "how" to merge data. Most common types from core, alloc and std have a sensible merge strategy. However, these wrappers can be used to refine the merging of data even more. Such wrappers live under types.

Errors & Context

When merging complex nested data, it is possible that an error occurs in a merge operation deep inside the data. Error and Context exist to provide useful errors and context about where the failure happened and why.

To create such complex structures, the crate provides the Merge derive macro that merges each field of the struct and automatically adds the necessary context.

NOTE: The derive macro only supports structs. It is not obvious how to merge enums and a handwritten implementation will probably be better for readability in this case.

Evaluators

Just the Merge trait is not enough however to build a fully functioning module system from configuration files in some format. Users of the crate must build an "evaluator".

The evaluator's job is to construct such modules and merge them together. The source of these modules can be files from disk, environment variables and generally any medium that can be used to pass information to the app.

Evaluators can be purpose-written for custom solutions. However, for some common use cases, the module-util crate provides some fully functional evaluators.

Examples

Full examples do not fit here. See examples for reimplementations of popular programs using this crate.

Features

  • std: Implement Merge for many std types. This is a default feature. Disabling it will also make the entire crate no_std. (alloc is still required)

  • derive: Enable the Merge derive macro. This is disabled by default to avoid introducing the heavy dependencies of proc-macros when not needed.

  • serde: Implement serde::Deserialize for types under types, allowing them to be used seamlessly with serde.

License

All code in this repository is licensed under the Apache 2.0 license, a copy of which can be found here.