|
1 | 1 | { config, lib, pkgs, hookModule, ... }: |
2 | 2 | let |
3 | | - inherit (config) hooks tools settings; |
| 3 | + inherit (config) hooks tools; |
4 | 4 | cfg = config; |
5 | 5 | inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types; |
6 | 6 |
|
7 | | - cargoManifestPathArg = |
8 | | - lib.optionalString |
9 | | - (settings.rust.cargoManifestPath != null) |
10 | | - "--manifest-path ${lib.escapeShellArg settings.rust.cargoManifestPath}"; |
11 | | - |
12 | 7 | mkCmdArgs = predActionList: |
13 | 8 | lib.concatStringsSep |
14 | 9 | " " |
|
76 | 71 |
|
77 | 72 | # PLEASE keep this sorted alphabetically. |
78 | 73 | options.hooks = |
79 | | - { |
| 74 | + import ./rust/options.nix { inherit config lib hookModule; } |
| 75 | + // { |
80 | 76 | alejandra = mkOption { |
81 | 77 | description = "alejandra hook"; |
82 | 78 | type = types.submodule { |
|
201 | 197 | }; |
202 | 198 | }; |
203 | 199 | }; |
204 | | - clippy = mkOption { |
205 | | - description = "clippy hook"; |
206 | | - type = types.submodule |
207 | | - ({ config, ... }: { |
208 | | - imports = [ hookModule ]; |
209 | | - options.packageOverrides = { |
210 | | - cargo = mkOption { |
211 | | - type = types.package; |
212 | | - description = "The cargo package to use"; |
213 | | - }; |
214 | | - clippy = mkOption { |
215 | | - type = types.package; |
216 | | - description = "The clippy package to use"; |
217 | | - }; |
218 | | - }; |
219 | | - options.settings = { |
220 | | - denyWarnings = mkOption { |
221 | | - type = types.bool; |
222 | | - description = "Fail when warnings are present"; |
223 | | - default = false; |
224 | | - }; |
225 | | - offline = mkOption { |
226 | | - type = types.bool; |
227 | | - description = "Run clippy offline"; |
228 | | - default = true; |
229 | | - }; |
230 | | - allFeatures = mkOption { |
231 | | - type = types.bool; |
232 | | - description = "Run clippy with --all-features"; |
233 | | - default = false; |
234 | | - }; |
235 | | - extraArgs = mkOption { |
236 | | - type = types.str; |
237 | | - description = "Additional arguments to pass to clippy"; |
238 | | - default = ""; |
239 | | - }; |
240 | | - }; |
241 | | - |
242 | | - config.extraPackages = [ |
243 | | - config.packageOverrides.cargo |
244 | | - config.packageOverrides.clippy |
245 | | - ]; |
246 | | - }); |
247 | | - }; |
248 | 200 | cmake-format = mkOption { |
249 | 201 | description = "cmake-format hook"; |
250 | 202 | type = types.submodule { |
@@ -1372,37 +1324,6 @@ in |
1372 | 1324 | }; |
1373 | 1325 | }; |
1374 | 1326 | }; |
1375 | | - rustfmt = mkOption { |
1376 | | - description = '' |
1377 | | - Additional rustfmt settings |
1378 | | -
|
1379 | | - Override the `rustfmt` and `cargo` packages by setting `hooks.rustfmt.packageOverrides`. |
1380 | | -
|
1381 | | - ``` |
1382 | | - hooks.rustfmt.packageOverrides.cargo = pkgs.cargo; |
1383 | | - hooks.rustfmt.packageOverrides.rustfmt = pkgs.rustfmt; |
1384 | | - ``` |
1385 | | - ''; |
1386 | | - type = types.submodule |
1387 | | - ({ config, ... }: { |
1388 | | - imports = [ hookModule ]; |
1389 | | - options.packageOverrides = { |
1390 | | - cargo = mkOption { |
1391 | | - type = types.package; |
1392 | | - description = "The cargo package to use."; |
1393 | | - }; |
1394 | | - rustfmt = mkOption { |
1395 | | - type = types.package; |
1396 | | - description = "The rustfmt package to use."; |
1397 | | - }; |
1398 | | - }; |
1399 | | - |
1400 | | - config.extraPackages = [ |
1401 | | - config.packageOverrides.cargo |
1402 | | - config.packageOverrides.rustfmt |
1403 | | - ]; |
1404 | | - }); |
1405 | | - }; |
1406 | 1327 | shfmt = mkOption { |
1407 | 1328 | description = "shfmt hook"; |
1408 | 1329 | type = types.submodule { |
@@ -1738,8 +1659,10 @@ in |
1738 | 1659 | }; |
1739 | 1660 | }; |
1740 | 1661 |
|
| 1662 | + config.assertions = import ./rust/assertions.nix { inherit config lib; }; |
1741 | 1663 | config.warnings = |
1742 | | - lib.optional cfg.hooks.rome.enable '' |
| 1664 | + import ./rust/warnings.nix { inherit config lib; } |
| 1665 | + ++ lib.optional cfg.hooks.rome.enable '' |
1743 | 1666 | The hook `hooks.rome` has been renamed to `hooks.biome`. |
1744 | 1667 | '' |
1745 | 1668 | ++ lib.optional cfg.hooks.nixfmt.enable '' |
|
1749 | 1672 | ''; |
1750 | 1673 |
|
1751 | 1674 | # PLEASE keep this sorted alphabetically. |
1752 | | - config.hooks = mapAttrs (_: mapAttrs (_: mkDefault)) |
1753 | | - rec { |
| 1675 | + config.hooks = mapAttrs (_: mapAttrs (_: mkDefault)) ( |
| 1676 | + import ./rust/config.nix { inherit config lib pkgs; } |
| 1677 | + // rec { |
1754 | 1678 | actionlint = |
1755 | 1679 | { |
1756 | 1680 | name = "actionlint"; |
@@ -1889,15 +1813,6 @@ in |
1889 | 1813 | entry = "${hooks.cabal2nix.package}/bin/cabal2nix-dir"; |
1890 | 1814 | files = "\\.cabal$"; |
1891 | 1815 | }; |
1892 | | - cargo-check = |
1893 | | - { |
1894 | | - name = "cargo-check"; |
1895 | | - description = "Check the cargo package for errors"; |
1896 | | - package = tools.cargo; |
1897 | | - entry = "${hooks.cargo-check.package}/bin/cargo check ${cargoManifestPathArg}"; |
1898 | | - files = "\\.rs$"; |
1899 | | - pass_filenames = false; |
1900 | | - }; |
1901 | 1816 | checkmake = { |
1902 | 1817 | name = "checkmake"; |
1903 | 1818 | description = "Experimental linter/analyzer for Makefiles"; |
@@ -2060,28 +1975,6 @@ in |
2060 | 1975 | entry = "${hooks.clang-tidy.package}/bin/clang-tidy --fix"; |
2061 | 1976 | types_or = [ "c" "c++" "c#" "objective-c" ]; |
2062 | 1977 | }; |
2063 | | - clippy = |
2064 | | - let |
2065 | | - inherit (hooks.clippy) packageOverrides; |
2066 | | - wrapper = pkgs.symlinkJoin { |
2067 | | - name = "clippy-wrapped"; |
2068 | | - paths = [ packageOverrides.clippy ]; |
2069 | | - nativeBuildInputs = [ pkgs.makeWrapper ]; |
2070 | | - postBuild = '' |
2071 | | - wrapProgram $out/bin/cargo-clippy \ |
2072 | | - --prefix PATH : ${lib.makeBinPath [ packageOverrides.cargo ]} |
2073 | | - ''; |
2074 | | - }; |
2075 | | - in |
2076 | | - { |
2077 | | - name = "clippy"; |
2078 | | - description = "Lint Rust code."; |
2079 | | - package = wrapper; |
2080 | | - packageOverrides = { cargo = tools.cargo; clippy = tools.clippy; }; |
2081 | | - entry = "${hooks.clippy.package}/bin/cargo-clippy clippy ${cargoManifestPathArg} ${lib.optionalString hooks.clippy.settings.offline "--offline"} ${lib.optionalString hooks.clippy.settings.allFeatures "--all-features"} ${hooks.clippy.settings.extraArgs} -- ${lib.optionalString hooks.clippy.settings.denyWarnings "-D warnings"}"; |
2082 | | - files = "\\.rs$"; |
2083 | | - pass_filenames = false; |
2084 | | - }; |
2085 | 1978 | cljfmt = |
2086 | 1979 | { |
2087 | 1980 | name = "cljfmt"; |
@@ -3259,28 +3152,6 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol |
3259 | 3152 | entry = "${hooks.ruff.package}/bin/ruff format"; |
3260 | 3153 | types = [ "python" ]; |
3261 | 3154 | }; |
3262 | | - rustfmt = |
3263 | | - let |
3264 | | - inherit (hooks.rustfmt) packageOverrides; |
3265 | | - wrapper = pkgs.symlinkJoin { |
3266 | | - name = "rustfmt-wrapped"; |
3267 | | - paths = [ packageOverrides.rustfmt ]; |
3268 | | - nativeBuildInputs = [ pkgs.makeWrapper ]; |
3269 | | - postBuild = '' |
3270 | | - wrapProgram $out/bin/cargo-fmt \ |
3271 | | - --prefix PATH : ${lib.makeBinPath [ packageOverrides.cargo packageOverrides.rustfmt ]} |
3272 | | - ''; |
3273 | | - }; |
3274 | | - in |
3275 | | - { |
3276 | | - name = "rustfmt"; |
3277 | | - description = "Format Rust code."; |
3278 | | - package = wrapper; |
3279 | | - packageOverrides = { cargo = tools.cargo; rustfmt = tools.rustfmt; }; |
3280 | | - entry = "${hooks.rustfmt.package}/bin/cargo-fmt fmt ${cargoManifestPathArg} --all -- --color always"; |
3281 | | - files = "\\.rs$"; |
3282 | | - pass_filenames = false; |
3283 | | - }; |
3284 | 3155 | shellcheck = |
3285 | 3156 | { |
3286 | 3157 | name = "shellcheck"; |
@@ -3640,5 +3511,6 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol |
3640 | 3511 | types_or = [ "clojure" "clojurescript" "edn" ]; |
3641 | 3512 | }; |
3642 | 3513 |
|
3643 | | - }; |
| 3514 | + } |
| 3515 | + ); |
3644 | 3516 | } |
0 commit comments