Skip to content

Commit d392301

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 d392301

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
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$";

nix/tools.nix

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,16 @@ in
231231
# Disable tests as these take way to long on our infra.
232232
julia-bin = julia-bin.overrideAttrs (_: _: { doInstallCheck = false; });
233233

234-
# nixfmt was renamed to nixfmt-classic in 24.05.
235-
# nixfmt may be replaced by nixfmt-rfc-style in the future.
236-
nixfmt = if nixfmt-classic == null then nixfmt else nixfmt-classic;
234+
# nixfmt 1.0 is now the official Nix formatter as of 25.11.
235+
#
236+
# In 24.05, the `nixfmt` package was deprecated and replaced with two separate packages:
237+
# - nixfmt-classic
238+
# - nixfmt-rfc-style
239+
#
240+
# Remove this block in 26.05
241+
nixfmt =
242+
if lib.versionOlder nixfmt.version "1.0" && nixfmt-classic != null
243+
then nixfmt-classic
244+
else nixfmt;
237245
inherit nixfmt-classic nixfmt-rfc-style;
238246
}

0 commit comments

Comments
 (0)