kineuroExperimental Neuroradiology Research
Karolinska Institutet

The first registry

Make the key, initialise the registry, ask it what it holds, and read files again.

The wizard does this for you. This page is what it does, for when you would rather do it yourself.

A registry is a directory. It holds nils.toml, the databases (on SQLite), and the key store.

The key

Pseudonyms are derived from a key. The same subject digested twice under the same key gets the same code; under another key, another code. That is what makes two registries agree or disagree, so the key is the one secret that matters.

mkdir -p /srv/nils/registry
nils --registry /srv/nils/registry key add nils

The passphrase is read from standard input, one line. Choose it the way you choose a password and keep it where you keep passwords: without it you cannot rebuild the key store from a backup. The command prints the key’s name, its length and a fingerprint, and never the key itself. nils key list lists the keys the same way, as the desk’s Keys panel on Backups does.

Initialise

nils --registry /srv/nils/registry init --key nils

It prints the registry’s id, its schema version and its pseudonym scheme:

initialised /srv/nils/registry on sqlite: registry 2caa20b0-..., schema version 106,
pseudonyms blake2b-8 from key nils

blake2b-8 is the subject code generator: a person’s code is the keyed 8-byte BLAKE2b of their identifier (of a personnummer, its twelve digits) under the registry’s key, written as 16 hex characters. --scheme blake2b-32 makes a longer code instead. A registry keeps the scheme it was made with.

Ask it what it holds

nils --registry /srv/nils/registry status

A fresh registry says so plainly: epoch 0, no jobs, no batches. The epoch is the registry’s own clock; it moves when something changes what a question would answer.

NILS_REGISTRY in the environment saves typing --registry every time. The engine also accepts the flag after the subcommand for serve.

Reading a manufacturer’s files again

A newer engine may read more of a file than the one that digested it, such as PulseSequenceName (0018,9005) since 1.0.0-alpha.57, or a pack may come to read private elements it did not before. Rather than digest the whole archive again, re-read one manufacturer’s MR files:

nils digest /data/source --reread "GE MEDICAL SYSTEMS"
nils digest /data/source --reread "Siemens Healthineers" --reread-exact Siemens

It reads, without walking the tree, only the files the registry holds for that manufacturer’s MR series, every file of each series, a series at a time. Nothing is marked gone, and the fingerprints of those series are derived again. --reread compares the manufacturer without its case and --reread-exact with it, which matters for Siemens: its XA scanners write Siemens and its older ones SIEMENS, so --reread-exact Siemens takes the XA fleet alone. Both repeat.

A re-read that was stopped, failed or was killed is continued by the next one, which counts the files already written as unchanged and does not read them again; --restart starts over. It runs at the rate the parsers and the storage allow, so on a large archive it takes hours: some 17 million files took about seven hours at 670 files a second. Reclassify afterwards to let the pack read what was added.

Postgres instead of SQLite

For more than one machine, or for a registry that outgrows a file:

nils --registry /srv/nils/registry init \
  --backend postgres --dsn "postgres://nils@db.example.org/nils" --schema nils

The linkage store goes into <schema>_linkage. Everything else in this documentation is unchanged. The dsn may be left out of nils.toml and given as NILS_DSN at run time, so the password is not in a file.

A Postgres that runs in a container has 64 MB of shared memory unless it is given more, and on a large registry a question’s parallel workers ask for more than that. Since engine 1.0.0-beta.16 such a question is run again without parallel workers, so it is answered, more slowly. Give the container more for the faster answer:

podman run --shm-size=1g ... docker.io/library/postgres:17

The axes of a stack in one row

Since engine 1.0.0-beta.16 (schema 118) a question reads the axes of a stack from one row of stack_axis, a copy of the axis rows that every sort and pass keeps in the same transaction. The update fills it once, about ten seconds on five million axis rows. To hold the copy against the axis rows, and make it again where one differs:

nils --registry /srv/nils/registry repair stack-axis --dry-run   # says how they stand, writes nothing
nils --registry /srv/nils/registry repair stack-axis

Since engine 1.0.0-beta.20 (schema 119) that row also holds the stack’s series, whether it has a fingerprint, and the fingerprint columns a question filters stacks on (acquisition type, pixel spacings, slice thickness), so a set of stacks is read from one table. The update makes the table again and fills it, some seconds on half a million stacks. The database keeps the new columns itself, by triggers on stack and stack_fingerprint.

Note: a registry copied by hand loses the triggers. A table copied without them, a trigger dropped or switched off, or a dump restored under another schema’s name leaves the rows behind their sources. Every open of the registry by a command that writes looks for the triggers (one read of the database’s catalogue) and, where one is not set, sets them all again, makes every row again, says so on stderr and records a registry.repair audit row. repair stack-axis --dry-run shows how they stand without mending: triggers, triggers_missing, triggers_disabled and triggers_astray in its JSON. A registry put back from an archive is looked at the same way at its first open.

One word a value

Since engine 1.0.0-beta.23 a classification row holds one word for a value, the word the pack stores, whoever wrote it: the rules, a person’s decision, a model’s committed answer or an import. Before, a post-contrast decided by a person was stored as given where the rules stored 1, and a count made straight from the rows could differ from the answer to a question. Every earlier word still names its value in a question, a selection and a saved rule.

After the update, look at how the registry stands, then mend it:

nils --registry /srv/nils/registry status                       # counts the rows in an earlier word, by axis
nils --registry /srv/nils/registry repair axis-values           # says how many it would write, writes nothing
nils --registry /srv/nils/registry repair axis-values --apply   # writes each in the stored word

No stack changes the value it holds. A row of a sealed sample is left as it is and counted apart. A sort with the new pack writes the rows the rules decide, so the repair and a sort together leave no row in an earlier word.

Note: a system install names the packs. Where the packs are not beside the binary, give them in NILS_PACK_DIR or with --pack-dir, or status says no pack is installed.

Sessions after a merge

The sessions of a subject are a cache its readers build. Since engine 1.0.0-beta.23 a subject merge builds the sessions of the subject it leaves, and every question brings the cache up to date before it reads a session, so a merged subject is in every answer. To find and build the subjects that hold a study and have no session:

nils --registry /srv/nils/registry repair sessions --dry-run   # names them, writes nothing
nils --registry /srv/nils/registry repair sessions

Next: run it.

Updated 17 October 2026