From a60064f08789f5f557ca79f6078687db0ed23a8f Mon Sep 17 00:00:00 2001 From: kashw2 Date: Sat, 27 Apr 2024 15:17:51 +1000 Subject: grype: migrate to `by-name` overlay --- pkgs/by-name/gr/grype/package.nix | 121 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 pkgs/by-name/gr/grype/package.nix (limited to 'pkgs/by-name/gr') diff --git a/pkgs/by-name/gr/grype/package.nix b/pkgs/by-name/gr/grype/package.nix new file mode 100644 index 0000000000000..645c9cadb4fce --- /dev/null +++ b/pkgs/by-name/gr/grype/package.nix @@ -0,0 +1,121 @@ +{ + lib, + buildGoModule, + fetchFromGitHub, + git, + installShellFiles, + openssl, +}: + +buildGoModule rec { + pname = "grype"; + version = "0.77.1"; + + src = fetchFromGitHub { + owner = "anchore"; + repo = "grype"; + rev = "refs/tags/v${version}"; + hash = "sha256-Qfoo05MicnQ1shbEV/Rrz9TDrMBDvWBr0U/ZqnlnLTI="; + # 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" + 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 + ''; + }; + + proxyVendor = true; + + vendorHash = "sha256-lAq1PRElWR0F+OfuSBpR/gnFOptFH33ObR8yd1k7oMk="; + + nativeBuildInputs = [ installShellFiles ]; + + nativeCheckInputs = [ + git + openssl + ]; + + subPackages = [ "cmd/grype" ]; + + excludedPackages = "test/integration"; + + ldflags = [ + "-s" + "-w" + "-X=main.version=${version}" + "-X=main.gitDescription=v${version}" + "-X=main.gitTreeState=clean" + ]; + + 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 + SYFT_VERSION="$(grep "github.com/anchore/syft" go.sum -m 1 | awk '{print $2}')" + ldflags+=" -X main.syftVersion=$SYFT_VERSION" + ldflags+=" -X main.gitCommit=$(cat COMMIT)" + ldflags+=" -X main.buildDate=$(cat SOURCE_DATE_EPOCH)" + ''; + + 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" + substituteInPlace grype/pkg/provider_test.go \ + --replace-fail "TestSyftLocationExcludes" "SkipSyftLocationExcludes" + substituteInPlace test/cli/cmd_test.go \ + --replace-fail "Test_descriptorNameAndVersionSet" "Skip_descriptorNameAndVersionSet" + # remove tests that depend on git + substituteInPlace test/cli/db_validations_test.go \ + --replace-fail "TestDBValidations" "SkipDBValidations" + substituteInPlace test/cli/registry_auth_test.go \ + --replace-fail "TestRegistryAuth" "SkipRegistryAuth" + substituteInPlace test/cli/sbom_input_test.go \ + --replace-fail "TestSBOMInput_FromStdin" "SkipSBOMInput_FromStdin" \ + --replace-fail "TestSBOMInput_AsArgument" "SkipSBOMInput_AsArgument" + substituteInPlace test/cli/subprocess_test.go \ + --replace-fail "TestSubprocessStdin" "SkipSubprocessStdin" + substituteInPlace grype/internal/packagemetadata/names_test.go \ + --replace-fail "TestAllNames" "SkipAllNames" + substituteInPlace test/cli/version_cmd_test.go \ + --replace-fail "TestVersionCmdPrintsToStdout" "SkipVersionCmdPrintsToStdout" + + # segfault + rm grype/db/v5/namespace/cpe/namespace_test.go + ''; + + 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; { + homepage = "https://github.com/anchore/grype"; + changelog = "https://github.com/anchore/grype/releases/tag/v${version}"; + description = "Vulnerability scanner for container images and filesystems"; + mainProgram = "grype"; + longDescription = '' + As a vulnerability scanner grype is able to scan the contents of a + container image or filesystem to find known vulnerabilities. + ''; + license = with licenses; [ asl20 ]; + maintainers = with maintainers; [ + fab + jk + kashw2 + ]; + }; +} -- cgit 1.4.1