sqlite_orm: 1.9 -> 1.9.1 (#379250)
[NixPkgs.git] / pkgs / by-name / op / open-policy-agent / package.nix
blob50d92479055724f46829390307cdf7c2d8d1de42
2   lib,
3   stdenv,
4   buildGoModule,
5   fetchFromGitHub,
6   installShellFiles,
8   enableWasmEval ? false,
9 }:
11 assert
12   enableWasmEval && stdenv.hostPlatform.isDarwin
13   -> builtins.throw "building with wasm on darwin is failing in nixpkgs";
15 buildGoModule rec {
16   pname = "open-policy-agent";
17   version = "0.70.0";
19   src = fetchFromGitHub {
20     owner = "open-policy-agent";
21     repo = "opa";
22     rev = "v${version}";
23     hash = "sha256-7br0rxhVNH+lt+gWwFSuYCBmZMrejLatWJyVNcQ95NA=";
24   };
26   vendorHash = null;
28   nativeBuildInputs = [ installShellFiles ];
30   subPackages = [ "." ];
32   ldflags = [
33     "-s"
34     "-w"
35     "-X github.com/open-policy-agent/opa/version.Version=${version}"
36   ];
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   );
46   checkFlags = lib.optionals (!enableWasmEval) [
47     "-skip=TestRegoTargetWasmAndTargetPluginDisablesIndexingTopdownStages"
48   ];
50   preCheck =
51     ''
52       # Feed in all but the e2e tests for testing
53       # This is because subPackages above limits what is built to just what we
54       # want but also limits the tests
55       # Also avoid wasm tests on darwin due to wasmtime-go build issues
56       getGoDirs() {
57         go list ./... | grep -v -e e2e ${lib.optionalString stdenv.hostPlatform.isDarwin "-e wasm"}
58       }
59     ''
60     + lib.optionalString stdenv.hostPlatform.isDarwin ''
61       # remove tests that have "too many open files"/"no space left on device" issues on darwin in hydra
62       rm server/server_test.go
63     '';
65   postInstall = ''
66     installShellCompletion --cmd opa \
67       --bash <($out/bin/opa completion bash) \
68       --fish <($out/bin/opa completion fish) \
69       --zsh <($out/bin/opa completion zsh)
70   '';
72   doInstallCheck = true;
73   installCheckPhase = ''
74     runHook preInstallCheck
76     $out/bin/opa --help
77     $out/bin/opa version | grep "Version: ${version}"
79     ${lib.optionalString enableWasmEval ''
80       # If wasm is enabled verify it works
81       $out/bin/opa eval -t wasm 'trace("hello from wasm")'
82     ''}
84     runHook postInstallCheck
85   '';
87   meta = with lib; {
88     mainProgram = "opa";
89     homepage = "https://www.openpolicyagent.org";
90     changelog = "https://github.com/open-policy-agent/opa/blob/v${version}/CHANGELOG.md";
91     description = "General-purpose policy engine";
92     longDescription = ''
93       The Open Policy Agent (OPA, pronounced "oh-pa") is an open source, general-purpose policy engine that unifies
94       policy enforcement across the stack. OPA provides a high-level declarative language that let’s you specify policy
95       as code and simple APIs to offload policy decision-making from your software. You can use OPA to enforce policies
96       in microservices, Kubernetes, CI/CD pipelines, API gateways, and more.
97     '';
98     license = licenses.asl20;
99     maintainers = with maintainers; [
100       lewo
101       jk
102     ];
103   };