diff --git a/README.md b/README.md index 9966d25..6fcc835 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,13 @@ That mostly means, for the given formatter: - You get precedence if any decisions need to be made. - Getting pinged if any issue is being found. +## Supported Nix versions + +treefmt-nix works with all known Nix version. + +If you rely on flakes and `nix fmt`, we recommend running Nix 2.25 or Lix 2.92 +or later. See https://github.com/NixOS/nix/pull/11438 + ## Commercial support Looking for help or customization? diff --git a/programs/nixfmt.nix b/programs/nixfmt.nix index 1e056d8..e449415 100644 --- a/programs/nixfmt.nix +++ b/programs/nixfmt.nix @@ -1,4 +1,12 @@ -{ mkFormatterModule, ... }: +{ + lib, + config, + mkFormatterModule, + ... +}: +let + cfg = config.programs.nixfmt; +in { meta.maintainers = [ ]; @@ -9,4 +17,33 @@ includes = [ "*.nix" ]; }) ]; + + options.programs.nixfmt = { + strict = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Enable a stricter formatting mode that isn't influenced + as much by how the input is formatted. + ''; + }; + + width = lib.mkOption { + type = lib.types.nullOr lib.types.int; + default = null; + example = 120; + description = '' + Maximum width in characters [default: 100] + ''; + }; + }; + + config = lib.mkIf cfg.enable { + settings.formatter.nixfmt.options = + lib.optionals (!isNull cfg.width) [ + "--width" + (toString cfg.width) + ] + ++ lib.optional cfg.strict "--strict"; + }; }