|
13 | 13 | ;
|
14 | 14 |
|
15 | 15 | inherit (pkgs) runCommand git;
|
| 16 | + inherit (pkgs.rustPlatform) cargoSetupHook; |
| 17 | + inherit (pkgs.stdenv) mkDerivation; |
16 | 18 |
|
17 | 19 | cfg = config;
|
18 | 20 | install_stages = lib.unique (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks));
|
|
26 | 28 | if excludes == [ ] then "^$" else "(${concatStringsSep "|" excludes})";
|
27 | 29 |
|
28 | 30 | enabledHooks = filterAttrs (id: value: value.enable) cfg.hooks;
|
| 31 | + enabledExtraPackages = builtins.concatLists (mapAttrsToList (_: value: value.extraPackages) enabledHooks); |
29 | 32 | processedHooks =
|
30 | 33 | mapAttrsToList (id: value: value.raw // { inherit id; }) enabledHooks;
|
31 | 34 |
|
|
51 | 54 | );
|
52 | 55 |
|
53 | 56 | run =
|
54 |
| - runCommand "pre-commit-run" { buildInputs = [ git ]; } '' |
55 |
| - set +e |
56 |
| - HOME=$PWD |
57 |
| - # Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to |
58 |
| - # preserve the executable bit at the same time |
59 |
| - cp -R ${cfg.rootSrc} src |
60 |
| - chmod -R +w src |
61 |
| - ln -fs ${configFile} src/.pre-commit-config.yaml |
62 |
| - cd src |
63 |
| - rm -rf .git |
64 |
| - git init -q |
65 |
| - git add . |
66 |
| - git config --global user.email "[email protected]" |
67 |
| - git config --global user.name "Your Name" |
68 |
| - git commit -m "init" -q |
69 |
| - if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]] |
70 |
| - then |
71 |
| - echo "Running: $ pre-commit run --hook-stage manual --all-files" |
72 |
| - ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files |
73 |
| - else |
74 |
| - echo "Running: $ pre-commit run --all-files" |
75 |
| - ${cfg.package}/bin/pre-commit run --all-files |
76 |
| - fi |
77 |
| - exitcode=$? |
78 |
| - git --no-pager diff --color |
79 |
| - mkdir $out |
80 |
| - [ $? -eq 0 ] && exit $exitcode |
81 |
| - ''; |
| 57 | + mkDerivation { |
| 58 | + name = "pre-commit-run"; |
| 59 | + |
| 60 | + src = cfg.rootSrc; |
| 61 | + buildInputs = [ git ]; |
| 62 | + nativeBuildInputs = enabledExtraPackages |
| 63 | + ++ lib.optional (config.settings.rust.check.cargoDeps != null) cargoSetupHook; |
| 64 | + cargoDeps = config.settings.rust.check.cargoDeps; |
| 65 | + buildPhase = '' |
| 66 | + set +e |
| 67 | + HOME=$PWD |
| 68 | + ln -fs ${configFile} .pre-commit-config.yaml |
| 69 | + git init -q |
| 70 | + git add . |
| 71 | + git config --global user.email "[email protected]" |
| 72 | + git config --global user.name "Your Name" |
| 73 | + git commit -m "init" -q |
| 74 | + if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]] |
| 75 | + then |
| 76 | + echo "Running: $ pre-commit run --hook-stage manual --all-files" |
| 77 | + ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files |
| 78 | + else |
| 79 | + echo "Running: $ pre-commit run --all-files" |
| 80 | + ${cfg.package}/bin/pre-commit run --all-files |
| 81 | + fi |
| 82 | + exitcode=$? |
| 83 | + git --no-pager diff --color |
| 84 | + mkdir $out |
| 85 | + [ $? -eq 0 ] && exit $exitcode |
| 86 | + ''; |
| 87 | + }; |
82 | 88 |
|
83 | 89 | failedAssertions = builtins.map (x: x.message) (builtins.filter (x: !x.assertion) config.assertions);
|
84 | 90 |
|
|
0 commit comments