Skip to content

Libraries

Add and remove Go libraries with nsgo add and nsgo remove, use custom registries, and ship libraries’ native code.

Add a library, a Go module, with nsgo add, which is go get with its plan shown first:

nsgo add -list # list libraries and components in NSGo's built-in index
nsgo add -list icons flags # filter case-insensitively by words across name, description and tags
nsgo add media # resolve a short name in NSGo's built-in index
nsgo add github.com/acme/chart # its newest release, unless go.mod has it already
nsgo add github.com/acme/chart@v1.3.0 # this version, even one below go.mod's
nsgo add -dry-run github.com/acme/chart # print the plan and write nothing

Bare names (without a dot in their first segment) resolve only in NSGo’s built-in index (cmd/nsgo/registry.yaml, embedded in nsgo with nothing fetched or cached). A bare name plans the same way as its module path, using the entry’s version when present else @upgrade, and refuses a module with no release tag (<name> has no release; add its module by path with a version). Unknown names suggest nsgo add -list. nsgo add -list [words...] prints each matching item’s name, kind (library or component), module path and description, and works inside or outside a module. Items with kind component are listed in the index and refused by nsgo add until component copying lands.

github.com/acme/chart
module github.com/acme/chart v1.3.0, published 2026-11-20
owner github.com/acme, the first module from it in go.mod
licenses github.com/acme/chart: MIT
example.com/units: MIT
next import "github.com/acme/chart"
example.com/hello
go.mod + require github.com/acme/chart v1.3.0 // indirect
+ require example.com/units v1.0.0 // indirect
~ require github.com/nsgo-dev/nsgo v0.4.0 => v0.4.2, a release
go.sum + 6 lines
tools go tool nsgo then runs v0.4.2, and so does an installed nsgo here
Apply these changes? [y/N]

For each module, the plan names its version and publication date, and its owner: the host, and on a code host such as github.com the account, marked when go.mod has no module from it yet. Retraction and deprecation notices, a version with no release tag, a replace of the module, the classified licenses of every module and native library it brings in (noting when a registry license differs from what was detected), each target’s native libraries with their licenses and download hosts, any package that does not build for a target (such as when build constraints exclude every file), and the import line of its root package follow when they apply. Target inspection runs for each of the app’s expanded build.targets, or the host’s target without nsgo.yaml. When a module ships an nsgo-module.yaml, the plan uses its declared import packages, names any of the app’s build.targets its targets lack, lists its components with their nsgo add <module>#<name> commands, and prints the author’s notes last and marked. Then come the lines of go.mod that change, go and toolchain included, the go tool commands that would run another version, the modules fetched from their own hosts and those go.sum takes unchecked by the checksum database. go get marks a module no package imports yet // indirect, and go mod tidy drops the mark once one does.

In a terminal, add asks before writing, and -y applies the plan without asking; without a terminal and without -y, it writes nothing and exits with status 1. An interrupt, such as Ctrl+C, leaves go.mod and go.sum as they were and exits with status 130. A module go.mod already requires is left as it is, its version printed, unless a version is typed.

Planning runs nothing but the go command, on copies of go.mod and go.sum:

  • with the toolchain the module already uses and GOTOOLCHAIN=local, so no other toolchain is downloaded or run;
  • through the module proxies GOPROXY lists before its first direct, which becomes off, so only the modules GOPRIVATE or GONOPROXY marks are fetched from their own hosts, with GONOSUMDB and GOAUTH as they are;
  • with GOWORK=off for go get, so in a workspace it plans go.mod for the module alone, as GOWORK=off go get writes it, and says so; per-target package listing reads the planned go.mod and go.sum through -overlay with -mod=readonly, so it also runs in a workspace and ignores a vendor directory.

Whether or not -y is given, add refuses:

  • moving NSGo’s requirement to a pseudo-version or a pre-release, as a library that requires a commit of NSGo would; go get github.com/nsgo-dev/nsgo@<version> moves it there on purpose first;
  • a module that needs a newer Go than the module’s toolchain; go get go@<version> raises the module’s first;
  • lowering a module through a query such as @latest; typing the version lowers it, and the plan calls it a downgrade;
  • a module or native library whose license fails the app’s licenses policy (unrecognized or missing license text by default, or copyleft text under licenses.copyleft: error), naming the licenses.allow entry or warn setting for nsgo.yaml; add never edits the policy.

It writes go.mod and go.sum only when neither has changed since planning, each through a temporary file renamed over it, and puts both back on an error or an interrupt. In a module with a vendor directory, the plan names go mod vendor as the next step.

add is new after NSGo 0.3.4. In a module that pins 0.3.4 or an earlier release, an installed nsgo does not run the module’s nsgo for it but prints the go get github.com/nsgo-dev/nsgo@<version> that brings add; there, go tool nsgo add runs the pinned nsgo, which does not know add.

Teams can name their own libraries and forks in nsgo.yaml under registries: without shadowing NSGo’s own names:

registries:
"@acme": https://nsgo.acme.example/registry.yaml
"@team": tools/registry.yaml

Each key is @ followed by 1 to 64 lowercase letters, digits or hyphens (not starting or ending with -; @nsgo is reserved). Each value is an https URL without user credentials, query or fragment (http is accepted only for a loopback host), or a path relative to nsgo.yaml. Unknown keys and bad entries fail with their line number, and nsgo never adds an unconfigured registry to nsgo.yaml on its own.

nsgo add @acme/chart # resolve chart in @acme; bare names never check custom registries
nsgo add @acme/chart@v1.3.0 # pin a specific version
nsgo add -list # list NSGo's index and every configured registry's items (with their @prefix)
nsgo add -list @acme charts # filter one registry by words across name, description and tags

A registry file is a single strict YAML document of at most 4 MiB with version: 1 and an items list (name, module, optional component, optional tagged version, single-line description, SPDX license, optional https homepage, and optional lowercase tags), without anchors, aliases, merge keys, control characters or Unicode format characters. Remote registries follow up to 10 redirects (refusing redirects to plain HTTP or non-loopback HTTP), use a 30-second connect timeout and 5-minute total timeout, and cache their copy and ETag at <user cache dir>/nsgo/registries/<sha256>.yaml. Offline, nsgo add reuses the cached copy and shows its age on the plan’s first line alongside the registry and URL; with no cached copy, the error names the URL. Private registries use a file in the repository or an intranet server, and private Go modules keep GOPRIVATE and GOAUTH.

nsgo add also copies components declared in a module’s nsgo-module.yaml (nsgo add [-diff] [-dir D] [-tests=false] name|@registry/name|module[@version]#component), rewriting their imports, generating their catalogs, checking their licenses and recording their source in nsgo-copy.yaml. See Copying components.

Once no package in the module imports a library, drop it with nsgo remove, which takes a bare name from NSGo’s built-in index, a @registry/name from nsgo.yaml’s registries, or a Go module path, and previews go mod tidy on copies of go.mod and go.sum before writing:

nsgo remove media # resolve a bare name in NSGo's built-in index
nsgo remove @acme/chart # resolve a name in a configured custom registry
nsgo remove github.com/acme/chart # show what go mod tidy drops and ask before writing
nsgo remove -dry-run github.com/acme/chart # print the plan and write nothing
nsgo remove -y github.com/acme/chart # apply without asking
github.com/acme/chart
module remove github.com/acme/chart v1.3.0
example.com/hello
go.mod - require github.com/acme/chart v1.3.0
- require example.com/units v1.0.0
- require example.com/stray v0.1.0, also tidied
go.sum - 6 lines
Apply these changes? [y/N]

Before running go mod tidy, remove checks imports with go mod why -m, which counts every build tag (_ios.go and test files included), and refuses while any package of the module still imports the library directly, naming that package. A name that resolves to a copied component is also refused before anything is planned. Custom registries print their registry @<name> (<source>) line at the top of the plan, as add does.

remove runs go mod tidy in add’s environment (GOTOOLCHAIN=local, GOWORK=off and proxy-only GOPROXY) and never lowers another module’s version; versions raised when the library was added stay, matching what go mod tidy writes. In the plan:

  • lines unrelated to the removed library or its dropped dependencies are marked also tidied;
  • a library that stays because another dependency needs it or because go.mod declares one of its tools says why;
  • any replace of the library in go.mod is mentioned as left in place.

Confirmation, -dry-run, -y, running without a terminal, interrupts, atomic writes and go mod vendor follow the same rules as add. remove is likewise new after NSGo 0.3.4.

Desktop app builds and target tests compile app code with CGO_ENABLED=0, as they do NSGo itself. If an app package contains cgo files, the build stops and names them instead of silently dropping them. Use purego and nsgo-natives.yaml for native libraries.

Apps that import base/terminal also ship libghostty-vt: Windows and Linux packages place the library beside the executable; macOS and iOS bundles sign it into their frameworks. Embedding explains the companion XCFramework for iOS hosts.

A dependency can declare prebuilt desktop shared libraries in nsgo-natives.yaml, and from version 2 of that file frameworks for iOS and tvOS. NSGo verifies their SHA-256, copies them into the app before signing and includes them in installers; the app author runs no extra step. From version 2 it can also name Linux packages, which the .deb and the Arch package then depend on or recommend after the app’s own linux.depends and linux.recommends. Native libraries describes the package author’s format and loading paths.