···88# updater
99, python3, writeScript
1010# Apple dependencies
1111-, cctools, libcxx, CoreFoundation, CoreServices, Foundation
1111+, cctools, libcxx, CoreFoundation, CoreServices, Foundation, sigtool
1212# Allow to independently override the jdks used to build and run respectively
1313, buildJdk, runJdk
1414, runtimeShell
···2525}:
26262727let
2828- version = "6.4.0";
2828+ version = "6.5.0";
2929 sourceRoot = ".";
30303131 src = fetchurl {
3232 url = "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-dist.zip";
3333- hash = "sha256-vYj/YCyLuynugroqaxKtCS1R7GaMZXf5Yo8Y5I/05R4=";
3333+ hash = "sha256-/InakZQVKJ8p5P8YpeAScOzppv6Dy2CWchi6xKO7PtI=";
3434 };
35353636 # Update with
···179179180180in
181181stdenv.mkDerivation rec {
182182- pname = "bazel";
182182+ pname = "bazel${ lib.optionalString enableNixHacks "-hacks" }";
183183 inherit version;
184184185185 meta = with lib; {
···205205 # the prebuilt one does not work in nix world.
206206 ./java_toolchain.patch
207207208208+ # Bazel integrates with apple IOKit to inhibit and track system sleep.
209209+ # Inside the darwin sandbox, these API calls are blocked, and bazel
210210+ # crashes. It seems possible to allow these APIs inside the sandbox, but it
211211+ # feels simpler to patch bazel not to use it at all. So our bazel is
212212+ # incapable of preventing system sleep, which is a small price to pay to
213213+ # guarantee that it will always run in any nix context.
214214+ #
215215+ # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
216216+ # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
217217+ # sandbox.
218218+ #
219219+ # If you want to investigate the sandbox profile path,
220220+ # IORegisterForSystemPower can be allowed with
221221+ #
222222+ # propagatedSandboxProfile = ''
223223+ # (allow iokit-open (iokit-user-client-class "RootDomainUserClient"))
224224+ # '';
225225+ #
226226+ # I do not know yet how to allow IOPMAssertion{CreateWithName,Release}
227227+ ./darwin_sleep.patch
228228+208229 # On Darwin, the last argument to gcc is coming up as an empty string. i.e: ''
209230 # This is breaking the build of any C target. This patch removes the last
210231 # argument if it's found to be an empty string.
···289310 bazelTest = { name, bazelScript, workspaceDir, bazelPkg, buildInputs ? [] }:
290311 let
291312 be = extracted bazelPkg;
292292- in runLocal name { inherit buildInputs; } (
313313+ in runLocal name {
314314+ inherit buildInputs;
315315+ # Necessary for the tests to pass on Darwin with sandbox enabled.
316316+ __darwinAllowLocalNetworking = true;
317317+ } (
293318 # skip extraction caching on Darwin, because nobody knows how Darwin works
294319 (lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
295320 # set up home with pre-unpacked bazel
···403428 export NIX_CFLAGS_COMPILE+=" -Wno-deprecated-builtins -Wno-gnu-offsetof-extensions"
404429405430 # don't use system installed Xcode to run clang, use Nix clang instead
406406- sed -i -E "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $(bazelLinkFlags) -framework CoreFoundation;g" \
431431+ sed -i -E \
432432+ -e "s;/usr/bin/xcrun (--sdk macosx )?clang;${stdenv.cc}/bin/clang $NIX_CFLAGS_COMPILE $(bazelLinkFlags) -framework CoreFoundation;g" \
433433+ -e "s;/usr/bin/codesign;CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate ${sigtool}/bin/codesign;" \
434434+ -e "s;env -i codesign;env -i CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate ${sigtool}/bin/codesign;" \
407435 scripts/bootstrap/compile.sh \
408436 tools/osx/BUILD
409437···557585 which
558586 zip
559587 python3.pkgs.absl-py # Needed to build fish completion
560560- ] ++ lib.optionals (stdenv.isDarwin) [ cctools libcxx CoreFoundation CoreServices Foundation ];
588588+ ] ++ lib.optionals (stdenv.isDarwin) [ cctools libcxx sigtool CoreFoundation CoreServices Foundation ];
561589562590 # Bazel makes extensive use of symlinks in the WORKSPACE.
563591 # This causes problems with infinite symlinks if the build output is in the same location as the
···593621 ${python3}/bin/python3 ./bazel_src/scripts/generate_fish_completion.py \
594622 --bazel=./bazel_src/output/bazel \
595623 --output=./bazel_src/output/bazel-complete.fish
596596-624624+ '' +
625625+ # disable execlog parser on darwin, since it fails to build
626626+ # see https://github.com/NixOS/nixpkgs/pull/273774#issuecomment-1865322055
627627+ lib.optionalString (!stdenv.isDarwin) ''
597628 # need to change directory for bazel to find the workspace
598629 cd ./bazel_src
599630 # build execlog tooling
···617648 wrapProgram $out/bin/bazel $wrapperfile --suffix PATH : ${defaultShellPath}
618649 mv ./bazel_src/output/bazel $out/bin/bazel-${version}-${system}-${arch}
619650651651+ '' +
652652+ # disable execlog parser on darwin, since it fails to build
653653+ # see https://github.com/NixOS/nixpkgs/pull/273774#issuecomment-1865322055
654654+ (lib.optionalString (!stdenv.isDarwin) ''
620655 mkdir $out/share
621656 cp ./bazel_src/bazel-bin/src/tools/execlog/parser_deploy.jar $out/share/parser_deploy.jar
622657 cat <<EOF > $out/bin/bazel-execlog
···624659 ${runJdk}/bin/java -jar $out/share/parser_deploy.jar \$@
625660 EOF
626661 chmod +x $out/bin/bazel-execlog
627627-662662+ '') + ''
628663 # shell completion files
629664 installShellCompletion --bash \
630665 --name bazel.bash \
···677712678713 # second call succeeds because it defers to $out/bin/bazel-{version}-{os_arch}
679714 hello_test
715715+716716+ ## Test that the GSON serialisation files are present
717717+ gson_classes=$(unzip -l $($out/bin/bazel info install_base)/A-server.jar | grep -F -c _GsonTypeAdapter.class)
718718+ if [ "$gson_classes" -lt 10 ]; then
719719+ echo "Missing GsonTypeAdapter classes in A-server.jar. Lockfile generation will not work"
720720+ exit 1
721721+ fi
680722681723 runHook postInstall
682724 '';
···213213 #
214214 # See also ./bazel_darwin_sandbox.patch in bazel_5. That patch uses
215215 # NIX_BUILD_TOP env var to conditionnally disable sleep features inside the
216216- # sandbox. Oddly, bazel_6 does not need that patch :-/.
216216+ # sandbox.
217217 #
218218 # If you want to investigate the sandbox profile path,
219219 # IORegisterForSystemPower can be allowed with