-
Notifications
You must be signed in to change notification settings - Fork 83
/
flake-module.nix
62 lines (59 loc) · 2.04 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
{ self, lib, flake-parts-lib, ... }:
let
inherit (flake-parts-lib)
mkPerSystemOption;
inherit (lib)
mkOption
types;
in
{
options = {
perSystem = mkPerSystemOption
({ config, self', inputs', pkgs, system, ... }: {
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 = types.submoduleWith {
modules = (import ./.).submodule-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);
};
});
};
}