nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 pkgs,
4 treefmt,
5}:
6{
7 /**
8 Evaluate a treefmt configuration.
9
10 # Type
11
12 ```
13 Module -> Configuration
14 ```
15
16 # Inputs
17
18 `module`
19 : A treefmt module. See [options reference](#sec-treefmt-options-reference).
20 */
21 evalConfig =
22 module:
23 lib.evalModules {
24 class = "treefmtConfig";
25 specialArgs.modulesPath = ./modules;
26 modules = [
27 {
28 _file = "treefmt.evalConfig";
29 _module.args.pkgs = lib.mkOptionDefault pkgs;
30 package = lib.mkOptionDefault treefmt;
31 }
32 {
33 _file = "<treefmt.evalConfig args>";
34 imports = lib.toList module;
35 }
36 ./modules/default.nix
37 ];
38 };
39
40 /**
41 Wrap treefmt, configured using structured settings.
42
43 # Type
44
45 ```
46 Module -> Derivation
47 ```
48
49 # Inputs
50
51 `module`
52 : A treefmt module. See [options reference](#sec-treefmt-options-reference).
53 */
54 withConfig =
55 module:
56 let
57 configuration = treefmt.evalConfig {
58 _file = "<treefmt.withConfig args>";
59 imports = lib.toList module;
60 };
61 in
62 configuration.config.result;
63
64 /**
65 Build a treefmt config file from structured settings.
66
67 # Type
68
69 ```
70 Module -> Derivation
71 ```
72
73 # Inputs
74
75 `settings`
76 : A settings module, used to build a treefmt config file.
77 See [`settings` option reference](#opt-treefmt-settings).
78 */
79 buildConfig =
80 module:
81 let
82 configuration = treefmt.evalConfig {
83 _file = "<treefmt.buildConfig args>";
84 settings.imports = lib.toList module;
85 };
86 in
87 configuration.config.configFile.overrideAttrs {
88 passthru = {
89 inherit (configuration.config) settings;
90 options = (opt: opt.type.getSubOptions opt.loc) configuration.options.settings;
91 };
92 };
93}