22 # v8 (upstream default), wavm, wamr, wasmtime, disabled
28 # We need the commit hash, since Bazel stamps the build with it.
29 # However, the version string is more useful for end-users.
30 # These are contained in a attrset of their own to make it obvious that
31 # people should update both.
33 rev = "86dc7ef91ca15fb4957a74bd599397413fc26a24";
34 hash = "sha256-Wcbt62RfaNcTntmPjaAM0cP3LJangm4ht7Q0bzEpu5A=";
37 # these need to be updated for any changes to fetchAttrs
40 x86_64-linux = "sha256-LkDNPFT7UUCsGPG1dMnwzdIw0lzc5+3JYDoblF5oZVk=";
41 aarch64-linux = "sha256-DkibjmY1YND9Q2aQ41bhNdch0SKM5ghY2mjYSQfV30M=";
43 .${stdenv.system} or (throw "unsupported system ${stdenv.system}");
45 buildBazelPackage rec {
47 inherit (srcVer) version;
49 src = fetchFromGitHub {
52 inherit (srcVer) hash rev;
57 echo ${srcVer.rev} > $out/SOURCE_VERSION
62 sed -i 's,#!/usr/bin/env python3,#!${python3}/bin/python,' bazel/foreign_cc/luajit.patch
63 sed -i '/javabase=/d' .bazelrc
64 sed -i '/"-Werror"/d' bazel/envoy_internal.bzl
67 substitute ${./bazel_nix.BUILD.bazel} bazel/nix/BUILD.bazel \
68 --subst-var-by bash "$(type -p bash)"
69 ln -sf "${cargo}/bin/cargo" bazel/nix/cargo
70 ln -sf "${rustc}/bin/rustc" bazel/nix/rustc
71 ln -sf "${rustc}/bin/rustdoc" bazel/nix/rustdoc
72 ln -sf "${rustPlatform.rustLibSrc}" bazel/nix/ruststd
73 substituteInPlace bazel/dependency_imports.bzl \
74 --replace-fail 'crate_universe_dependencies()' 'crate_universe_dependencies(rust_toolchain_cargo_template="@@//bazel/nix:cargo", rust_toolchain_rustc_template="@@//bazel/nix:rustc")' \
75 --replace-fail 'crates_repository(' 'crates_repository(rust_toolchain_cargo_template="@@//bazel/nix:cargo", rust_toolchain_rustc_template="@@//bazel/nix:rustc",'
77 substitute ${./rules_rust_extra.patch} bazel/nix/rules_rust_extra.patch \
78 --subst-var-by bash "$(type -p bash)"
79 cat bazel/nix/rules_rust_extra.patch bazel/rules_rust.patch > bazel/nix/rules_rust.patch
80 mv bazel/nix/rules_rust.patch bazel/rules_rust.patch
84 # use system Python, not bazel-fetched binary Python
85 ./0001-nixpkgs-use-system-Python.patch
87 # use system Go, not bazel-fetched binary Go
88 ./0002-nixpkgs-use-system-Go.patch
90 # use system C/C++ tools
91 ./0003-nixpkgs-use-system-C-C-toolchains.patch
105 buildInputs = [ linuxHeaders ];
109 env.CARGO_BAZEL_REPIN = true;
110 dontUseCmakeConfigure = true;
111 dontUseGnConfigure = true;
115 substituteInPlace bazel/dependency_imports.bzl \
116 --replace-fail 'crate_universe_dependencies(' 'crate_universe_dependencies(bootstrap=True, ' \
117 --replace-fail 'crates_repository(' 'crates_repository(generator="@@cargo_bazel_bootstrap//:cargo-bazel", '
120 # Strip out the path to the build location (by deleting the comment line).
121 find $bazelOut/external -name requirements.bzl | while read requirements; do
122 sed -i '/# Generated from /d' "$requirements"
125 # Remove references to paths in the Nix store.
127 -e 's,${python3},__NIXPYTHON__,' \
128 -e 's,${stdenv.shellPackage},__NIXSHELL__,' \
129 $bazelOut/external/com_github_luajit_luajit/build.py \
130 $bazelOut/external/local_config_sh/BUILD \
131 $bazelOut/external/*_pip3/BUILD.bazel
133 rm -r $bazelOut/external/go_sdk
134 rm -r $bazelOut/external/local_jdk
135 rm -r $bazelOut/external/bazel_gazelle_go_repository_tools/bin
137 # Remove compiled python
138 find $bazelOut -name '*.pyc' -delete
140 # Remove Unix timestamps from go cache.
141 rm -rf $bazelOut/external/bazel_gazelle_go_repository_cache/{gocache,pkg/mod/cache,pkg/sumdb}
143 # fix tcmalloc failure https://github.com/envoyproxy/envoy/issues/30838
144 sed -i '/TCMALLOC_GCC_FLAGS = \[/a"-Wno-changes-meaning",' $bazelOut/external/com_github_google_tcmalloc/tcmalloc/copts.bzl
146 # Install repinned rules_rust lockfile
147 cp source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock $bazelOut/external/Cargo.Bazel.lock
149 # Don't save cargo_bazel_bootstrap or the crate index cache
150 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
154 dontUseCmakeConfigure = true;
155 dontUseGnConfigure = true;
156 dontUseNinjaInstall = true;
158 # Make executables work, for the most part.
159 find $bazelOut/external -type f -executable | while read execbin; do
160 file "$execbin" | grep -q ': ELF .*, dynamically linked,' || continue
162 --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
163 "$execbin" || echo "$execbin"
166 ln -s ${bazel-gazelle}/bin $bazelOut/external/bazel_gazelle_go_repository_tools/bin
168 sed -i 's,#!/usr/bin/env bash,#!${stdenv.shell},' $bazelOut/external/rules_foreign_cc/foreign_cc/private/framework/toolchains/linux_commands.bzl
170 # Add paths to Nix store back.
172 -e 's,__NIXPYTHON__,${python3},' \
173 -e 's,__NIXSHELL__,${stdenv.shellPackage},' \
174 $bazelOut/external/com_github_luajit_luajit/build.py \
175 $bazelOut/external/local_config_sh/BUILD \
176 $bazelOut/external/*_pip3/BUILD.bazel
178 # Install repinned rules_rust lockfile
179 cp $bazelOut/external/Cargo.Bazel.lock source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock
182 install -Dm0755 bazel-bin/source/exe/envoy-static $out/bin/envoy
186 removeRulesCC = false;
187 removeLocalConfigCc = true;
189 bazelTargets = [ "//source/exe:envoy-static" ];
193 "--spawn_strategy=standalone"
194 "--noexperimental_strict_action_env"
195 "--cxxopt=-Wno-error"
196 "--linkopt=-Wl,-z,noexecstack"
198 # Force use of system Java.
199 "--extra_toolchains=@local_jdk//:all"
200 "--java_runtime_version=local_jdk"
201 "--tool_java_runtime_version=local_jdk"
203 # Force use of system Rust.
204 "--extra_toolchains=//bazel/nix:rust_nix_aarch64,//bazel/nix:rust_nix_x86_64"
206 # undefined reference to 'grpc_core::*Metadata*::*Memento*
208 # During linking of the final binary, we see undefined references to grpc_core related symbols.
209 # 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
210 # "ParseMemento" and "MementoToValue" are only implemented for some types
211 # and appear unused and unimplemented for the undefined cases reported by the linker.
212 "--linkopt=-Wl,--unresolved-symbols=ignore-in-object-files"
214 "--define=wasm=${wasmRuntime}"
216 ++ (lib.optionals stdenv.hostPlatform.isAarch64 [
217 # external/com_github_google_tcmalloc/tcmalloc/internal/percpu_tcmalloc.h:611:9: error: expected ':' or '::' before '[' token
218 # 611 | : [end_ptr] "=&r"(end_ptr), [cpu_id] "=&r"(cpu_id),
220 "--define=tcmalloc=disabled"
224 "--define=wasm=${wasmRuntime}"
226 # Force use of system Rust.
227 "--extra_toolchains=//bazel/nix:rust_nix_aarch64,//bazel/nix:rust_nix_x86_64"
229 # https://github.com/bazelbuild/rules_go/issues/3844
230 "--repo_env=GOPROXY=https://proxy.golang.org,direct"
231 "--repo_env=GOSUMDB=sum.golang.org"
234 requiredSystemFeatures = [ "big-parallel" ];
237 envoy = nixosTests.envoy;
238 # tested as a core component of Pomerium
239 pomerium = nixosTests.pomerium;
243 homepage = "https://envoyproxy.io";
244 changelog = "https://github.com/envoyproxy/envoy/releases/tag/v${version}";
245 description = "Cloud-native edge and service proxy";
246 mainProgram = "envoy";
247 license = licenses.asl20;
248 maintainers = with maintainers; [ lukegb ];