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

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

74 lines
2.4 KiB
Nix
Raw Normal View History

2022-02-16 09:09:26 +01:00
{ lib
2022-06-16 00:24:21 +02:00
, stdenv
2022-02-16 09:09:26 +01:00
, buildGoModule
, fetchFromGitHub
, installShellFiles
}:
2021-01-06 19:11:00 +01:00
buildGoModule rec {
pname = "grype";
2022-07-13 21:59:48 +02:00
version = "0.42.0";
2021-01-06 19:11:00 +01:00
src = fetchFromGitHub {
owner = "anchore";
repo = pname;
rev = "v${version}";
2022-07-13 21:59:48 +02:00
hash = "sha256-MShlKtrorqXRInQ01dEzVeLDRDua9PISkficF02PrBI=";
# 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 19:53:00 +01: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 19:11:00 +01:00
};
2022-07-13 21:59:48 +02:00
vendorSha256 = "sha256-MusEvYNaMM0kqHSDdenPKo4IrIFmvPHSCRzciKMFiew=";
2022-02-16 09:09:26 +01:00
nativeBuildInputs = [
installShellFiles
];
2021-01-06 19:11:00 +01:00
2021-08-21 10:23:50 +02:00
ldflags = [
"-s"
"-w"
"-X github.com/anchore/grype/internal/version.version=${version}"
2022-03-17 19:53:00 +01:00
"-X github.com/anchore/grype/internal/version.gitDescription=v${version}"
"-X github.com/anchore/grype/internal/version.gitTreeState=clean"
2021-08-21 10:23:50 +02:00
];
2021-03-27 15:16:51 +01: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 19:53:00 +01: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)"
'';
2021-03-27 15:16:51 +01:00
# Tests require a running Docker instance
2021-01-06 19:11:00 +01:00
doCheck = false;
2022-01-10 17:49:31 +01: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 17:49:31 +01:00
homepage = "https://github.com/anchore/grype";
changelog = "https://github.com/anchore/grype/releases/tag/v${version}";
2021-01-06 19:11:00 +01:00
description = "Vulnerability scanner for container images and filesystems";
longDescription = ''
2022-01-10 17:49:31 +01: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 19:11:00 +01:00
'';
license = with licenses; [ asl20 ];
2022-01-10 17:49:31 +01:00
maintainers = with maintainers; [ fab jk ];
2021-01-06 19:11:00 +01:00
};
}