Skip to content

Commit 50e9fca

Browse files
committed
nixfmt: support the new official 1.0 release of nixfmt
- Deprecate nixfmt-classic when used with v1.0+ - Warn when `hooks.nixfmt` is used with older `nixfmt` versions Once 25.11 lands, we can deprecate `nixfmt-rfc-style`.
1 parent 46d55f0 commit 50e9fca

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

modules/hooks.nix

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ in
959959
};
960960
};
961961
nixfmt = mkOption {
962-
description = "Deprecated nixfmt hook. Use nixfmt-classic or nixfmt-rfc-style instead.";
962+
description = "nixfmt hook";
963963
visible = false;
964964
type = types.submodule {
965965
imports = [ hookModule ];
@@ -2143,10 +2143,19 @@ in
21432143
lib.optional cfg.hooks.rome.enable ''
21442144
The hook `hooks.rome` has been renamed to `hooks.biome`.
21452145
''
2146-
++ lib.optional cfg.hooks.nixfmt.enable ''
2146+
++ lib.optional (cfg.hooks.nixfmt.enable && lib.versionOlder cfg.hooks.nixfmt.package.version "1.0") ''
21472147
The hook `hooks.nixfmt` has been renamed to `hooks.nixfmt-classic`.
21482148
21492149
The new RFC 166-style nixfmt is available as `hooks.nixfmt-rfc-style`.
2150+
''
2151+
++ lib.optional (cfg.hooks.nixfmt-classic.enable && lib.versionAtLeast cfg.hooks.nixfmt-classic.package.version "1.0") ''
2152+
The hook `hooks.nixfmt-classic` is using an incompatible version of `nixfmt`.
2153+
2154+
Found: ${cfg.hooks.nixfmt-classic.package.version}.
2155+
Expected: < v1.0
2156+
2157+
`hooks.nixfmt-classic` supports versions of `nixfmt` up to `v1.0`.
2158+
For `nixfmt` `v1.0` and newer, switch to `hooks.nixfmt`.
21502159
'';
21512160

21522161
# PLEASE keep this sorted alphabetically.
@@ -3402,8 +3411,8 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
34023411
};
34033412
nixfmt =
34043413
{
3405-
name = "nixfmt-deprecated";
3406-
description = "Deprecated Nix code prettifier. Use nixfmt-classic.";
3414+
name = "nixfmt";
3415+
description = "Official Nix code formatter.";
34073416
package = tools.nixfmt;
34083417
entry = "${hooks.nixfmt.package}/bin/nixfmt ${lib.optionalString (hooks.nixfmt.settings.width != null) "--width=${toString hooks.nixfmt.settings.width}"}";
34093418
files = "\\.nix$";

0 commit comments

Comments
 (0)