third_party/nix: move bazel-inner wrapper to external file

Because of previous interpolation issues and hard to read escaping, we are moving the wrapper script to a dedicated file. This also corrects the .gitignore to not exclude files that are
prefixed with bazel-

Change-Id: I922636041302ba01b331665f74b64f4e91dae56c
Reviewed-on: https://review.monogon.dev/c/monogon/+/2837
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/third_party/nix/bazel-inner.sh b/third_party/nix/bazel-inner.sh
new file mode 100755
index 0000000..1fdfd38
--- /dev/null
+++ b/third_party/nix/bazel-inner.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/bash
+function get_workspace_root() {
+  workspace_dir="${PWD}"
+  while [[ "${workspace_dir}" != / ]]; do
+    if [[ -e "${workspace_dir}/WORKSPACE" || -e "${workspace_dir}/WORKSPACE.bazel" ]]; then
+      readonly workspace_dir
+      return
+    fi
+    workspace_dir="$(dirname "${workspace_dir}")"
+  done
+  readonly workspace_dir=""
+}
+
+get_workspace_root
+readonly wrapper="${workspace_dir}/tools/bazel"
+if [ -f "${wrapper}" ]; then
+  exec -a "$0" "${wrapper}" "$@"
+fi
+exec -a "$0" "${BAZEL_REAL}" "$@"