-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Expand file tree
/
Copy pathlib.nix
More file actions
107 lines (90 loc) · 2.14 KB
/
lib.nix
File metadata and controls
107 lines (90 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
lib,
pkgs,
treefmt,
}:
{
/**
Evaluate a treefmt configuration.
# Type
```
Module -> Configuration
```
# Inputs
`module`
: A treefmt module. See [options reference](#sec-treefmt-options-reference).
*/
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.
# Check
The resulting package has a `check` attribute of type `Path -> Derivation`.
The derivation returned will only build if the path supplied is already formatted correctly.
```
{ pkgs }:
let
myTreefmt = pkgs.treefmt.withConfig ./treefmt-config.nix;
project = ../.;
in
myTreefmt.check project
```
# Type
```
Module -> Derivation
```
# Inputs
`module`
: A treefmt module. See [options reference](#sec-treefmt-options-reference).
*/
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`
: A settings module, used to build a treefmt config file.
See [`settings` option reference](#opt-treefmt-settings).
*/
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;
};
};
}