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