Skip to content

Commit 3ed7ec8

Browse files
committed
fix: avoid putting empty keys in the config file
1 parent c8fd00f commit 3ed7ec8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

module-options.nix

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ let
2323

2424
configFormat = pkgs.formats.toml { };
2525

26+
# Remove keys in the setting that are "empty" to keep the config file lean
27+
emptySettingsKeys =
28+
lib.optional (config.settings.excludes == []) "excludes"
29+
++ lib.optional (config.settings.on-unmatched == null) "on-unmatched";
30+
31+
settingsData = builtins.removeAttrs config.settings emptySettingsKeys;
32+
33+
configFile = configFormat.generate "treefmt.toml" settingsData;
34+
2635
# The schema of the treefmt.toml data structure.
2736
configSchema = mkOption {
2837
default = { };
@@ -36,16 +45,17 @@ let
3645
default = [ ];
3746
example = [ "node_modules/*" ];
3847
};
48+
3949
on-unmatched = mkOption {
4050
description = "Log paths that did not match any formatters at the specified log level.";
41-
type = types.enum [
51+
type = types.nullOr (types.enum [
4252
"debug"
4353
"info"
4454
"warn"
4555
"error"
4656
"fatal"
47-
];
48-
default = "warn";
57+
]);
58+
default = null;
4959
};
5060

5161
formatter = mkOption {
@@ -324,7 +334,7 @@ in
324334

325335
# Config
326336
config.build = {
327-
configFile = configFormat.generate "treefmt.toml" config.settings;
337+
inherit configFile;
328338
devShell = pkgs.mkShell {
329339
nativeBuildInputs = [ config.build.wrapper ] ++ (lib.attrValues config.build.programs);
330340
};

0 commit comments

Comments
 (0)