|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + buildGoModule, |
| 5 | + fetchFromGitHub, |
| 6 | + installShellFiles, |
| 7 | + |
| 8 | + enableWasmEval ? false, |
| 9 | +}: |
| 10 | + |
| 11 | +assert |
| 12 | + enableWasmEval && stdenv.hostPlatform.isDarwin |
| 13 | + -> builtins.throw "building with wasm on darwin is failing in nixpkgs"; |
| 14 | + |
| 15 | +buildGoModule rec { |
| 16 | + pname = "opa-envoy-plugin"; |
| 17 | + version = "1.1.0-envoy-1"; |
| 18 | + |
| 19 | + src = fetchFromGitHub { |
| 20 | + owner = "open-policy-agent"; |
| 21 | + repo = "opa-envoy-plugin"; |
| 22 | + tag = "v${version}"; |
| 23 | + hash = "sha256-IGB3m3xXZnDs8Vb38MYnS01yt/Nk3jHiPn+QjrPIfuQ="; |
| 24 | + }; |
| 25 | + |
| 26 | + vendorHash = null; |
| 27 | + |
| 28 | + nativeBuildInputs = [ installShellFiles ]; |
| 29 | + |
| 30 | + subPackages = [ "./cmd/opa-envoy-plugin" ]; |
| 31 | + |
| 32 | + ldflags = [ |
| 33 | + "-s" |
| 34 | + "-w" |
| 35 | + "-X github.com/open-policy-agent/opa/v1/version.Version=${version}" |
| 36 | + ]; |
| 37 | + |
| 38 | + tags = lib.optional enableWasmEval ( |
| 39 | + builtins.trace ( |
| 40 | + "Warning: enableWasmEval breaks reproducability, " |
| 41 | + + "ensure you need wasm evaluation. " |
| 42 | + + "`opa build` does not need this feature." |
| 43 | + ) "opa_wasm" |
| 44 | + ); |
| 45 | + |
| 46 | + checkPhase = '' |
| 47 | + go test -v $(go list ./.../ | grep -v 'vendor') |
| 48 | + ''; |
| 49 | + |
| 50 | + doInstallCheck = true; |
| 51 | + installCheckPhase = '' |
| 52 | + runHook preInstallCheck |
| 53 | +
|
| 54 | + $out/bin/opa-envoy-plugin --help |
| 55 | + $out/bin/opa-envoy-plugin version |
| 56 | + $out/bin/opa-envoy-plugin version | grep "Version: ${version}" |
| 57 | +
|
| 58 | + ${lib.optionalString enableWasmEval '' |
| 59 | + # If wasm is enabled verify it works |
| 60 | + $out/bin/opa eval -t wasm 'trace("hello from wasm")' |
| 61 | + ''} |
| 62 | +
|
| 63 | + runHook postInstallCheck |
| 64 | + ''; |
| 65 | + |
| 66 | + meta = { |
| 67 | + mainProgram = "opa"; |
| 68 | + homepage = "https://www.openpolicyagent.org/docs/latest/envoy-introduction/"; |
| 69 | + changelog = "https://github.com/open-policy-agent/opa-envoy-plugin/blob/v${version}/CHANGELOG.md"; |
| 70 | + description = "A plugin to enforce OPA policies with Envoy"; |
| 71 | + longDescription = '' |
| 72 | + OPA-Envoy extends OPA with a gRPC server that implements the Envoy |
| 73 | + External Authorization API. You can use this version of OPA to enforce |
| 74 | + fine-grained, context-aware access control policies with Envoy without |
| 75 | + modifying your microservice. |
| 76 | + ''; |
| 77 | + license = lib.licenses.asl20; |
| 78 | + maintainers = with lib.maintainers; [ |
| 79 | + charlieegan3 |
| 80 | + ]; |
| 81 | + }; |
| 82 | +} |
0 commit comments