Skip to content

Commit 7106561

Browse files
authored
Merge pull request #515 from cachix/fix-migrations
hooks: fix rome and nixfmt migrations
2 parents eb74e0b + e76201c commit 7106561

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

modules/hooks.nix

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ in
851851
};
852852
};
853853
nixfmt = mkOption {
854-
description = "Deprecated nixfmt hook";
854+
description = "Deprecated nixfmt hook. Use nixfmt-classic or nixfmt-rfc-style instead.";
855855
visible = false;
856856
type = types.submodule {
857857
imports = [ hookModule ];
@@ -1372,6 +1372,37 @@ in
13721372
};
13731373
};
13741374
};
1375+
rome = mkOption {
1376+
description = "Deprecated rome hook. Use biome instead.";
1377+
visible = false;
1378+
type = types.submodule {
1379+
imports = [ hookModule ];
1380+
options.settings = {
1381+
binPath =
1382+
mkOption {
1383+
type = types.nullOr types.path;
1384+
description = "`biome` binary path. E.g. if you want to use the `biome` in `node_modules`, use `./node_modules/.bin/biome`.";
1385+
default = null;
1386+
defaultText = "\${tools.biome}/bin/biome";
1387+
};
1388+
1389+
write =
1390+
mkOption {
1391+
type = types.bool;
1392+
description = "Whether to edit files inplace.";
1393+
default = true;
1394+
};
1395+
1396+
configPath = mkOption {
1397+
type = types.str;
1398+
description = "Path to the configuration JSON file";
1399+
# an empty string translates to use default configuration of the
1400+
# underlying biome binary (i.e biome.json if exists)
1401+
default = "";
1402+
};
1403+
};
1404+
};
1405+
};
13751406
rustfmt = mkOption {
13761407
description = ''
13771408
Additional rustfmt settings
@@ -2986,9 +3017,14 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
29863017
builtins.toString script;
29873018
files = "\\.nix$";
29883019
};
2989-
# nixfmt was renamed to nixfmt-classic.
2990-
# The hook has been deprecated to free up the name for when the new RFC-style nixfmt becomes stable.
2991-
nixfmt = nixfmt-classic;
3020+
nixfmt =
3021+
{
3022+
name = "nixfmt-deprecated";
3023+
description = "Deprecated Nix code prettifier. Use nixfmt-classic.";
3024+
package = tools.nixfmt;
3025+
entry = "${hooks.nixfmt.package}/bin/nixfmt ${lib.optionalString (hooks.nixfmt.settings.width != null) "--width=${toString hooks.nixfmt.settings.width}"}";
3026+
files = "\\.nix$";
3027+
};
29923028
nixfmt-classic =
29933029
{
29943030
name = "nixfmt-classic";
@@ -3329,7 +3365,23 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
33293365
"${hooks.ripsecrets.package}/bin/ripsecrets ${cmdArgs}";
33303366
types = [ "text" ];
33313367
};
3332-
rome = biome;
3368+
rome =
3369+
{
3370+
name = "rome-deprecated";
3371+
description = "";
3372+
types_or = [ "javascript" "jsx" "ts" "tsx" "json" ];
3373+
package = tools.biome;
3374+
entry =
3375+
let
3376+
binPath = migrateBinPathToPackage hooks.rome "/bin/biome";
3377+
cmdArgs =
3378+
mkCmdArgs [
3379+
[ (hooks.rome.settings.write) "--apply" ]
3380+
[ (hooks.rome.settings.configPath != "") "--config-path ${hooks.rome.settings.configPath}" ]
3381+
];
3382+
in
3383+
"${binPath} check ${cmdArgs}";
3384+
};
33333385
ruff =
33343386
{
33353387
name = "ruff";

modules/pre-commit.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{ config, lib, pkgs, hookModule, ... }:
22
let
33
inherit (lib)
4-
attrNames
54
boolToString
65
concatStringsSep
76
compare
87
filterAttrs
98
literalExample
109
mapAttrsToList
11-
mkIf
1210
mkOption
1311
types
1412
remove
1513
;
1614

17-
inherit (pkgs) runCommand writeText git;
15+
inherit (pkgs) runCommand git;
1816

1917
cfg = config;
2018
install_stages = lib.unique (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks));

0 commit comments

Comments
 (0)