dinix examples¶
Every file under examples/ is a complete dinix configuration. It evaluates on
its own, and dev.nix wraps each one in a runner that starts dinit and opens
the TUI on it.
nix run --file ./dev.nix examples.services.redis
The runner makes a temporary runtime directory and points DINIX_STATE_DIR at
a writable one, so a service that keeps state needs nothing set up.
A file runs without the TUI as well. Then you choose both directories:
DINIX_STATE_DIR=$PWD/state nix run --file ./examples/services/redis.nix config.userWrapper -- --user
What each one shows¶
Example |
Shows |
|---|---|
|
the quick start: two services, one process and one internal |
|
|
|
automatic restart, with the limit lifted |
|
the |
|
|
|
|
|
redis, from the modular-service port |
|
postgres, with |
|
nginx, serving a store path |
|
memcached, the simplest port |
|
a container image, built by |
|
a container image for nginx |
|
what |
|
a modular service defined inline |
Containers¶
dev.nix builds the container images with nix2container and loads them with
podman:
nix run --file ./dev.nix containers.redis.copyToPodman
podman run --rm -it -p 6379:6379 dinix-example-redis:latest
The entrypoint is config.containerWrapper: dinit as PID 1, reading its
services from the store, in an image with no shell and no writable root.
The API¶
An example is an import ../.. { modules = [ ... ]; }. The result carries the
evaluated configuration, so you can build any piece of it:
nix build --file ./examples/api/usage.nix config.configDir
nix build --file ./examples/api/usage.nix config.containerWrapper
examples/api/usage.nix lists the attributes and what each one is for.
TUI keys¶
Key |
Action |
|---|---|
|
start the selected service |
|
stop the selected service |
|
restart the selected service |
|
reload the selected service's description |
|
print the selected service's log |
|
follow the selected service's log (poll the buffer) |
|
nix reload: rebuild and adopt the new configuration |
|
reload all: rebuild, reload, and restart every running service |
|
refresh the service list |
|
quit |
Editing and nix reload¶
n runs a rebuild command, points the runtime at its output, and reloads every
service. The runner wires that command to nix build --file <this example> config.configDir, so an edit to the file is picked up on n. The new
description applies at the next start: press r to restart one service, or A
to rebuild and restart everything at once.
The rebuild's own output streams into the log pane, prefixed nix|, so a slow
evaluation shows progress instead of a silent wait.
For a project of your own, set DINIX_TUI_NIX_COMMAND to a command that
builds your configuration and prints its config directory. The wrapper's
dinit searches <DINIX_RUNTIME_DIR>/current before the store, which is the
pointer n repoints.