Add Go to an existing workspace
Wire up the gonx inference plugin in an existing Nx workspace that was not created with the gonx preset.
Step 1: Register the plugin
Section titled “Step 1: Register the plugin”The idiomatic way is nx add, which installs the package and runs the init generator to register the plugin:
nx add @naxodev/gonx
This registers @naxodev/gonx under plugins in nx.json. Once registered, the plugin scans your workspace for go.mod files and infers Nx targets from them automatically.
If the package is already installed, run the init generator directly instead — it does the same registration:
nx g @naxodev/gonx:init
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
addGoDotWork | boolean | false | Add a go.work file to the project. |
Pass --addGoDotWork (to init) if you want a Go workspace (go.work) at the repo root:
nx g @naxodev/gonx:init --addGoDotWork
Step 2: Add Go projects
Section titled “Step 2: Add Go projects”After init, add Go projects in one of two ways:
Generate a new application or library:
nx g @naxodev/gonx:application apps/my-api
nx g @naxodev/gonx:library libs/my-lib
Or drop a go.mod into an existing directory. The inference plugin picks it up automatically — no project.json required.
Inferred targets
Section titled “Inferred targets”Once a go.mod is present in a directory, the plugin infers the following targets:
| Target | Available on | Description |
|---|---|---|
build | Applications only | Compile the Go binary. |
serve | Applications only | Run the application locally. |
test | Applications and libs | Run go test. |
tidy | Applications and libs | Run go mod tidy. |
lint | Applications and libs | Run the configured Go linter. |
generate | Applications and libs | Run go generate. |
nx-release-publish | Applications and libs | Publish via nx release. |
Applications are detected by the presence of a main.go containing package main and func main(, or a cmd/ directory.
Verify
Section titled “Verify”nx show project my-api
The project appears in the graph with its inferred targets — no project.json required.