2024-07-19 20:06:50 +00:00
{
lib ,
bazel_6 ,
bazel-gazelle ,
buildBazelPackage ,
fetchFromGitHub ,
stdenv ,
2024-10-19 17:35:02 +00:00
cacert ,
cargo ,
rustc ,
rustPlatform ,
2024-07-19 20:06:50 +00:00
cmake ,
gn ,
go ,
jdk ,
ninja ,
patchelf ,
python3 ,
linuxHeaders ,
nixosTests ,
2022-05-08 21:44:47 +00:00
2023-10-23 07:52:39 +00:00
# v8 (upstream default), wavm, wamr, wasmtime, disabled
2024-07-19 20:06:50 +00:00
wasmRuntime ? " w a m r " ,
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.
2024-10-16 12:45:00 +00:00
version = " 1 . 3 2 . 0 " ;
rev = " 8 6 d c 7 e f 9 1 c a 1 5 f b 4 9 5 7 a 7 4 b d 5 9 9 3 9 7 4 1 3 f c 2 6 a 2 4 " ;
hash = " s h a 2 5 6 - W c b t 6 2 R f a N c T n t m P j a A M 0 c P 3 L J a n g m 4 h t 7 Q 0 b z E p u 5 A = " ;
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
2024-07-19 20:06:50 +00:00
depsHash =
{
2024-10-19 17:35:02 +00:00
x86_64-linux = " s h a 2 5 6 - L k D N P F T 7 U U C s G P G 1 d M n w z d I w 0 l z c 5 + 3 J Y D o b l F 5 o Z V k = " ;
aarch64-linux = " s h a 2 5 6 - D k i b j m Y 1 Y N D 9 Q 2 a Q 4 1 b h N d c h 0 S K M 5 g h Y 2 m j Y S Q f V 3 0 M = " ;
2024-07-19 20:06:50 +00:00
}
. ${ stdenv . system } or ( throw " u n s u p p o r t e d s y s t e m ${ stdenv . system } " ) ;
2021-01-08 01:35:50 +00:00
in
2024-10-19 17:35:02 +00:00
buildBazelPackage rec {
2021-01-08 01:35:50 +00:00
pname = " e n v o y " ;
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 = " e n v o y p r o x y " ;
repo = " e n v o y " ;
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
2022-09-11 03:31:27 +00:00
sed - i ' / " - W e r r o r " /d ' bazel/envoy_internal.bzl
2024-10-19 17:35:02 +00:00
mkdir - p bazel/nix /
substitute $ { ./bazel_nix.BUILD.bazel } bazel/nix/BUILD.bazel \
- - subst-var-by bash " $ ( t y p e - p b a s h ) "
ln - sf " ${ cargo } / b i n / c a r g o " bazel/nix/cargo
ln - sf " ${ rustc } / b i n / r u s t c " bazel/nix/rustc
ln - sf " ${ rustc } / b i n / r u s t d o c " bazel/nix/rustdoc
ln - sf " ${ rustPlatform . rustLibSrc } " bazel/nix/ruststd
substituteInPlace bazel/dependency_imports.bzl \
- - replace-fail ' crate_universe_dependencies ( ) ' ' crate_universe_dependencies ( rust_toolchain_cargo_template = " @ @ / / b a z e l / n i x : c a r g o " , rust_toolchain_rustc_template = " @ @ / / b a z e l / n i x : r u s t c " ) ' \
- - replace-fail ' crates_repository ( ' ' crates_repository ( rust_toolchain_cargo_template = " @ @ / / b a z e l / n i x : c a r g o " , rust_toolchain_rustc_template = " @ @ / / b a z e l / n i x : r u s t c " , '
substitute $ { ./rules_rust_extra.patch } bazel/nix/rules_rust_extra.patch \
- - subst-var-by bash " $ ( t y p e - p b a s h ) "
cat bazel/nix/rules_rust_extra.patch bazel/rules_rust.patch > bazel/nix/rules_rust.patch
mv bazel/nix/rules_rust.patch bazel/rules_rust.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
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
2024-10-19 17:35:02 +00:00
cacert
2021-01-08 01:35:50 +00:00
] ;
2024-07-19 20:06:50 +00:00
buildInputs = [ linuxHeaders ] ;
2022-02-24 01:36:53 +00:00
2021-01-08 01:35:50 +00:00
fetchAttrs = {
2024-01-15 05:25:37 +00:00
sha256 = depsHash ;
2024-10-19 17:35:02 +00:00
env . CARGO_BAZEL_REPIN = true ;
2021-01-08 01:35:50 +00:00
dontUseCmakeConfigure = true ;
2021-06-07 01:18:01 +00:00
dontUseGnConfigure = true ;
2024-10-19 17:35:02 +00:00
postPatch = ''
$ { postPatch }
substituteInPlace bazel/dependency_imports.bzl \
- - replace-fail ' crate_universe_dependencies ( ' ' crate_universe_dependencies ( bootstrap = True , ' \
- - replace-fail ' crates_repository ( ' ' crates_repository ( generator = " @ @ c a r g o _ b a z e l _ b o o t s t r a p / / : c a r g o - b a z e l " , '
'' ;
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 \
2022-09-11 03:31:27 +00:00
$ bazelOut/external/local_config_sh/BUILD \
2023-09-15 18:41:44 +00:00
$ bazelOut/external /* _ p i p 3 / B U I L D . b a z e l
2022-09-11 03:31:27 +00:00
2021-01-08 01:35:50 +00:00
rm - r $ bazelOut/external/go_sdk
2022-09-11 03:31:27 +00:00
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 " - W n o - c h a n g e s - m e a n i n g " , ' $ bazelOut/external/com_github_google_tcmalloc/tcmalloc/copts.bzl
2024-10-19 17:35:02 +00:00
# Install repinned rules_rust lockfile
cp source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock $ bazelOut/external/Cargo.Bazel.lock
# Don't save cargo_bazel_bootstrap or the crate index cache
rm - rf $ bazelOut/external/cargo_bazel_bootstrap $ bazelOut/external/dynamic_modules_rust_sdk_crate_index/.cargo_home $ bazelOut/external/dynamic_modules_rust_sdk_crate_index/splicing-output
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 = ''
2022-09-11 03:31:27 +00:00
# Make executables work, for the most part.
find $ bazelOut/external - type f - executable | while read execbin ; do
file " $ e x e c b i n " | grep - q ' : ELF . * , dynamically linked , ' || continue
patchelf \
- - set-interpreter $ ( cat $ { stdenv . cc } /nix-support/dynamic-linker ) \
2024-10-19 17:35:02 +00:00
" $ e x e c b i n " || echo " $ e x e c b i n "
2022-09-11 03:31:27 +00:00
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 \
2022-09-11 03:31:27 +00:00
$ bazelOut/external/local_config_sh/BUILD \
2023-09-15 18:41:44 +00:00
$ bazelOut/external /* _ p i p 3 / B U I L D . b a z e l
2024-10-19 17:35:02 +00:00
# Install repinned rules_rust lockfile
cp $ bazelOut/external/Cargo.Bazel.lock source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock
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 ;
2023-04-05 02:59:54 +00:00
bazelTargets = [ " / / s o u r c e / e x e : e n v o y - s t a t i c " ] ;
2024-07-19 20:06:50 +00:00
bazelBuildFlags =
[
" - c o p t "
" - - s p a w n _ s t r a t e g y = s t a n d a l o n e "
" - - n o e x p e r i m e n t a l _ s t r i c t _ a c t i o n _ e n v "
" - - c x x o p t = - W n o - e r r o r "
" - - l i n k o p t = - W l , - z , n o e x e c s t a c k "
# Force use of system Java.
" - - e x t r a _ t o o l c h a i n s = @ l o c a l _ j d k / / : a l l "
" - - j a v a _ r u n t i m e _ v e r s i o n = l o c a l _ j d k "
" - - t o o l _ j a v a _ r u n t i m e _ v e r s i o n = l o c a l _ j d k "
2024-10-19 17:35:02 +00:00
# Force use of system Rust.
" - - e x t r a _ t o o l c h a i n s = / / b a z e l / n i x : r u s t _ n i x _ a a r c h 6 4 , / / b a z e l / n i x : r u s t _ n i x _ x 8 6 _ 6 4 "
2024-07-19 20:06:50 +00:00
# undefined reference to 'grpc_core::*Metadata*::*Memento*
#
# During linking of the final binary, we see undefined references to grpc_core related symbols.
# The missing symbols would be instantiations of a template class from https://github.com/grpc/grpc/blob/v1.59.4/src/core/lib/transport/metadata_batch.h
# "ParseMemento" and "MementoToValue" are only implemented for some types
# and appear unused and unimplemented for the undefined cases reported by the linker.
" - - l i n k o p t = - W l , - - u n r e s o l v e d - s y m b o l s = i g n o r e - i n - o b j e c t - f i l e s "
" - - d e f i n e = w a s m = ${ wasmRuntime } "
]
++ ( lib . optionals stdenv . hostPlatform . 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),
# | ^
" - - d e f i n e = t c m a l l o c = d i s a b l e d "
] ) ;
2024-04-22 09:31:13 +00:00
2022-05-08 21:44:47 +00:00
bazelFetchFlags = [
" - - d e f i n e = w a s m = ${ wasmRuntime } "
2024-04-22 09:31:13 +00:00
2024-10-19 17:35:02 +00:00
# Force use of system Rust.
" - - e x t r a _ t o o l c h a i n s = / / b a z e l / n i x : r u s t _ n i x _ a a r c h 6 4 , / / b a z e l / n i x : r u s t _ n i x _ x 8 6 _ 6 4 "
2024-04-22 09:31:13 +00:00
# https://github.com/bazelbuild/rules_go/issues/3844
" - - r e p o _ e n v = G O P R O X Y = h t t p s : / / p r o x y . g o l a n g . o r g , d i r e c t "
" - - r e p o _ e n v = G O S U M D B = s u m . g o l a n g . o r g "
2021-01-08 01:35:50 +00:00
] ;
2024-07-01 23:49:09 +00:00
requiredSystemFeatures = [ " b i g - p a r a l l e l " ] ;
2021-01-08 03:04:24 +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-08 03:04:24 +00:00
} ;
2021-01-24 00:40:18 +00:00
meta = with lib ; {
2021-01-08 01:35:50 +00:00
homepage = " h t t p s : / / e n v o y p r o x y . i o " ;
2024-02-14 02:58:04 +00:00
changelog = " h t t p s : / / g i t h u b . c o m / e n v o y p r o x y / e n v o y / r e l e a s e s / t a g / v ${ version } " ;
2021-01-08 01:35:50 +00:00
description = " C l o u d - n a t i v e e d g e a n d s e r v i c e p r o x y " ;
2024-03-19 02:14:51 +00:00
mainProgram = " e n v o y " ;
2021-01-08 01:35:50 +00:00
license = licenses . asl20 ;
maintainers = with maintainers ; [ lukegb ] ;
2024-07-19 20:06:50 +00:00
platforms = [
" x 8 6 _ 6 4 - l i n u x "
" a a r c h 6 4 - l i n u x "
] ;
2021-01-08 01:35:50 +00:00
} ;
}