nixpkgs/pkgs/tools/admin/syft/default.nix

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

79 lines
2.5 KiB
Nix
Raw Normal View History

2022-05-21 13:57:12 +02:00
{ lib, stdenv, buildGoModule, fetchFromGitHub, installShellFiles }:
2022-01-21 13:59:17 +01:00
buildGoModule rec {
pname = "syft";
2022-09-22 07:04:36 +02:00
version = "0.57.0";
2022-01-21 13:59:17 +01:00
src = fetchFromGitHub {
owner = "anchore";
repo = pname;
rev = "v${version}";
2022-09-22 07:04:36 +02:00
sha256 = "sha256-7O1QDGerDbVYoN+sKq6wmoD9waXgiIWFy6nCLrfZZkI=";
2022-01-21 13:59:17 +01: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-17 19:30:37 +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
2022-01-21 13:59:17 +01:00
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
};
2022-09-22 07:04:36 +02:00
vendorSha256 = "sha256-DzAdY0HlSjBsTYpi+FDwMMKOmOQy0yx+lep6f1MPuXA=";
2022-01-21 13:59:17 +01:00
nativeBuildInputs = [ installShellFiles ];
2022-05-17 10:23:21 +02:00
subPackages = [ "cmd/syft" ];
2022-01-21 13:59:17 +01:00
ldflags = [
"-s"
"-w"
"-X github.com/anchore/syft/internal/version.version=${version}"
2022-02-08 16:38:24 +01:00
"-X github.com/anchore/syft/internal/version.gitDescription=v${version}"
2022-03-17 19:30:37 +01:00
"-X github.com/anchore/syft/internal/version.gitTreeState=clean"
2022-01-21 13:59:17 +01:00
];
2022-03-17 19:30:37 +01:00
preBuild = ''
ldflags+=" -X github.com/anchore/syft/internal/version.gitCommit=$(cat COMMIT)"
ldflags+=" -X github.com/anchore/syft/internal/version.buildDate=$(cat SOURCE_DATE_EPOCH)"
'';
2022-01-21 13:59:17 +01:00
# tests require a running docker instance
doCheck = false;
postInstall = ''
# avoid update checks when generating completions
export SYFT_CHECK_FOR_APP_UPDATE=false
installShellCompletion --cmd syft \
--bash <($out/bin/syft completion bash) \
--fish <($out/bin/syft completion fish) \
--zsh <($out/bin/syft completion zsh)
'';
2022-05-17 10:23:21 +02:00
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
export SYFT_CHECK_FOR_APP_UPDATE=false
$out/bin/syft --help
$out/bin/syft version | grep "${version}"
runHook postInstallCheck
'';
2022-01-21 13:59:17 +01:00
meta = with lib; {
homepage = "https://github.com/anchore/syft";
changelog = "https://github.com/anchore/syft/releases/tag/v${version}";
description = "CLI tool and library for generating a Software Bill of Materials from container images and filesystems";
longDescription = ''
A CLI tool and Go library for generating a Software Bill of Materials
(SBOM) from container images and filesystems. Exceptional for
vulnerability detection when used with a scanner tool like Grype.
'';
license = with licenses; [ asl20 ];
maintainers = with maintainers; [ jk ];
};
}