-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathmbake.nix
More file actions
138 lines (133 loc) · 4.02 KB
/
mbake.nix
File metadata and controls
138 lines (133 loc) · 4.02 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
lib,
pkgs,
config,
mkFormatterModule,
...
}:
let
configFormat = pkgs.formats.toml { };
cfg = config.programs.mbake;
settingsSchema = {
space_around_assignment = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to add spaces around assignment operators (=, :=, etc.)";
};
space_before_colon = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to add a space before colons in rules";
};
space_after_colon = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to add a space after colons in rules";
};
normalize_line_continuations = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to normalize line continuation backslashes";
};
max_line_length = lib.mkOption {
type = lib.types.nullOr lib.types.ints.unsigned;
default = null;
description = "Maximum line length before wrapping";
};
auto_insert_phony_declarations = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to automatically insert .PHONY declarations for non-file targets";
};
group_phony_declarations = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to group all .PHONY declarations together";
};
phony_at_top = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to place .PHONY declarations at the top of the file";
};
remove_trailing_whitespace = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to remove trailing whitespace from lines";
};
ensure_final_newline = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to ensure the file ends with a newline";
};
normalize_empty_lines = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to normalize empty lines";
};
max_consecutive_empty_lines = lib.mkOption {
type = lib.types.nullOr lib.types.ints.unsigned;
default = null;
description = "Maximum number of consecutive empty lines allowed";
};
fix_missing_recipe_tabs = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to fix recipe lines that are missing tabs";
};
indent_nested_conditionals = lib.mkOption {
type = lib.types.nullOr lib.types.bool;
default = null;
description = "Whether to indent nested conditional blocks (ifdef, ifndef, etc.)";
};
tab_width = lib.mkOption {
type = lib.types.nullOr lib.types.ints.unsigned;
default = null;
description = "Tab width in spaces for display purposes";
};
};
settingsFile =
let
settings = lib.filterAttrsRecursive (_n: v: v != null) cfg.settings;
formatterSettings = {
formatter = settings;
};
in
if settings != { } then configFormat.generate ".bake.toml" formatterSettings else null;
in
{
meta.maintainers = [ "theobori" ];
imports = [
(mkFormatterModule {
name = "mbake";
args = [
"format"
];
includes = [
"Makefile"
"*/Makefile"
"*.Makefile"
"Makefile.*"
"makefile"
"*/makefile"
"*.makefile"
"makefile.*"
"*.mk"
];
})
];
options.programs.mbake = {
# Represents the mbake formatter settings
# See https://github.com/EbodShojaei/bake/blob/main/.bake.toml.example#L13-L38
settings = settingsSchema;
};
config = lib.mkIf cfg.enable {
settings.formatter.mbake = {
options = (
lib.optionals (settingsFile != null) [
"--config"
(toString settingsFile)
]
);
};
};
}