Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib 2, buildGoModule 3, fetchFromGitHub 4, installShellFiles 5, openssl 6}: 7 8buildGoModule rec { 9 pname = "grype"; 10 version = "0.62.2"; 11 12 src = fetchFromGitHub { 13 owner = "anchore"; 14 repo = pname; 15 rev = "refs/tags/v${version}"; 16 hash = "sha256-11uxu9oa0lSZH+zd+Uj2P9flw9wp9UD7bXKP4jxXDoE="; 17 # populate values that require us to use git. By doing this in postFetch we 18 # can delete .git afterwards and maintain better reproducibility of the src. 19 leaveDotGit = true; 20 postFetch = '' 21 cd "$out" 22 git rev-parse HEAD > $out/COMMIT 23 # 0000-00-00T00:00:00Z 24 date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH 25 find "$out" -name .git -print0 | xargs -0 rm -rf 26 ''; 27 }; 28 29 proxyVendor = true; 30 31 vendorHash = "sha256-n0daAFCP0KtS1mQGfq/EQv2m6c8jjdbFR6YWSeClHBg="; 32 33 nativeBuildInputs = [ 34 installShellFiles 35 ]; 36 37 nativeCheckInputs = [ 38 openssl 39 ]; 40 41 subPackages = [ "." ]; 42 43 excludedPackages = "test/integration"; 44 45 ldflags = [ 46 "-s" 47 "-w" 48 "-X github.com/anchore/grype/internal/version.version=${version}" 49 "-X github.com/anchore/grype/internal/version.gitDescription=v${version}" 50 "-X github.com/anchore/grype/internal/version.gitTreeState=clean" 51 ]; 52 53 preBuild = '' 54 # grype version also displays the version of the syft library used 55 # we need to grab it from the go.sum and add an ldflag for it 56 SYFT_VERSION="$(grep "github.com/anchore/syft" go.sum -m 1 | awk '{print $2}')" 57 ldflags+=" -X github.com/anchore/grype/internal/version.syftVersion=$SYFT_VERSION" 58 ldflags+=" -X github.com/anchore/grype/internal/version.gitCommit=$(cat COMMIT)" 59 ldflags+=" -X github.com/anchore/grype/internal/version.buildDate=$(cat SOURCE_DATE_EPOCH)" 60 ''; 61 62 preCheck = '' 63 # test all dirs (except excluded) 64 unset subPackages 65 # test goldenfiles expect no version 66 unset ldflags 67 68 # patch utility script 69 patchShebangs grype/db/test-fixtures/tls/generate-x509-cert-pair.sh 70 71 # remove tests that depend on docker 72 substituteInPlace test/cli/cmd_test.go \ 73 --replace "TestCmd" "SkipCmd" 74 substituteInPlace grype/pkg/provider_test.go \ 75 --replace "TestSyftLocationExcludes" "SkipSyftLocationExcludes" 76 # remove tests that depend on git 77 substituteInPlace test/cli/db_validations_test.go \ 78 --replace "TestDBValidations" "SkipDBValidations" 79 substituteInPlace test/cli/registry_auth_test.go \ 80 --replace "TestRegistryAuth" "SkipRegistryAuth" 81 substituteInPlace test/cli/sbom_input_test.go \ 82 --replace "TestSBOMInput_FromStdin" "SkipSBOMInput_FromStdin" \ 83 --replace "TestSBOMInput_AsArgument" "SkipSBOMInput_AsArgument" \ 84 --replace "TestAttestationInput_AsArgument" "SkipAttestationInput_AsArgument" 85 substituteInPlace test/cli/subprocess_test.go \ 86 --replace "TestSubprocessStdin" "SkipSubprocessStdin" 87 88 # segfault 89 rm grype/db/v5/namespace/cpe/namespace_test.go 90 ''; 91 92 postInstall = '' 93 installShellCompletion --cmd grype \ 94 --bash <($out/bin/grype completion bash) \ 95 --fish <($out/bin/grype completion fish) \ 96 --zsh <($out/bin/grype completion zsh) 97 ''; 98 99 meta = with lib; { 100 homepage = "https://github.com/anchore/grype"; 101 changelog = "https://github.com/anchore/grype/releases/tag/v${version}"; 102 description = "Vulnerability scanner for container images and filesystems"; 103 longDescription = '' 104 As a vulnerability scanner grype is able to scan the contents of a 105 container image or filesystem to find known vulnerabilities. 106 ''; 107 license = with licenses; [ asl20 ]; 108 maintainers = with maintainers; [ fab jk ]; 109 }; 110}