2022-02-20 05:27:41 +00:00
|
|
|
{ lib
|
|
|
|
, buildGoModule
|
|
|
|
, fetchFromGitHub
|
|
|
|
, installShellFiles
|
|
|
|
}:
|
2021-01-09 10:05:03 +00:00
|
|
|
|
|
|
|
buildGoModule rec {
|
|
|
|
pname = "grype";
|
2022-03-05 16:20:37 +00:00
|
|
|
version = "0.33.1";
|
2021-01-09 10:05:03 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "anchore";
|
|
|
|
repo = pname;
|
|
|
|
rev = "v${version}";
|
2022-03-05 16:20:37 +00:00
|
|
|
sha256 = "sha256-5QjyGIpxnrwTnEmi0D16vPKodg3+SKiINFONwU2OzC0=";
|
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"
|
|
|
|
commit="$(git rev-parse HEAD)"
|
|
|
|
source_date_epoch=$(git log --date=format:'%Y-%m-%dT%H:%M:%SZ' -1 --pretty=%ad)
|
|
|
|
substituteInPlace "$out/internal/version/build.go" \
|
|
|
|
--replace 'gitCommit = valueNotProvided' "gitCommit = \"$commit\"" \
|
|
|
|
--replace 'buildDate = valueNotProvided' "buildDate = \"$source_date_epoch\""
|
|
|
|
find "$out" -name .git -print0 | xargs -0 rm -rf
|
|
|
|
'';
|
2021-01-09 10:05:03 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
vendorSha256 = "sha256-CPMfQv9oiLbIMkZe/t482LzssoNTcNVJdr2o2wJecSA=";
|
2022-02-20 05:27:41 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
installShellFiles
|
|
|
|
];
|
2021-01-09 10:05:03 +00:00
|
|
|
|
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}"
|
|
|
|
"-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
|
|
|
|
SYFTVERSION="$(grep "github.com/anchore/syft" go.sum -m 1 | awk '{print $2}')"
|
|
|
|
ldflags+=" -X github.com/anchore/grype/internal/version.syftVersion=$SYFTVERSION"
|
|
|
|
'';
|
|
|
|
|
2021-03-20 04:20:00 +00:00
|
|
|
# Tests require a running Docker instance
|
2021-01-09 10:05:03 +00:00
|
|
|
doCheck = false;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|