diff --git a/module-options.nix b/module-options.nix index c81ac33..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 = { }; @@ -30,25 +39,23 @@ 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/**" ]; - }; + 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"; - }; + on-unmatched = mkOption { + description = "Log paths that did not match any formatters at the specified log level."; + type = types.nullOr (types.enum [ + "debug" + "info" + "warn" + "error" + "fatal" + ]); + default = null; }; formatter = mkOption { @@ -276,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); };