add go-raceless

This commit is contained in:
2025-10-28 11:25:08 +00:00
parent 08ea34ecd6
commit 9fe0bbaefe
5 changed files with 87 additions and 12 deletions

View File

@@ -0,0 +1,58 @@
{ pkgs, go }:
let
go-wrapper = pkgs.writeShellApplication {
name = "go";
text = ''
args=("$@")
new_args=()
has_test=false
found_race=false
for arg in "''${args[@]}"; do
if [[ "$arg" == "test" ]]; then
has_test=true
fi
done
if [[ "$has_test" == "true" ]]; then
for arg in "''${args[@]}"; do
if [[ "$arg" != "-race" ]]; then
new_args+=("$arg")
else
found_race=true
fi
done
if [[ "$found_race" == "true" ]]; then
exec "$REAL_GO" "''${new_args[@]}"
fi
fi
exec "$REAL_GO" "$@"
'';
};
preservedAttrs = pkgs.lib.attrsets.getAttrs [
"CGO_ENABLED"
"GOARCH"
"GOOS"
"meta"
] go;
in
pkgs.symlinkJoin (
{
name = "go-raceless";
paths = [ go ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
rm $out/bin/go
makeWrapper ${go-wrapper}/bin/go $out/bin/go \
--set REAL_GO ${go}/bin/go
'';
}
// preservedAttrs
// {
passthru = go.passthru or { };
}
)