The cx Book 1.0.0
cx: a package manager and build tool for C and C++
Loading...
Searching...
No Matches
Configuration

Settings that aren't part of a package, like which registries to use, how many jobs to run or whether to use the network, live in configuration files.

Where the files are

File Purpose Commit it?
~/.config/cx/config.toml ($XDG_CONFIG_HOME/cx/, APPDATA%\cx\ on Windows) your personal defaults no
<project>/.cx/config.toml settings for one project, found by walking up from the current directory yes
~/.config/cx/credentials.toml registry tokens only never

When a setting is given in several places, the most specific one wins:

  1. command-line flags (--offline, --jobs, --color)
  2. environment variables (CX_REGISTRY, CX_OFFLINE, ...)
  3. the project's .cx/config.toml
  4. your ~/.config/cx/config.toml

Settings

# .cx/config.toml
[registries]
default = "https://registry.example.com/index" # used by `fmt = "^11"`
internal = "https://cx.corp.example/index" # used by `{ registry = "internal" }`
[net]
offline = false # like --offline
retries = 2 # how often a failed request is retried (default 2)
[build]
jobs = 8 # like --jobs
compiler-cache = "auto" # sccache/ccache, see Build caches
artifact-cache = false # reuse built dependencies, see Build caches
[term]
color = "auto" # like --color: "auto", "always" or "never"
[toolchain] # compilers, see Toolchains (also [target.<triple>])
cxx = "clang++"
[source]
vendor = "vendor" # build from vendored sources (see Vendoring)
[audit]
database = "https://github.com/example/advisory-db" # for `cx audit`
[tools] # see External tools
cmake = "auto" # "auto", "system", "managed", or a program
clang-format = "managed"
[registries.signed] # the table form: an index plus trusted signing keys
index = "https://signed.example/index"
keys = ["ed25519:…"]
Key Type Environment variable Default
registries.default URL or path CX_REGISTRY none
registries.<name> URL or path CX_REGISTRY_<NAME> none
net.offline boolean CX_OFFLINE false
net.retries 0 to 100 2
build.jobs number number of CPUs
term.color "auto", "always", "never" NO_COLOR and friends (see Environment variables) "auto"
build.compiler-cache "auto", "sccache", "ccache", "none" or a program CX_COMPILER_CACHE "auto" (Build caches)
build.artifact-cache boolean CX_ARTIFACT_CACHE false (Build caches)
build.artifact-store URL or directory CX_ARTIFACT_STORE none (Build caches)
build.artifact-store-write boolean CX_ARTIFACT_STORE_WRITE false
build.artifact-keys list of "ed25519:<base64>" none: entries need no signature
build.artifact-signing-key file none: uploads aren't signed
cache.auto-gc an age like "90d", or "off" CX_CACHE_AUTO_GC off (Build caches)
source.vendor directory CX_VENDOR none (Vendoring)
audit.database git URL or directory CX_AUDIT_DB none (Security)
registries.<name>.keys list of "ed25519:<base64>" none (Security)
registries.<name>.credential-provider string or list (a provider) none (Credential providers)
registry.global-credential-providers list of providers ["cx:token"] (Credential providers)
tools.cmake, tools.ninja, tools.clang-format, tools.clang-tidy, tools.doxygen, tools.python, tools.scons, tools.vcpkg, tools.make, tools.autoreconf "auto", "system", "managed" or a program CX_CMAKE, CX_NINJA, CX_CLANG_FORMAT, CX_CLANG_TIDY, CX_DOXYGEN, CX_PYTHON, CX_SCONS, CX_VCPKG, CX_MAKE, CX_AUTORECONF "auto" (External tools)
tools.mirror URL or directory CX_TOOLS_MIRROR none (External tools)

A relative registry path (and a relative tools.* path) is relative to the directory that contains .cx/ (for the project file) or to ~/.config/cx/ (for the user file), not to the directory you run cx in.

Unknown keys get a warning, just as in cx.toml. A value of the wrong type is an error.

cx config

$ cx config list
build.jobs = 8 # user config `/home/me/.config/cx/config.toml`
registries.default = "https://registry.example.com/index" # project config `/src/app/.cx/config.toml`
token.internal = <hidden> # credentials `/home/me/.config/cx/credentials.toml`
$ cx config get registries.default
https://registry.example.com/index
$ cx config set build.jobs 4 # writes ~/.config/cx/config.toml
$ cx config set registries.default ../index --project # writes .cx/config.toml
$ cx config unset build.jobs

list shows each setting and where it came from, including environment variables. set and unset edit the file in place and keep its comments.

Credentials

Private registries need a token. Store one with cx login, which reads it from standard input:

$ cx login --registry internal
Paste the token for registry `internal` and press Enter:
$ echo "$TOKEN" | cx login # the default registry, e.g. in CI
$ cx logout --registry internal

The token goes to ~/.config/cx/credentials.toml, which only you can read (mode 0600):

[registries.internal]
token = "…"

In CI, set CX_TOKEN (default registry) or CX_TOKEN_<NAME> instead. They win over the file.

How cx handles tokens:

  • Where they go: a token is sent as Authorization: Bearer <token>, only to the host of that registry's index. It isn't sent to other hosts, even when the server redirects there or the archive URLs point elsewhere.
  • Where they don't go: tokens never appear in messages, in -v output or in cx config list.
  • File permissions: if credentials.toml can be read by other users, cx warns and ignores it, like ssh does. Fix it with chmod 600.
  • Rejected tokens: when a registry answers 401 or 403, the error says to run cx login.

Credential providers

Instead of credentials.toml, tokens can come from your operating system's credential store, a secret manager or a helper program. Configure a provider per registry, or a list of them for all registries:

# ~/.config/cx/config.toml
[registries.company]
index = "https://cx.example.com"
credential-provider = ["cx:token-from-stdout", "op", "read", "op://dev/cx-registry/token"]
[registry]
global-credential-providers = ["cx:keychain", "cx:token"]
Provider Where the token is
cx:token credentials.toml (the default)
cx:keychain the macOS keychain, the Windows Credential Manager, or the Secret Service on Linux (needs secret-tool from libsecret)
cx:token-from-stdout <COMMAND...> printed by the command, e.g. a secret manager's CLI; read-only
<COMMAND...> a helper program speaking the protocol below

A provider is a string (split at spaces) or a list of arguments. A registry's credential-provider replaces the global list for that registry. The providers are asked in order, and the first token wins. CX_TOKEN and CX_TOKEN_<NAME> still win over all of them. cx login and cx logout store and remove the token with the first provider.

Providers only run when a request to the registry's host needs a token, at most once per run, so a locked build with a warm cache never runs one.

Helper protocol. cx runs the helper with one request on standard input, as key=value lines:

action=get
registry=company
index-url=https://cx.example.com

action is get, store (with a token=... line) or erase. For get, the helper prints token=<TOKEN>, or nothing if it has no token. A non-zero exit is an error. Its output is never shown, and its standard error goes to the terminal.