Made with
```shell
git restore .
fd '\.nix$' pkgs/ --type f -j1 -x bash -xc "$(cat <<"EOF"
typos --no-check-filenames --write-changes "$1"
git diff --exit-code "$1" && exit
#( git diff "$1" | grep -qE "^\+ +[^# ]") && git restore "$1"
count1="$( bat --language nix --diff --style changes "$1" --theme "Monokai Extended" --color always | aha --no-header | grep -E '^<span style="color:olive;">~</span> ' | wc -l )"
count2="$( bat --language nix --diff --style changes "$1" --theme "Monokai Extended" --color always | aha --no-header | grep -E '^<span style="color:olive;">~</span> (<span style="color:#f8f8f2;"> *</span>)?<span style="color:#75715e;">.*</span>$' | wc -l )"
[[ $count1 -ne $count2 ]] && git restore "$1"
EOF
)" -- {}
```
and filtered with `GIT_DIFF_OPTS='--unified=15' git -c interactive.singleKey=true add --patch`
I initially tried using the tree-sitter cli, python bindings and even ast-grep through various means, but this is what I ended up with.
105 lines
3.0 KiB
Nix
105 lines
3.0 KiB
Nix
{
|
|
rustPlatform,
|
|
stdenv,
|
|
cargo,
|
|
}:
|
|
{
|
|
/*
|
|
test each hook individually, to make sure that:
|
|
- each hook works properly outside of buildRustPackage
|
|
- each hook is usable independently from each other
|
|
*/
|
|
cargoSetupHook = stdenv.mkDerivation {
|
|
name = "test-cargoSetupHook";
|
|
src = ./example-rust-project;
|
|
cargoVendorDir = "hello";
|
|
nativeBuildInputs = [
|
|
rustPlatform.cargoSetupHook
|
|
cargo
|
|
];
|
|
buildPhase = ''
|
|
cargo build --profile release --target ${stdenv.hostPlatform.rust.rustcTarget}
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/hello $out/bin/
|
|
'';
|
|
};
|
|
|
|
cargoBuildHook = stdenv.mkDerivation {
|
|
name = "test-cargoBuildHook";
|
|
src = ./example-rust-project;
|
|
cargoBuildType = "release";
|
|
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
|
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
nativeBuildInputs = [
|
|
rustPlatform.cargoBuildHook
|
|
cargo
|
|
];
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/hello $out/bin/
|
|
'';
|
|
};
|
|
|
|
cargoInstallHook = stdenv.mkDerivation {
|
|
name = "test-cargoInstallHook";
|
|
src = ./example-rust-project;
|
|
cargoBuildType = "release";
|
|
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
|
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
nativeBuildInputs = [
|
|
rustPlatform.cargoInstallHook
|
|
cargo
|
|
];
|
|
buildPhase = ''
|
|
cargo build --profile release --target ${stdenv.hostPlatform.rust.rustcTarget}
|
|
runHook postBuild
|
|
'';
|
|
};
|
|
|
|
cargoCheckHook = stdenv.mkDerivation {
|
|
name = "test-cargoCheckHook";
|
|
src = ./example-rust-project;
|
|
cargoBuildType = "release";
|
|
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
|
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
nativeBuildInputs = [
|
|
rustPlatform.cargoCheckHook
|
|
cargo
|
|
];
|
|
buildPhase = ''
|
|
cargo build --profile release --target ${stdenv.hostPlatform.rust.rustcTarget}
|
|
runHook postBuild
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/hello $out/bin/
|
|
'';
|
|
cargoCheckType = "release";
|
|
doCheck = true;
|
|
};
|
|
|
|
cargoNextestHook = stdenv.mkDerivation {
|
|
name = "test-cargoNextestHook";
|
|
src = ./example-rust-project;
|
|
cargoBuildType = "release";
|
|
"CARGO_TARGET_${stdenv.hostPlatform.rust.cargoEnvVarTarget}_LINKER" =
|
|
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
|
|
nativeBuildInputs = [
|
|
rustPlatform.cargoNextestHook
|
|
cargo
|
|
];
|
|
buildPhase = ''
|
|
cargo build --profile release --target ${stdenv.hostPlatform.rust.rustcTarget}
|
|
runHook postBuild
|
|
'';
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/hello $out/bin/
|
|
'';
|
|
cargoCheckType = "release";
|
|
doCheck = true;
|
|
};
|
|
}
|