2025-05-19 16:22:32 +01:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
treefmt,
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
Evaluate a treefmt configuration.
|
|
|
|
|
|
|
|
# Type
|
|
|
|
|
|
|
|
```
|
|
|
|
Module -> Configuration
|
|
|
|
```
|
|
|
|
|
|
|
|
# Inputs
|
|
|
|
|
2025-05-19 22:13:58 +01:00
|
|
|
`module`
|
|
|
|
: A treefmt module. See [options reference](#sec-treefmt-options-reference).
|
2025-05-19 16:22:32 +01:00
|
|
|
*/
|
|
|
|
evalConfig =
|
|
|
|
module:
|
|
|
|
lib.evalModules {
|
|
|
|
class = "treefmtConfig";
|
|
|
|
specialArgs.modulesPath = ./modules;
|
|
|
|
modules = [
|
|
|
|
{
|
|
|
|
_file = "treefmt.evalConfig";
|
|
|
|
_module.args.pkgs = lib.mkOptionDefault pkgs;
|
|
|
|
package = lib.mkOptionDefault treefmt;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
_file = "<treefmt.evalConfig args>";
|
|
|
|
imports = lib.toList module;
|
|
|
|
}
|
|
|
|
./modules/default.nix
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wrap treefmt, configured using structured settings.
|
|
|
|
|
|
|
|
# Type
|
|
|
|
|
|
|
|
```
|
|
|
|
Module -> Derivation
|
|
|
|
```
|
|
|
|
|
|
|
|
# Inputs
|
|
|
|
|
2025-05-19 22:13:58 +01:00
|
|
|
`module`
|
|
|
|
: A treefmt module. See [options reference](#sec-treefmt-options-reference).
|
2025-05-19 16:22:32 +01:00
|
|
|
*/
|
|
|
|
withConfig =
|
|
|
|
module:
|
|
|
|
let
|
|
|
|
configuration = treefmt.evalConfig {
|
|
|
|
_file = "<treefmt.withConfig args>";
|
|
|
|
imports = lib.toList module;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
configuration.config.result;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Build a treefmt config file from structured settings.
|
|
|
|
|
|
|
|
# Type
|
|
|
|
|
|
|
|
```
|
|
|
|
Module -> Derivation
|
|
|
|
```
|
|
|
|
|
|
|
|
# Inputs
|
|
|
|
|
|
|
|
`settings`
|
2025-05-19 22:13:58 +01:00
|
|
|
: A settings module, used to build a treefmt config file.
|
|
|
|
See [`settings` option reference](#opt-treefmt-settings).
|
2025-05-19 16:22:32 +01:00
|
|
|
*/
|
|
|
|
buildConfig =
|
|
|
|
module:
|
|
|
|
let
|
|
|
|
configuration = treefmt.evalConfig {
|
|
|
|
_file = "<treefmt.buildConfig args>";
|
|
|
|
settings.imports = lib.toList module;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
configuration.config.configFile.overrideAttrs {
|
|
|
|
passthru = {
|
|
|
|
inherit (configuration.config) settings;
|
|
|
|
options = (opt: opt.type.getSubOptions opt.loc) configuration.options.settings;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|