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.
Where nvs finds the file
Section titled “Where nvs finds the file”nvs uses the first of these that exists:
- the files that
--confignames. You can give--configmore than once. Thennvsreads no othernvs.toml. nvs.tomlin the folder you runnvsin.nvs.tomlin the data folder. This is the folder.nvsdatanext to thenvsprogram, or the folder that--datanames.- 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.
Start with nvs init
Section titled “Start with nvs init”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.
What the file controls
Section titled “What the file controls”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 withwall_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 filewrite = ["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.
What a program may do with no nvs.toml
Section titled “What a program may do with no nvs.toml”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 readingwrite = [] # no writing
[capabilities.net]connect = ["api.example.com"] # only this hostinternal = ["10.0.0.0/8"] # private addresses or ranges that are allowedOne file, several applications
Section titled “One file, several applications”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"Change a setting without editing nvs.toml
Section titled “Change a setting without editing nvs.toml”Write the settings you want to change in a second file. Then name both files with --config:
[limits]memory = "256M"nvs serve public/index.nvs --config nvs.toml --config /etc/nvs/override.tomlA 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 errorEvery 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.
Your program’s own settings and secrets
Section titled “Your program’s own settings and secrets”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 intshop_name = "Example Shop" # a string
[settings.api]base = "https://api.example.com"
[secrets]api_key_file = "/run/secrets/api_key" # the file contains the valueCore\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";20https://api.example.comCore\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:
[settings]page_size = 20
[[include]]path = "/etc/nvs/this-server.toml"optional = true[settings]page_size = 50On that server page_size is 50. On every other server it is 20.
Check it before you deploy
Section titled “Check it before you deploy”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 checkreads the file and reports every error. It also warns about a key in the four blocks that no program reads.nvs config dump --originprints 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 worddefault.
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 and don’t
Section titled “Do and don’t”- Do commit
nvs.tomlwith 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 checkin 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. Usepassword_fileto read it from a separate file. - Don’t grant
truefor a capability when a list of folders or hosts is enough.
Read every key in Reference: configuration.
