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

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

162 lines
4.6 KiB
Nix
Raw Normal View History

2021-01-24 03:40:18 +03:00
{ lib
2022-02-24 04:36:53 +03:00
, bazel_4
2021-01-24 03:40:18 +03:00
, buildBazelPackage
2021-01-08 04:35:50 +03:00
, fetchFromGitHub
2022-02-24 04:36:53 +03:00
, fetchpatch
2021-01-08 04:35:50 +03:00
, stdenv
, cmake
2021-06-07 04:18:01 +03:00
, gn
2021-01-08 04:35:50 +03:00
, go
2021-06-07 04:18:01 +03:00
, jdk
2021-01-08 04:35:50 +03:00
, ninja
, python3
2022-02-24 04:36:53 +03:00
, linuxHeaders
, nixosTests
# v8 (upstream default), wavm, wamr, wasmtime, disabled
, wasmRuntime ? "wamr"
2021-01-08 04:35:50 +03: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.
2022-02-24 04:36:53 +03:00
version = "1.21.1";
rev = "af50070ee60866874b0a9383daf9364e884ded22";
2021-01-08 04:35:50 +03:00
};
in
buildBazelPackage rec {
pname = "envoy";
2022-02-24 04:36:53 +03:00
inherit (srcVer) version;
bazel = bazel_4;
2021-01-08 04:35:50 +03:00
src = fetchFromGitHub {
owner = "envoyproxy";
repo = "envoy";
inherit (srcVer) rev;
2022-02-24 04:36:53 +03:00
hash = "sha256:11mm72zmb479ss585jzqzhklyyqmdadnvr91ghzvjxc0j2a1hrr4";
2021-01-08 04:35:50 +03:00
extraPostFetch = ''
chmod -R +w $out
rm $out/.bazelversion
2022-02-24 04:36:53 +03:00
echo ${srcVer.rev} > $out/SOURCE_VERSION
2021-01-08 04:35:50 +03:00
sed -i 's/GO_VERSION = ".*"/GO_VERSION = "host"/g' $out/bazel/dependency_imports.bzl
'';
};
postPatch = ''
sed -i 's,#!/usr/bin/env python3,#!${python3}/bin/python,' bazel/foreign_cc/luajit.patch
2021-06-07 04:18:01 +03:00
sed -i '/javabase=/d' .bazelrc
# Patch paths to build tools, and disable gold because it just segfaults.
substituteInPlace bazel/external/wee8.genrule_cmd \
--replace '"''$$gn"' '"''$$(command -v gn)"' \
--replace '"''$$ninja"' '"''$$(command -v ninja)"' \
--replace '"''$$WEE8_BUILD_ARGS"' '"''$$WEE8_BUILD_ARGS use_gold=false"'
2021-01-08 04:35:50 +03:00
'';
2022-02-24 04:36:53 +03:00
patches = [
# make linux/tcp.h relative. drop when upgrading to >1.21
(fetchpatch {
url = "https://github.com/envoyproxy/envoy/commit/68448aae7a78a3123097b6ea96016b270457e7b8.patch";
sha256 = "123kv3x37p8fgfp29jhw5xg5js5q5ipibs8hsm7gzfd5bcllnpfh";
})
# fix issues with brotli and GCC 11.2.0+ (-Werror=vla-parameter)
./bump-brotli.patch
# fix linux-aarch64 WAMR builds
# (upstream WAMR only detects aarch64 on Darwin, not Linux)
./fix-aarch64-wamr.patch
2022-02-24 04:36:53 +03:00
];
2021-01-08 04:35:50 +03:00
nativeBuildInputs = [
cmake
python3
2021-06-07 04:18:01 +03:00
gn
2021-01-08 04:35:50 +03:00
go
2021-06-07 04:18:01 +03:00
jdk
2021-01-08 04:35:50 +03:00
ninja
];
2022-02-24 04:36:53 +03:00
buildInputs = [
linuxHeaders
];
2021-01-08 04:35:50 +03:00
fetchAttrs = {
sha256 = {
2022-05-10 08:28:43 +03:00
x86_64-linux = "sha256-23Z6SbKnbah/NCrdMrXhrNFFASd/8xRH3fSyIE++heA=";
aarch64-linux = "1ijv4arw67nprykn2wkn4ji8fbr284mc7p74zxfsky772s42yy9j";
}.${stdenv.system} or (throw "unsupported system ${stdenv.system}");
2021-01-08 04:35:50 +03:00
dontUseCmakeConfigure = true;
2021-06-07 04:18:01 +03:00
dontUseGnConfigure = true;
2021-01-08 04:35:50 +03: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
rm -r $bazelOut/external/go_sdk
2021-06-07 04:18:01 +03:00
# Remove Unix timestamps from go cache.
rm -rf $bazelOut/external/bazel_gazelle_go_repository_cache/{gocache,pkg/mod/cache,pkg/sumdb}
2021-01-08 04:35:50 +03:00
'';
};
buildAttrs = {
dontUseCmakeConfigure = true;
2021-06-07 04:18:01 +03:00
dontUseGnConfigure = true;
2021-01-08 04:35:50 +03:00
dontUseNinjaInstall = true;
preConfigure = ''
2022-02-24 04:36:53 +03: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 04:35:50 +03: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
'';
installPhase = ''
install -Dm0755 bazel-bin/source/exe/envoy-static $out/bin/envoy
'';
};
removeRulesCC = false;
removeLocalConfigCc = true;
removeLocal = false;
bazelTarget = "//source/exe:envoy-static";
bazelBuildFlags = [
"-c opt"
"--spawn_strategy=standalone"
"--noexperimental_strict_action_env"
"--cxxopt=-Wno-maybe-uninitialized"
"--cxxopt=-Wno-uninitialized"
"--cxxopt=-Wno-error=type-limits"
"--define=wasm=${wasmRuntime}"
];
bazelFetchFlags = [
"--define=wasm=${wasmRuntime}"
2021-01-08 04:35:50 +03:00
];
passthru.tests = {
2021-08-28 05:28:27 +03:00
envoy = nixosTests.envoy;
# tested as a core component of Pomerium
pomerium = nixosTests.pomerium;
};
2021-01-24 03:40:18 +03:00
meta = with lib; {
2021-01-08 04:35:50 +03:00
homepage = "https://envoyproxy.io";
description = "Cloud-native edge and service proxy";
license = licenses.asl20;
maintainers = with maintainers; [ lukegb ];
platforms = [ "x86_64-linux" "aarch64-linux" ];
2021-01-08 04:35:50 +03:00
};
}