nixpkgs/pkgs/servers/http/envoy/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

203 lines
6.1 KiB
Nix
Raw Normal View History

2021-01-24 00:40:18 +00:00
{ lib
2023-05-12 07:22:58 +00:00
, bazel_6
, bazel-gazelle
2021-01-24 00:40:18 +00:00
, buildBazelPackage
2021-01-08 01:35:50 +00:00
, fetchFromGitHub
2024-01-15 05:25:37 +00:00
, fetchpatch
2021-01-08 01:35:50 +00:00
, stdenv
, cmake
2021-06-07 01:18:01 +00:00
, gn
2021-01-08 01:35:50 +00:00
, go
2021-06-07 01:18:01 +00:00
, jdk
2021-01-08 01:35:50 +00:00
, ninja
2022-09-04 21:20:47 +00:00
, patchelf
2021-01-08 01:35:50 +00:00
, python3
2022-02-24 01:36:53 +00:00
, linuxHeaders
, nixosTests
# v8 (upstream default), wavm, wamr, wasmtime, disabled
, wasmRuntime ? "wamr"
2021-01-08 01:35:50 +00:00
}:
let
srcVer = {
# We need the commit hash, since Bazel stamps the build with it.
# However, the version string is more useful for end-users.
# These are contained in a attrset of their own to make it obvious that
# people should update both.
version = "1.27.3";
rev = "0fd81ee7ffcd7cfc864094b24dc9b5c3ade89ff2";
hash = "sha256-WNyyUw3517oKqMd1sJMk9CiLa/V7UrhwlRS+AWNNOOo=";
2021-01-08 01:35:50 +00:00
};
2024-01-15 05:25:37 +00:00
# these need to be updated for any changes to fetchAttrs
depsHash = {
x86_64-linux = "sha256-wTGHfeFkCuijPdX//lT5GPspaxZsxzBHJffH1tpVM2w=";
aarch64-linux = "sha256-9/Wem+Gk/7bFeMNFC4J3mdTm3mrNmyMxiu5oadQcovU=";
2024-01-15 05:25:37 +00:00
}.${stdenv.system} or (throw "unsupported system ${stdenv.system}");
2021-01-08 01:35:50 +00:00
in
2024-01-15 05:25:37 +00:00
buildBazelPackage {
2021-01-08 01:35:50 +00:00
pname = "envoy";
2022-02-24 01:36:53 +00:00
inherit (srcVer) version;
2023-05-12 07:22:58 +00:00
bazel = bazel_6;
2021-01-08 01:35:50 +00:00
src = fetchFromGitHub {
owner = "envoyproxy";
repo = "envoy";
2024-01-15 05:25:37 +00:00
inherit (srcVer) hash rev;
2021-01-08 01:35:50 +00:00
2022-05-17 19:10:33 +00:00
postFetch = ''
2021-01-08 01:35:50 +00:00
chmod -R +w $out
rm $out/.bazelversion
2022-02-24 01:36:53 +00:00
echo ${srcVer.rev} > $out/SOURCE_VERSION
2021-01-08 01:35:50 +00:00
'';
};
postPatch = ''
sed -i 's,#!/usr/bin/env python3,#!${python3}/bin/python,' bazel/foreign_cc/luajit.patch
2021-06-07 01:18:01 +00:00
sed -i '/javabase=/d' .bazelrc
sed -i '/"-Werror"/d' bazel/envoy_internal.bzl
2022-09-04 21:20:47 +00:00
2023-02-19 18:56:55 +00:00
cp ${./protobuf.patch} bazel/protobuf.patch
2021-01-08 01:35:50 +00:00
'';
2022-02-24 01:36:53 +00:00
patches = [
2022-09-04 21:20:47 +00:00
# use system Python, not bazel-fetched binary Python
2023-02-19 18:56:55 +00:00
./0001-nixpkgs-use-system-Python.patch
# use system Go, not bazel-fetched binary Go
./0002-nixpkgs-use-system-Go.patch
2023-10-13 22:13:20 +00:00
# use system C/C++ tools
./0003-nixpkgs-use-system-C-C-toolchains.patch
2024-01-15 05:25:37 +00:00
# bump proxy-wasm-cpp-host until > 1.27.3/1.28.0
2024-01-15 05:25:37 +00:00
(fetchpatch {
url = "https://github.com/envoyproxy/envoy/pull/31451.patch";
hash = "sha256-n8k7bho3B8Gm0dJbgf43kU7ymvo15aGJ2Twi2xR450g=";
})
2022-02-24 01:36:53 +00:00
];
2021-01-08 01:35:50 +00:00
nativeBuildInputs = [
cmake
python3
2021-06-07 01:18:01 +00:00
gn
2021-01-08 01:35:50 +00:00
go
2021-06-07 01:18:01 +00:00
jdk
2021-01-08 01:35:50 +00:00
ninja
2022-09-04 21:20:47 +00:00
patchelf
2021-01-08 01:35:50 +00:00
];
2022-02-24 01:36:53 +00:00
buildInputs = [
linuxHeaders
];
2023-02-19 18:56:55 +00:00
# external/com_github_grpc_grpc/src/core/ext/transport/binder/transport/binder_transport.cc:756:29: error: format not a string literal and no format arguments [-Werror=format-security]
hardeningDisable = [ "format" ];
2021-01-08 01:35:50 +00:00
fetchAttrs = {
2024-01-15 05:25:37 +00:00
sha256 = depsHash;
2021-01-08 01:35:50 +00:00
dontUseCmakeConfigure = true;
2021-06-07 01:18:01 +00:00
dontUseGnConfigure = true;
2021-01-08 01:35:50 +00:00
preInstall = ''
# Strip out the path to the build location (by deleting the comment line).
find $bazelOut/external -name requirements.bzl | while read requirements; do
sed -i '/# Generated from /d' "$requirements"
done
# Remove references to paths in the Nix store.
sed -i \
-e 's,${python3},__NIXPYTHON__,' \
-e 's,${stdenv.shellPackage},__NIXSHELL__,' \
$bazelOut/external/com_github_luajit_luajit/build.py \
$bazelOut/external/local_config_sh/BUILD \
$bazelOut/external/*_pip3/BUILD.bazel
2021-01-08 01:35:50 +00:00
rm -r $bazelOut/external/go_sdk
rm -r $bazelOut/external/local_jdk
rm -r $bazelOut/external/bazel_gazelle_go_repository_tools/bin
2021-01-08 01:35:50 +00:00
2023-09-12 13:03:41 +00:00
# Remove compiled python
find $bazelOut -name '*.pyc' -delete
2021-06-07 01:18:01 +00:00
# Remove Unix timestamps from go cache.
rm -rf $bazelOut/external/bazel_gazelle_go_repository_cache/{gocache,pkg/mod/cache,pkg/sumdb}
2024-01-15 05:25:37 +00:00
# fix tcmalloc failure https://github.com/envoyproxy/envoy/issues/30838
sed -i '/TCMALLOC_GCC_FLAGS = \[/a"-Wno-changes-meaning",' $bazelOut/external/com_github_google_tcmalloc/tcmalloc/copts.bzl
2021-01-08 01:35:50 +00:00
'';
};
buildAttrs = {
dontUseCmakeConfigure = true;
2021-06-07 01:18:01 +00:00
dontUseGnConfigure = true;
2021-01-08 01:35:50 +00:00
dontUseNinjaInstall = true;
preConfigure = ''
# Make executables work, for the most part.
find $bazelOut/external -type f -executable | while read execbin; do
file "$execbin" | grep -q ': ELF .*, dynamically linked,' || continue
patchelf \
--set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
"$execbin"
done
ln -s ${bazel-gazelle}/bin $bazelOut/external/bazel_gazelle_go_repository_tools/bin
2022-02-24 01:36:53 +00:00
sed -i 's,#!/usr/bin/env bash,#!${stdenv.shell},' $bazelOut/external/rules_foreign_cc/foreign_cc/private/framework/toolchains/linux_commands.bzl
2021-01-08 01:35:50 +00:00
# Add paths to Nix store back.
sed -i \
-e 's,__NIXPYTHON__,${python3},' \
-e 's,__NIXSHELL__,${stdenv.shellPackage},' \
$bazelOut/external/com_github_luajit_luajit/build.py \
$bazelOut/external/local_config_sh/BUILD \
$bazelOut/external/*_pip3/BUILD.bazel
2021-01-08 01:35:50 +00:00
'';
installPhase = ''
install -Dm0755 bazel-bin/source/exe/envoy-static $out/bin/envoy
'';
};
removeRulesCC = false;
removeLocalConfigCc = true;
removeLocal = false;
bazelTargets = [ "//source/exe:envoy-static" ];
2021-01-08 01:35:50 +00:00
bazelBuildFlags = [
"-c opt"
"--spawn_strategy=standalone"
"--noexperimental_strict_action_env"
"--cxxopt=-Wno-error"
2023-02-09 10:41:09 +00:00
"--linkopt=-Wl,-z,noexecstack"
2022-09-04 21:20:47 +00:00
# Force use of system Java.
"--extra_toolchains=@local_jdk//:all"
"--java_runtime_version=local_jdk"
"--tool_java_runtime_version=local_jdk"
"--define=wasm=${wasmRuntime}"
] ++ (lib.optionals stdenv.isAarch64 [
# external/com_github_google_tcmalloc/tcmalloc/internal/percpu_tcmalloc.h:611:9: error: expected ':' or '::' before '[' token
# 611 | : [end_ptr] "=&r"(end_ptr), [cpu_id] "=&r"(cpu_id),
# | ^
"--define=tcmalloc=disabled"
]);
bazelFetchFlags = [
"--define=wasm=${wasmRuntime}"
2021-01-08 01:35:50 +00:00
];
passthru.tests = {
2021-08-28 02:28:27 +00:00
envoy = nixosTests.envoy;
# tested as a core component of Pomerium
pomerium = nixosTests.pomerium;
};
2021-01-24 00:40:18 +00:00
meta = with lib; {
2021-01-08 01:35:50 +00:00
homepage = "https://envoyproxy.io";
changelog = "https://github.com/envoyproxy/envoy/releases/tag/v${version}";
2021-01-08 01:35:50 +00:00
description = "Cloud-native edge and service proxy";
mainProgram = "envoy";
2021-01-08 01:35:50 +00:00
license = licenses.asl20;
maintainers = with maintainers; [ lukegb ];
platforms = [ "x86_64-linux" "aarch64-linux" ];
knownVulnerabilities = [ "CVE-2024-30255" ];
2021-01-08 01:35:50 +00:00
};
}