2022-02-20 05:27:41 +00:00
|
|
|
{ lib
|
|
|
|
, buildGoModule
|
|
|
|
, fetchFromGitHub
|
|
|
|
, installShellFiles
|
2022-10-30 15:09:59 +00:00
|
|
|
, openssl
|
2022-02-20 05:27:41 +00:00
|
|
|
}:
|
2021-01-09 10:05:03 +00:00
|
|
|
|
|
|
|
buildGoModule rec {
|
|
|
|
pname = "grype";
|
2023-04-12 12:48:02 +00:00
|
|
|
version = "0.61.0";
|
2021-01-09 10:05:03 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "anchore";
|
|
|
|
repo = pname;
|
2023-03-08 16:32:21 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-04-12 12:48:02 +00:00
|
|
|
hash = "sha256-PPCeEhV4+iSGDBUIN89wlEUEX20bkcX3B7LxU7JDZQc=";
|
2022-01-25 03:21:06 +00:00
|
|
|
# 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-30 09:31:56 +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
|
2022-01-25 03:21:06 +00:00
|
|
|
find "$out" -name .git -print0 | xargs -0 rm -rf
|
|
|
|
'';
|
2021-01-09 10:05:03 +00:00
|
|
|
};
|
2023-03-08 16:32:21 +00:00
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
proxyVendor = true;
|
2022-11-27 09:42:12 +00:00
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
vendorHash = "sha256-L77tzgcshTNAvg6fKkgN6zdDws76wWoJvygAdArscVI=";
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
installShellFiles
|
|
|
|
];
|
2021-01-09 10:05:03 +00:00
|
|
|
|
2023-03-08 16:32:21 +00:00
|
|
|
nativeCheckInputs = [
|
|
|
|
openssl
|
|
|
|
];
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
subPackages = [ "." ];
|
2022-11-27 09:42:12 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
excludedPackages = "test/integration";
|
|
|
|
|
2021-08-22 07:53:02 +00:00
|
|
|
ldflags = [
|
2022-01-25 03:21:06 +00:00
|
|
|
"-s"
|
|
|
|
"-w"
|
|
|
|
"-X github.com/anchore/grype/internal/version.version=${version}"
|
2022-03-30 09:31:56 +00:00
|
|
|
"-X github.com/anchore/grype/internal/version.gitDescription=v${version}"
|
2022-01-25 03:21:06 +00:00
|
|
|
"-X github.com/anchore/grype/internal/version.gitTreeState=clean"
|
2021-08-22 07:53:02 +00:00
|
|
|
];
|
2021-03-20 04:20:00 +00:00
|
|
|
|
2022-01-25 03:21:06 +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-30 09:31:56 +00:00
|
|
|
SYFT_VERSION="$(grep "github.com/anchore/syft" go.sum -m 1 | awk '{print $2}')"
|
|
|
|
ldflags+=" -X github.com/anchore/grype/internal/version.syftVersion=$SYFT_VERSION"
|
|
|
|
ldflags+=" -X github.com/anchore/grype/internal/version.gitCommit=$(cat COMMIT)"
|
|
|
|
ldflags+=" -X github.com/anchore/grype/internal/version.buildDate=$(cat SOURCE_DATE_EPOCH)"
|
2022-01-25 03:21:06 +00:00
|
|
|
'';
|
|
|
|
|
2022-10-30 15:09:59 +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 "TestCmd" "SkipCmd"
|
|
|
|
substituteInPlace grype/pkg/provider_test.go \
|
|
|
|
--replace "TestSyftLocationExcludes" "SkipSyftLocationExcludes"
|
|
|
|
# remove tests that depend on git
|
|
|
|
substituteInPlace test/cli/db_validations_test.go \
|
|
|
|
--replace "TestDBValidations" "SkipDBValidations"
|
|
|
|
substituteInPlace test/cli/registry_auth_test.go \
|
|
|
|
--replace "TestRegistryAuth" "SkipRegistryAuth"
|
|
|
|
substituteInPlace test/cli/sbom_input_test.go \
|
|
|
|
--replace "TestSBOMInput_FromStdin" "SkipSBOMInput_FromStdin" \
|
|
|
|
--replace "TestSBOMInput_AsArgument" "SkipSBOMInput_AsArgument" \
|
|
|
|
--replace "TestAttestationInput_AsArgument" "SkipAttestationInput_AsArgument"
|
|
|
|
substituteInPlace test/cli/subprocess_test.go \
|
|
|
|
--replace "TestSubprocessStdin" "SkipSubprocessStdin"
|
|
|
|
|
|
|
|
# segfault
|
|
|
|
rm grype/db/v5/namespace/cpe/namespace_test.go
|
|
|
|
'';
|
2021-01-09 10:05:03 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
postInstall = ''
|
|
|
|
installShellCompletion --cmd grype \
|
|
|
|
--bash <($out/bin/grype completion bash) \
|
|
|
|
--fish <($out/bin/grype completion fish) \
|
|
|
|
--zsh <($out/bin/grype completion zsh)
|
|
|
|
'';
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2022-01-13 20:06:32 +00:00
|
|
|
homepage = "https://github.com/anchore/grype";
|
|
|
|
changelog = "https://github.com/anchore/grype/releases/tag/v${version}";
|
2021-01-09 10:05:03 +00:00
|
|
|
description = "Vulnerability scanner for container images and filesystems";
|
|
|
|
longDescription = ''
|
2022-01-13 20:06:32 +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-09 10:05:03 +00:00
|
|
|
'';
|
|
|
|
license = with licenses; [ asl20 ];
|
2022-01-13 20:06:32 +00:00
|
|
|
maintainers = with maintainers; [ fab jk ];
|
2021-01-09 10:05:03 +00:00
|
|
|
};
|
|
|
|
}
|