nixpkgs/pkgs/tools/security/grype/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.8 KiB
Nix
Raw Normal View History

2024-04-04 20:49:03 +00:00
{
lib,
buildGoModule,
fetchFromGitHub,
git,
installShellFiles,
openssl,
2022-02-16 08:09:26 +00:00
}:
2021-01-06 18:11:00 +00:00
buildGoModule rec {
pname = "grype";
2024-04-22 14:19:52 +00:00
version = "0.77.0";
2021-01-06 18:11:00 +00:00
src = fetchFromGitHub {
owner = "anchore";
repo = "grype";
2023-03-04 13:03:57 +00:00
rev = "refs/tags/v${version}";
2024-04-22 14:19:52 +00:00
hash = "sha256-EnAMAmoP8rbkOkdPPxkN14lOPVYPqVpmaekfXBboeyI=";
# populate values that require us to use git. By doing this in postFetch we
# can delete .git afterwards and maintain better reproducibility of the src.
leaveDotGit = true;
postFetch = ''
cd "$out"
2022-03-17 18:53:00 +00:00
git rev-parse HEAD > $out/COMMIT
# 0000-00-00T00:00:00Z
date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
2021-01-06 18:11:00 +00:00
};
2023-03-04 13:03:57 +00:00
2022-11-07 11:38:32 +00:00
proxyVendor = true;
2024-04-16 04:52:48 +00:00
vendorHash = "sha256-oJNTvbfVkz4fK+EsF2ZoFfBSlkt0pFT4r2QDyhZhv5Y=";
2022-02-16 08:09:26 +00:00
2024-04-04 20:49:03 +00:00
nativeBuildInputs = [ installShellFiles ];
2021-01-06 18:11:00 +00:00
2023-03-04 13:03:57 +00:00
nativeCheckInputs = [
git
2023-03-04 13:03:57 +00:00
openssl
];
2024-04-04 20:49:03 +00:00
subPackages = [ "cmd/grype" ];
2022-10-28 12:25:17 +00:00
excludedPackages = "test/integration";
2021-08-21 08:23:50 +00:00
ldflags = [
"-s"
"-w"
2023-09-14 13:26:40 +00:00
"-X=main.version=${version}"
"-X=main.gitDescription=v${version}"
"-X=main.gitTreeState=clean"
2021-08-21 08:23:50 +00:00
];
2021-03-27 14:16:51 +00:00
preBuild = ''
# grype version also displays the version of the syft library used
# we need to grab it from the go.sum and add an ldflag for it
2022-03-17 18:53:00 +00:00
SYFT_VERSION="$(grep "github.com/anchore/syft" go.sum -m 1 | awk '{print $2}')"
2023-09-14 13:26:40 +00:00
ldflags+=" -X main.syftVersion=$SYFT_VERSION"
ldflags+=" -X main.gitCommit=$(cat COMMIT)"
ldflags+=" -X main.buildDate=$(cat SOURCE_DATE_EPOCH)"
'';
2022-10-28 12:25:17 +00:00
preCheck = ''
# test all dirs (except excluded)
unset subPackages
# test goldenfiles expect no version
unset ldflags
# patch utility script
patchShebangs grype/db/test-fixtures/tls/generate-x509-cert-pair.sh
# remove tests that depend on docker
substituteInPlace test/cli/cmd_test.go \
--replace-fail "TestCmd" "SkipCmd"
2022-10-28 12:25:17 +00:00
substituteInPlace grype/pkg/provider_test.go \
--replace-fail "TestSyftLocationExcludes" "SkipSyftLocationExcludes"
2023-12-01 10:04:03 +00:00
substituteInPlace test/cli/cmd_test.go \
--replace-fail "Test_descriptorNameAndVersionSet" "Skip_descriptorNameAndVersionSet"
2022-10-28 12:25:17 +00:00
# remove tests that depend on git
substituteInPlace test/cli/db_validations_test.go \
--replace-fail "TestDBValidations" "SkipDBValidations"
2022-10-28 12:25:17 +00:00
substituteInPlace test/cli/registry_auth_test.go \
--replace-fail "TestRegistryAuth" "SkipRegistryAuth"
2022-10-28 12:25:17 +00:00
substituteInPlace test/cli/sbom_input_test.go \
--replace-fail "TestSBOMInput_FromStdin" "SkipSBOMInput_FromStdin" \
--replace-fail "TestSBOMInput_AsArgument" "SkipSBOMInput_AsArgument"
2022-10-28 12:25:17 +00:00
substituteInPlace test/cli/subprocess_test.go \
--replace-fail "TestSubprocessStdin" "SkipSubprocessStdin"
2023-12-01 10:04:03 +00:00
substituteInPlace grype/internal/packagemetadata/names_test.go \
--replace-fail "TestAllNames" "SkipAllNames"
substituteInPlace test/cli/version_cmd_test.go \
--replace-fail "TestVersionCmdPrintsToStdout" "SkipVersionCmdPrintsToStdout"
2022-10-28 12:25:17 +00:00
# segfault
rm grype/db/v5/namespace/cpe/namespace_test.go
'';
2021-01-06 18:11:00 +00:00
2022-01-10 16:49:31 +00:00
postInstall = ''
installShellCompletion --cmd grype \
--bash <($out/bin/grype completion bash) \
--fish <($out/bin/grype completion fish) \
--zsh <($out/bin/grype completion zsh)
'';
meta = with lib; {
2022-01-10 16:49:31 +00:00
homepage = "https://github.com/anchore/grype";
changelog = "https://github.com/anchore/grype/releases/tag/v${version}";
2021-01-06 18:11:00 +00:00
description = "Vulnerability scanner for container images and filesystems";
mainProgram = "grype";
2021-01-06 18:11:00 +00:00
longDescription = ''
2022-01-10 16:49:31 +00:00
As a vulnerability scanner grype is able to scan the contents of a
container image or filesystem to find known vulnerabilities.
2021-01-06 18:11:00 +00:00
'';
license = with licenses; [ asl20 ];
2024-04-04 20:49:03 +00:00
maintainers = with maintainers; [
fab
jk
kashw2
];
2021-01-06 18:11:00 +00:00
};
}