diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
index f81526240312..15854d524283 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/cpp-test.nix
@@ -40,8 +40,6 @@ let
     export LD='${darwin.cctools}/bin/ld'
     export LIBTOOL='${darwin.cctools}/bin/libtool'
     export CC='${stdenv.cc}/bin/clang'
-    export BAZEL_LINKLIBS='-lstdc++:-lm'
-    export BAZEL_LINKOPTS='-x:c++'
 
     # XXX: hack for macosX, this flags disable bazel usage of xcode
     # See: https://github.com/bazelbuild/bazel/issues/4231
@@ -67,33 +65,25 @@ let
     inherit workspaceDir;
     bazelPkg = bazel;
     bazelScript = ''
-      set -x
-      env | grep c..abi
       ${bazel}/bin/bazel build //... \
         --enable_bzlmod \
         --verbose_failures \
         --repository_cache=${mergedDistDir} \
-        --action_env=NIX_DEBUG=1 \
-        --announce_rc \
         --curses=no \
     '' + lib.optionalString (stdenv.isDarwin) ''
-        --repo_env=BAZEL_LINKLIBS \
-        --repo_env=BAZEL_LINKOPTS \
         --cxxopt=-x --cxxopt=c++ \
         --host_cxxopt=-x --host_cxxopt=c++ \
-        --action_env=NIX_CFLAGS_COMPILE \
-        --action_env=NIX_LDFLAGS \
+    '' + lib.optionalString (stdenv.cc.isClang && stdenv ? cc.libcxx.cxxabi.libName) ''
+        --linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+        --linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+        --host_linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+        --host_linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
     '' + lib.optionalString (stdenv.isDarwin && Foundation != null) ''
         --linkopt=-Wl,-F${Foundation}/Library/Frameworks \
         --linkopt=-L${darwin.libobjc}/lib \
     '' + ''
 
     '';
-    #'' + lib.optionalString (stdenv.isDarwin) ''
-    #    --repo_env=BAZEL_LINKLIBS='-lstdc++:-lm' \
-    #'' + lib.optionalString (stdenv.isDarwin) ''
-    #    --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
-    #    --linkopt=-Wl,-lstdc++ --host_linkopt=-Wl,-lstdc++ \
   };
 
 in testBazel
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
index 37520ad3008a..88867e89d620 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/protobuf-test.nix
@@ -1,24 +1,25 @@
 { bazel
+, Foundation
 , bazelTest
+, callPackage
+, darwin
+, distDir
+, extraBazelArgs ? ""
 , fetchFromGitHub
 , fetchurl
-, stdenv
-, darwin
-, extraBazelArgs ? ""
-, lib
-, openjdk8
 , jdk11_headless
-, runLocal
-, runtimeShell
-, writeScript
-, writeText
-, distDir
-, Foundation
-, callPackage
+, lib
 , libtool
 , lndir
+, openjdk8
 , repoCache
+, runLocal
+, runtimeShell
+, stdenv
+, symlinkJoin
 , tree
+, writeScript
+, writeText
 }:
 
 # This test uses bzlmod because I could not make it work without it.
@@ -35,7 +36,7 @@ let
   #    [nix-shell]$ cp MODULE.bazel.lock $HERE/protobuf-test.MODULE.bazel.lock
   lockfile = ./protobuf-test.MODULE.bazel.lock;
 
-  protocbufRepoCache = callPackage ./bazel-repository-cache.nix {
+  protobufRepoCache = callPackage ./bazel-repository-cache.nix {
     # We are somewhat lucky that bazel's own lockfile works for our tests.
     # Use extraDeps if the tests need things that are not in that lockfile.
     # But most test dependencies are bazel's builtin deps, so that at least aligns.
@@ -46,6 +47,11 @@ let
       null == builtins.match ".*(macos|osx|linux|win|android|maven).*" name;
   };
 
+  mergedRepoCache = symlinkJoin {
+    name = "mergedDistDir";
+    paths = [ protobufRepoCache distDir ];
+  };
+
   MODULE = writeText "MODULE.bazel" ''
     bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
     bazel_dep(name = "protobuf", version = "21.7")
@@ -137,29 +143,26 @@ let
     ];
 
     bazelScript = ''
-      # Augment bundled repository_cache with our extra paths
-      mkdir -p $PWD/.repository_cache/content_addressable
-      ${lndir}/bin/lndir ${repoCache}/content_addressable \
-        $PWD/.repository_cache/content_addressable
-      ${lndir}/bin/lndir ${protocbufRepoCache}/content_addressable \
-        $PWD/.repository_cache/content_addressable
-
-      tree $PWD/.repository_cache
-
       ${bazel}/bin/bazel \
         build \
-        --repository_cache=$PWD/.repository_cache \
+        --repository_cache=${mergedRepoCache} \
         ${extraBazelArgs} \
         --enable_bzlmod \
         --verbose_failures \
         //... \
     '' + lib.optionalString (lib.strings.versionOlder bazel.version "5.0.0") ''
-      --host_javabase='@local_jdk//:jdk' \
-      --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
-      --javabase='@local_jdk//:jdk' \
+        --host_javabase='@local_jdk//:jdk' \
+        --java_toolchain='@bazel_tools//tools/jdk:toolchain_hostjdk8' \
+        --javabase='@local_jdk//:jdk' \
     '' + lib.optionalString (stdenv.isDarwin) ''
-      --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
-      --linkopt=-stdlib=libc++ --host_linkopt=-stdlib=libc++ \
+        --cxxopt=-x --cxxopt=c++ --host_cxxopt=-x --host_cxxopt=c++ \
+    '' + lib.optionalString (stdenv.cc.isClang && stdenv ? cc.libcxx.cxxabi.libName) ''
+        --linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+        --linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+        --host_linkopt=-Wl,-l${stdenv.cc.libcxx.cxxabi.libName} \
+        --host_linkopt=-L${stdenv.cc.libcxx.cxxabi}/lib \
+    '' + ''
+
     '';
   };
 
diff --git a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
index 15088ef84e6a..7aafce0f4619 100644
--- a/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
+++ b/pkgs/development/tools/build-managers/bazel/bazel_7/tests.nix
@@ -126,26 +126,32 @@ let
     hash = "sha256-DaPKp7Sn5uvfZRjdDx6grot3g3B7trqCyL0TRIdwg98=";
   };
 
-  callBazelTests = args:
+  callBazelTests = bazel:
     let
       callBazelTest = newScope {
         inherit runLocal bazelTest bazel-examples;
         inherit Foundation;
-        bazel = bazel_self;
+        inherit bazel;
         distDir = testsDistDir;
         extraBazelArgs = "";
+        repoCache = testsRepoCache;
       };
     in
     recurseIntoAttrs (
       (lib.optionalAttrs (!isDarwin) {
         # `extracted` doesn’t work on darwin
-        shebang = callBazelTest ../shebang-test.nix (args // { inherit extracted; });
+        shebang = callBazelTest ../shebang-test.nix {
+          inherit extracted;
+          extraBazelArgs = "--noenable_bzlmod";
+        };
       }) // {
-        bashTools = callBazelTest ../bash-tools-test.nix args;
-        cpp = callBazelTest ./cpp-test.nix args;
-        java = callBazelTest ../java-test.nix args;
-        pythonBinPath = callBazelTest ../python-bin-path-test.nix args;
-        protobuf = callBazelTest ./protobuf-test.nix (args // { repoCache = testsRepoCache; });
+        bashTools = callBazelTest ../bash-tools-test.nix { };
+        cpp = callBazelTest ./cpp-test.nix { };
+        java = callBazelTest ../java-test.nix {
+          extraBazelArgs = "--noenable_bzlmod";
+        };
+        pythonBinPath = callBazelTest ../python-bin-path-test.nix { };
+        protobuf = callBazelTest ./protobuf-test.nix { };
       }
     );
 
@@ -156,8 +162,8 @@ recurseIntoAttrs {
   distDir = testsDistDir;
   testsRepoCache = testsRepoCache;
 
-  vanilla = callBazelTests { };
-  withNixHacks = callBazelTests { bazel = bazelWithNixHacks; };
+  vanilla = callBazelTests bazel_self;
+  withNixHacks = callBazelTests bazelWithNixHacks;
 
   # add some downstream packages using buildBazelPackage
   downstream = recurseIntoAttrs ({