From 4aea2e44ed77abc119ac7cfb08d81e9cc208e37c Mon Sep 17 00:00:00 2001 From: zimbatm Date: Sat, 11 Jan 2025 10:09:21 +0100 Subject: [PATCH 1/2] nixfmt: add support for --width and --strict flags --- programs/nixfmt.nix | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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"; + }; } From 79fbd2cc9ab5bffad8e30eb87e04a85bc49e267c Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 24 Jan 2025 12:22:09 +0100 Subject: [PATCH 2/2] README: add supported nix versions Document what versions of Nix work best with the project. Fixes #303 --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) 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?