-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathflake-module.nix
79 lines (77 loc) · 2.19 KB
/
flake-module.nix
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
{
self,
lib,
flake-parts-lib,
...
}:
let
inherit (flake-parts-lib)
mkPerSystemOption
;
inherit (lib)
mkOption
types
;
treefmt-nix-lib = import ./.;
in
{
options = {
perSystem = mkPerSystemOption (
{
config,
pkgs,
...
}:
{
options.treefmt = mkOption {
description = ''
Project-level treefmt configuration
Use `config.treefmt.build.wrapper` to get access to the resulting treefmt
package based on this configuration.
By default treefmt-nix will set the `formatter.<system>` attribute of the flake,
used by the `nix fmt` command.
'';
type = treefmt-nix-lib.submoduleWith lib {
modules = [
{
options.pkgs = lib.mkOption {
default = pkgs;
defaultText = "`pkgs` (module argument of `perSystem`)";
};
options.flakeFormatter = lib.mkOption {
type = types.bool;
default = true;
description = ''
Enables `treefmt` the default formatter used by the `nix fmt` command
'';
};
options.flakeCheck = lib.mkOption {
type = types.bool;
default = true;
description = ''
Add a flake check to run `treefmt`
'';
};
options.projectRoot = lib.mkOption {
type = types.path;
default = self;
defaultText = lib.literalExpression "self";
description = ''
Path to the root of the project on which treefmt operates
'';
};
}
];
};
default = { };
};
config = {
checks = lib.mkIf config.treefmt.flakeCheck {
treefmt = config.treefmt.build.check config.treefmt.projectRoot;
};
formatter = lib.mkIf config.treefmt.flakeFormatter (lib.mkDefault config.treefmt.build.wrapper);
};
}
);
};
}