> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# nsc bazel setup

Set up a remote Bazel execution cluster.

`bazel setup` provisions a [Bazel Remote Execution](/docs/bazel/execution) cluster
for your workspace and generates a bazelrc that points Bazel at it. The generated
configuration covers the remote executor, the remote cache, credentials, and
recommended execution defaults, so a single `--bazelrc` flag is enough to run a
build remotely.

Pass `--remote=false` to configure remote caching and build events without remote
execution. This is the form used to set up [Bazel caching](/docs/bazel/cache) on
its own.

## Usage

```bash theme={null}
nsc bazel setup [--bazelrc <path>] \
    [--command <command>] \
    [--disable_build_events] \
    [--enable_remote_asset_api] \
    [--key <name>] \
    [--output <plain|json>] \
    [--remote] \
    [--static] \
    [--static_token_duration <duration>] \
    [--token <path>]
```

### Example with remote execution

The following example provisions an execution cluster and runs a build against it.

<Steps titleSize="h4">
  <Step title="Configure remote execution">
    Generate a Bazel configuration for remote execution:

    ```bash theme={null}
    nsc bazel setup --bazelrc=~/.namespace.bazelrc
    ```
  </Step>

  <Step title="Run a build">
    Use the generated configuration during a build:

    ```bash theme={null}
    bazel --bazelrc=~/.namespace.bazelrc build //...
    ```
  </Step>
</Steps>

### Example with remote caching

The following example configures remote cache access without remote execution and uses it during a build.

<Steps titleSize="h4">
  <Step title="Configure remote caching">
    Configure remote cache access without remote execution:

    ```bash theme={null}
    nsc bazel setup --remote=false --bazelrc /etc/bazel.bazelrc
    ```
  </Step>

  <Step title="Run a build">
    Use the generated cache configuration during a build:

    ```bash theme={null}
    bazel --bazelrc=/etc/bazel.bazelrc build //...
    ```
  </Step>
</Steps>

## Options

<h3 id="--bazelrc">
  \--bazelrc
</h3>

If specified, write the bazelrc to this path.

<h3 id="--command">
  \--command
</h3>

The Bazel command to use in the generated bazelrc (e.g. `build` or `common`). Defaults to `build`.

<h3 id="--disable_build_events">
  \--disable\_build\_events
</h3>

If specified, do not configure Bazel to send build events to Namespace.

<h3 id="--enable_remote_asset_api">
  \--enable\_remote\_asset\_api
</h3>

Opt in to the [remote asset API](/docs/bazel/cache#remote-asset-api), so Bazel can route external dependency fetches through the Namespace cache via `--experimental_remote_downloader`.

<h3 id="--key">
  \--key
</h3>

Stable identifier that disambiguates multiple parallel execution clusters for the same workspace. Defaults to `default`. Use a distinct key when you want a separate cluster, for example to keep one project's workers from sharing capacity with another.

<h3 id="-o---output">
  -o, --output
</h3>

Output format, one of `plain` or `json`. Defaults to `plain`.

<h3 id="--remote">
  \--remote
</h3>

Whether to configure remote execution. Defaults to `true`. Set `--remote=false` to configure remote caching and build events without remote execution.

<h3 id="--static">
  \--static
</h3>

Use a static bearer token in `--remote_header` against the public endpoints, instead of issuing an mTLS client certificate. Useful for CI/CD pipelines and automation without an interactive login.

<h3 id="--static_token_duration">
  \--static\_token\_duration
</h3>

The minimum duration of the static token configured. Requires `--static`. Defaults to `4h`.

<h3 id="--token">
  \--token
</h3>

Use the bearer token stored at this location for authentication instead of the default. Implies `--static`. Pair it with [`nsc bazel create-token`](/docs/reference/cli/bazel-create-token) to authenticate without an interactive login.

## Related Topics

* [Bazel Remote Execution](/docs/bazel/execution) - Run Bazel actions on Namespace compute
* [Bazel cache](/docs/bazel/cache) - Reuse build artifacts across runs
* [nsc bazel create-token](/docs/reference/cli/bazel-create-token) - Create a revocable token for Bazel remote execution
* [nsc bazel invocation list](/docs/reference/cli/bazel-invocation-list) - List recent Bazel invocations
