Expand description
Typed border for the nix-daemon worker protocol.
When a nix client (nix build, nix-env, nix-store --realise)
needs to mutate the store, it doesn’t write /nix/store itself
— it connects to the nix-daemon over a unix socket and speaks
the worker protocol. cppnix’s libstore/worker-protocol.cc
defines ~30 opcodes covering the full read+write surface of the
store.
Today sui-daemon implements this protocol in Rust; this module names the wire contract as a typed Lisp spec so any future client (or any third-party daemon) rides on the same authored shape. Both engines (sui’s client side + sui-daemon’s server side) drive the same spec — they cannot drift.
§Authoring surface
Two keyword forms compose:
(defworker-protocol ...)declares the protocol version + handshake (magic bytes, version negotiation).(defworker-opcode ...)declares ONE opcode per form: numeric code, direction, request-field types, response-field types, feature gate. ~30 opcodes today; new ones land as additional(defworker-opcode)forms.
Example:
(defworker-protocol
:name "cppnix-worker-protocol"
:version 35
:magic-client "0x6e697863" ;; "nixc"
:magic-server "0x6478696f") ;; "dxio"
(defworker-opcode
:name "QueryPathInfo"
:code 29
:direction ClientToDaemon
:request-fields (StorePath)
:response-fields (PathInfo)
:since-version 17)Structs§
- Dispatch
Outcome - Result of dispatching a worker-protocol opcode against a handler.
- Worker
Opcode - One worker-protocol opcode.
- Worker
Protocol - One worker-protocol version. Typically there’s one entry per major nix release (v23, v25, v27, v33, v35).
Enums§
- Opcode
Direction - Direction of an opcode call.
- Wire
Type - Wire-level field type — the primitive types the worker protocol
can serialise. Length-prefixed strings + 8-byte LE integers
per cppnix’s
worker-protocol.ccWORKER_MAGICframing.
Constants§
Traits§
- Worker
Protocol Handler - Abstract handler for the worker protocol’s server side. Each
opcode dispatches to a corresponding method here; the default
implementation returns a typed
unhandled-opcodeerror so an incomplete handler surfaces missing opcodes loudly.
Functions§
- apply
- Dispatch one wire-arriving opcode against a handler. Looks up
the opcode by code in the canonical catalog, then routes to
handler.dispatch. - load_
canonical_ opcodes - Compile every authored opcode.
- load_
canonical_ protocols - Compile the canonical worker-protocol version envelope(s).
- load_
opcode_ by_ code - Return the opcode with the given
code. - load_
opcode_ named - Return the opcode whose
namematches.