2021-10-08 12:07:54 +00:00
|
|
|
|
{ lib
|
2022-05-10 18:34:53 +00:00
|
|
|
|
, stdenv
|
2021-10-08 12:07:54 +00:00
|
|
|
|
, buildGoModule
|
|
|
|
|
, fetchFromGitHub
|
|
|
|
|
, installShellFiles
|
|
|
|
|
|
|
|
|
|
, enableWasmEval ? false
|
|
|
|
|
}:
|
2019-11-08 12:47:13 +00:00
|
|
|
|
|
2022-05-10 18:34:53 +00:00
|
|
|
|
assert enableWasmEval && stdenv.isDarwin -> builtins.throw "building with wasm on darwin is failing in nixpkgs";
|
|
|
|
|
|
2020-11-13 18:51:06 +00:00
|
|
|
|
buildGoModule rec {
|
2019-11-08 12:47:13 +00:00
|
|
|
|
pname = "open-policy-agent";
|
2022-07-04 12:46:06 +00:00
|
|
|
|
version = "0.42.0";
|
2019-11-08 12:47:13 +00:00
|
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
|
owner = "open-policy-agent";
|
|
|
|
|
repo = "opa";
|
|
|
|
|
rev = "v${version}";
|
2022-07-04 12:46:06 +00:00
|
|
|
|
sha256 = "sha256-Sn0vtC6skQE/IxXj3cjrq5iXYjM1wi17d4eavPKhk+g=";
|
2019-11-08 12:47:13 +00:00
|
|
|
|
};
|
2020-11-13 18:51:06 +00:00
|
|
|
|
vendorSha256 = null;
|
|
|
|
|
|
2021-10-08 12:07:54 +00:00
|
|
|
|
nativeBuildInputs = [ installShellFiles ];
|
|
|
|
|
|
2020-10-13 22:00:46 +00:00
|
|
|
|
subPackages = [ "." ];
|
|
|
|
|
|
2021-07-02 07:29:05 +00:00
|
|
|
|
ldflags = [ "-s" "-w" "-X github.com/open-policy-agent/opa/version.Version=${version}" ];
|
2021-03-09 17:51:14 +00:00
|
|
|
|
|
2021-10-08 12:07:54 +00:00
|
|
|
|
tags = lib.optional enableWasmEval (
|
|
|
|
|
builtins.trace
|
|
|
|
|
("Warning: enableWasmEval breaks reproducability, "
|
|
|
|
|
+ "ensure you need wasm evaluation. "
|
|
|
|
|
+ "`opa build` does not need this feature.")
|
|
|
|
|
"opa_wasm");
|
|
|
|
|
|
|
|
|
|
preCheck = ''
|
|
|
|
|
# Feed in all but the e2e tests for testing
|
|
|
|
|
# This is because subPackages above limits what is built to just what we
|
|
|
|
|
# want but also limits the tests
|
2022-05-10 18:34:53 +00:00
|
|
|
|
# Also avoid wasm tests on darwin due to wasmtime-go build issues
|
2021-10-08 12:07:54 +00:00
|
|
|
|
getGoDirs() {
|
2022-05-10 18:34:53 +00:00
|
|
|
|
go list ./... | grep -v -e e2e ${lib.optionalString stdenv.isDarwin "-e wasm"}
|
2021-10-08 12:07:54 +00:00
|
|
|
|
}
|
2022-05-10 18:34:53 +00:00
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
2022-05-11 10:53:36 +00:00
|
|
|
|
# remove tests that have "too many open files"/"no space left on device" issues on darwin in hydra
|
|
|
|
|
rm server/server_test.go
|
2021-10-08 12:07:54 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
|
installShellCompletion --cmd opa \
|
|
|
|
|
--bash <($out/bin/opa completion bash) \
|
|
|
|
|
--fish <($out/bin/opa completion fish) \
|
|
|
|
|
--zsh <($out/bin/opa completion zsh)
|
|
|
|
|
'';
|
|
|
|
|
|
2021-03-09 17:51:14 +00:00
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
installCheckPhase = ''
|
|
|
|
|
runHook preInstallCheck
|
2021-10-08 12:07:54 +00:00
|
|
|
|
|
2021-03-09 17:51:14 +00:00
|
|
|
|
$out/bin/opa --help
|
|
|
|
|
$out/bin/opa version | grep "Version: ${version}"
|
2021-10-08 12:07:54 +00:00
|
|
|
|
|
|
|
|
|
${lib.optionalString enableWasmEval ''
|
|
|
|
|
# If wasm is enabled verify it works
|
|
|
|
|
$out/bin/opa eval -t wasm 'trace("hello from wasm")'
|
|
|
|
|
''}
|
|
|
|
|
|
2021-03-09 17:51:14 +00:00
|
|
|
|
runHook postInstallCheck
|
|
|
|
|
'';
|
2020-07-25 19:30:12 +00:00
|
|
|
|
|
2019-11-08 12:47:13 +00:00
|
|
|
|
meta = with lib; {
|
2022-05-10 18:34:53 +00:00
|
|
|
|
mainProgram = "opa";
|
2021-06-04 12:39:01 +00:00
|
|
|
|
homepage = "https://www.openpolicyagent.org";
|
|
|
|
|
changelog = "https://github.com/open-policy-agent/opa/blob/v${version}/CHANGELOG.md";
|
2019-11-08 12:47:13 +00:00
|
|
|
|
description = "General-purpose policy engine";
|
2020-11-13 18:56:15 +00:00
|
|
|
|
longDescription = ''
|
|
|
|
|
The Open Policy Agent (OPA, pronounced "oh-pa") is an open source, general-purpose policy engine that unifies
|
|
|
|
|
policy enforcement across the stack. OPA provides a high-level declarative language that let’s you specify policy
|
|
|
|
|
as code and simple APIs to offload policy decision-making from your software. You can use OPA to enforce policies
|
|
|
|
|
in microservices, Kubernetes, CI/CD pipelines, API gateways, and more.
|
|
|
|
|
'';
|
2019-11-08 12:47:13 +00:00
|
|
|
|
license = licenses.asl20;
|
2021-03-09 17:51:14 +00:00
|
|
|
|
maintainers = with maintainers; [ lewo jk ];
|
2019-11-08 12:47:13 +00:00
|
|
|
|
};
|
|
|
|
|
}
|