From c267ebfe88fb4070f33f4625ee19556a627f8d48 Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Wed, 8 Jan 2025 10:48:54 +0000 Subject: [PATCH 1/2] fix: on-unmatched option Also moves excludes in the root of the settings, as global has been deprecated. Signed-off-by: Brian McGee --- module-options.nix | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/module-options.nix b/module-options.nix index c81ac33..4f92dd2 100644 --- a/module-options.nix +++ b/module-options.nix @@ -30,25 +30,22 @@ let type = types.submodule { freeformType = configFormat.type; options = { - global = { - excludes = mkOption { - description = "A global list of paths to exclude. Supports glob."; - type = types.listOf types.str; - default = [ ]; - example = [ "./node_modules/**" ]; - }; - - on-unmatched = mkOption { - description = "Log paths that did not match any formatters at the specified log level."; - type = types.enum [ - "debug" - "info" - "warn" - "error" - "fatal" - ]; - default = "warn"; - }; + excludes = mkOption { + description = "A global list of paths to exclude. Supports glob."; + type = types.listOf types.str; + default = [ ]; + example = [ "./node_modules/**" ]; + }; + on-unmatched = mkOption { + description = "Log paths that did not match any formatters at the specified log level."; + type = types.enum [ + "debug" + "info" + "warn" + "error" + "fatal" + ]; + default = "warn"; }; formatter = mkOption { From 9af0bd661485d9a35f30d22e77023d349f9efad0 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 8 Jan 2025 15:29:10 +0100 Subject: [PATCH 2/2] fix: avoid putting empty keys in the config file --- module-options.nix | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/module-options.nix b/module-options.nix index 4f92dd2..fb989ef 100644 --- a/module-options.nix +++ b/module-options.nix @@ -23,6 +23,15 @@ let configFormat = pkgs.formats.toml { }; + # Remove keys in the setting that are "empty" to keep the config file lean + emptySettingsKeys = + lib.optional (config.settings.excludes == []) "excludes" + ++ lib.optional (config.settings.on-unmatched == null) "on-unmatched"; + + settingsData = builtins.removeAttrs config.settings emptySettingsKeys; + + configFile = configFormat.generate "treefmt.toml" settingsData; + # The schema of the treefmt.toml data structure. configSchema = mkOption { default = { }; @@ -36,16 +45,17 @@ let default = [ ]; example = [ "./node_modules/**" ]; }; + on-unmatched = mkOption { description = "Log paths that did not match any formatters at the specified log level."; - type = types.enum [ + type = types.nullOr (types.enum [ "debug" "info" "warn" "error" "fatal" - ]; - default = "warn"; + ]); + default = null; }; formatter = mkOption { @@ -273,7 +283,7 @@ in # Config config.build = { - configFile = configFormat.generate "treefmt.toml" config.settings; + inherit configFile; devShell = pkgs.mkShell { nativeBuildInputs = [ config.build.wrapper ] ++ (lib.attrValues config.build.programs); };