Skip to content

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.

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
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

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.

Once a go.mod is present in a directory, the plugin infers the following targets:

TargetAvailable onDescription
buildApplications onlyCompile the Go binary.
serveApplications onlyRun the application locally.
testApplications and libsRun go test.
tidyApplications and libsRun go mod tidy.
lintApplications and libsRun the configured Go linter.
generateApplications and libsRun go generate.
nx-release-publishApplications and libsPublish via nx release.

Applications are detected by the presence of a main.go containing package main and func main(, or a cmd/ directory.

nx show project my-api

The project appears in the graph with its inferred targets — no project.json required.