Skip to content

Configuration

All configuration is in TOML files. Usually there is one file, nvs.toml. Novis reads no setting from an environment variable. Two command-line options change a setting: --listen and --port of nvs serve.

nvs uses the first of these that exists:

  1. the files that --config names. You can give --config more than once. Then nvs reads no other nvs.toml.
  2. nvs.toml in the folder you run nvs in.
  3. nvs.toml in the data folder. This is the folder .nvsdata next to the nvs program, or the folder that --data names.
  4. the built-in defaults. Each request may use up to 128M of memory. Read What a program may do with no nvs.toml for the rest.

When nvs run, nvs serve, nvs test, nvs build or nvs check finds no file, it writes nvs.toml into the data folder. It never writes into your project. --no-init stops it from writing the file. Novis updates this file when you update Novis, unless you changed it. After you change it, Novis never touches it again.

nvs init writes an nvs.toml into the folder you run it in, or to the path that --config names. Every key is in the file, and each one is commented out. Each line ends with a short note. # default means Novis uses the value shown when the key is not set. Remove the # from a line to set that key.

A setting is always inside a block. These are the blocks you need first:

[mode]
default = "production" # or "development"
[limits]
memory = "128M" # what each request starts with
wall_time = "30s"
[limits.hard]
memory = "256M" # the most a request may raise itself to
[capabilities.fs]
read = ["data"] # folders the program may read, relative to this file
write = ["data/uploads"]
[server]
listen = ["127.0.0.1:8000"]

The [capabilities] blocks say which files, hosts and programs your code may use. A call that is not allowed throws a RuntimeError. The message shows the exact line to add to nvs.toml.

A [[server.mount]] block serves one program at a path or a host. To serve many programs from one nvs.toml, read Many modules on one server.

A relative path in the file is relative to the folder of the file. It is not relative to the folder you run nvs in.

Novis has two kinds of run. A CLI run is nvs run, a #[Command] method or nvs test. Server work is a request, a connection, a scheduled run or a queued job. The app folder is the folder of the entry file. If an [[app]] block with root matches, the app folder is that root.

CLI run Server work
Read files any file the app folder, except names that start with . and files named nvs.toml
Write files any file only folders that Core\IO::createTemporaryDirectory created for this run
Connect any public host, and 127.0.0.1 or ::1 any public host. 127.0.0.1 and ::1 work only in development mode
Run a program any program. A name such as git is found on PATH none
Start a script a script in the app folder a script in the app folder
Memory starts at 128M. Your code may raise it with Core\Config::set('memory', ...) if [limits.hard] sets no memory 128M

A private address, such as 10.0.0.5, always needs an internal line. Code from a package never gets these defaults. It gets only the line for its own package.

When you write a key, its value replaces the default completely. Write only what the program uses:

[capabilities.fs]
read = ["public/"] # only this folder. read = [] allows no reading
write = [] # no writing
[capabilities.net]
connect = ["api.example.com"] # only this host
internal = ["10.0.0.0/8"] # private addresses or ranges that are allowed

An [[app]] block sets values for one folder or one file. A later, more specific block replaces a value from an earlier one. So one application can have a lower limit. It can also have fewer permissions than the others.

[[app]]
entry = "jobs/nightly.nvs"
[app.limits]
memory = "64M"

Write the settings you want to change in a second file. Then name both files with --config:

/etc/nvs/override.toml
[limits]
memory = "256M"
Terminal window
nvs serve public/index.nvs --config nvs.toml --config /etc/nvs/override.toml

A later file replaces each key that it sets. Here memory is 256M. wall_time and every other key keep their values from nvs.toml. Name nvs.toml too, because with --config, nvs does not read it by itself.

A list is one value. If the second file sets read = ["data"], then data is the only folder. A block with two brackets, such as [[app]], is different. Each one adds an entry.

An [[include]] block does the same from inside a file. The included file is read after the file that includes it, so its keys replace the keys of that file:

[[include]]
path = "local.toml"
optional = true # a missing local.toml is not an error

Every file must belong to the account that runs nvs serve, or to root. No other account may write to the file or to its folder. Otherwise nvs serve stops with the error E0607. A file can grant capabilities, so this check protects it.

Four blocks are for your own values: [settings], [secrets], [app.settings] and [app.secrets]. You choose the key names. A key name has letters, digits and _, and it does not start with a digit.

[settings]
page_size = 20 # an int
shop_name = "Example Shop" # a string
[settings.api]
base = "https://api.example.com"
[secrets]
api_key_file = "/run/secrets/api_key" # the file contains the value

Core\Config::setting returns a value with its type from the file. A number is an int or a float, and true is a bool. A block such as [settings.api] is an array. Read one of its keys with a dot: api.base. The result is null when no block sets the name.

<?nvs
// This program reads two settings from `nvs.toml`.
int $size = Core\Config::setting('page_size') as int;
// `api.base` is the `base` key under `[settings.api]`.
string $base = Core\Config::setting('api.base') as string;
echo $size, "\n", $base, "\n";
Output
20
https://api.example.com

Core\Config::secret returns a secret string. Your program can send it in a request header or use it as a database password. It cannot print it or write it to a log. Write a secret in the file, or write name_file with the path of a file that contains it.

[app.settings] and [app.secrets] under an [[app]] block are for that application only. Each key replaces the same key from [settings] or [secrets].

To use other values on one server, put them in a file on that server and include it:

nvs.toml
[settings]
page_size = 20
[[include]]
path = "/etc/nvs/this-server.toml"
optional = true
/etc/nvs/this-server.toml
[settings]
page_size = 50

On that server page_size is 50. On every other server it is 20.

A key that Novis does not know stops the program before it starts, with the error E0601. So a typo in a key always gives an error message.

  • nvs config check reads the file and reports every error. It also warns about a key in the four blocks that no program reads.
  • nvs config dump --origin prints every key in force, and the file that set it. When a later file replaced a key, it names both files. A key that no file sets shows its default value and the word default.

Both commands read the files you list, in the order you list them: nvs config dump --origin nvs.toml /etc/nvs/override.toml.

A program can read a setting with Core\Config::get. It returns the value in force. For a key the file does not set, that is the built-in default, such as 128M for memory. A program can change some settings for one request with Core\Config::set. The page of Core\Config::set lists the settings a request may change. Read Limits for an example.

  • Do commit nvs.toml with your code, so every server runs the same settings.
  • Do give each capability only the folders and hosts the program really uses.
  • Do run nvs config check in your build, before each deploy.
  • Do put the settings that differ on one server in a second file. Don’t edit a copy of nvs.toml.
  • Don’t write a password in nvs.toml. Use password_file to read it from a separate file.
  • Don’t grant true for a capability when a list of folders or hosts is enough.

Read every key in Reference: configuration.