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