Skip to content

nix: add a NixOS module for dmq-node - #84

Open
manveru wants to merge 3 commits into
IntersectMBO:mainfrom
manveru:nixos-module
Open

manveru wants to merge 3 commits into
IntersectMBO:mainfrom
manveru:nixos-module

Conversation

@manveru

@manveru manveru commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

List of changes

  • Add: nixosModules.dmq-node (alias default) in nix/nixos/dmq-node-service.nix, and overlays.default, which provides pkgs.dmq-node.
  • Add: a README section on the module.

The module is meant to run next to the services.cardano-node module from cardano-node 11.2+, as it would in iohk-nix and cardano-parts:

services.dmq-node = {
  enable = true;
  networkMagic = 4242;
  cardanoNodeConfig = config.services.cardano-node.nodeConfig;
  cardanoNodeSocketPath = config.services.cardano-node.socketPath 0;
  topology = { ... };
  traceOptions."" = { backends = [ "Stdout MachineFormat" ]; severity = "Info"; };
};
  • cardanoNodeConfig takes the node's config attrset as it is. The module takes the genesis file and its hash from it, and reads the network magic from that genesis file, so you set them only once.
  • cardanoNodeSocketGroup (default cardano-node) is added to SupplementaryGroups, which gives the service access to the node socket without running as the node user.
  • dmq-node exits when it can't connect to cardano-node. The unit therefore starts it only once the node socket accepts connections, and restarts it every 10 s without a start limit.
  • user and group both default to dmq-node and are created only while left at that default.
  • package defaults to this flake's dmq-node.
  • openFirewall is a separate option, as in nixpkgs modules.
  • topology and traceOptions are required and link to their documentation. dmq-node crashes when TraceOptions is missing.
  • extraSettings adds any other config key; the module asserts that none of them collide with a key the module sets.
  • socketPath is read-only, under RuntimeDirectory.
  • The unit runs with systemd hardening.

The module file uses only nixpkgs, so iohk-nix or cardano-parts can import it directly and supply their own package.

Tested by evaluating a NixOS system that uses the module, and by the two-pool VM test proposed separately.

Checklist

  • My changes generate no new warnings
  • My code follows the style guidelines of this project (nixpkgs-fmt gate passes)
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works (VM test in the follow-up PR)

Exports nixosModules.dmq-node and overlays.default.

@coot coot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked codex for a review:

• The documented NixOS setup fails as a standalone module, and fixing the import alone can still leave DMQ waiting forever on a healthy Cardano node because
its socket is not group-writable. Several otherwise valid Cardano configurations also fail evaluation or produce a service that cannot start.

Full review comments:

• [P1] Grant the DMQ account write access to the Cardano socket — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:276-276
With the upstream cardano-node service's default non-socket-activated setup, systemd's 0022 umask leaves the socket at 0755. Linux requires write
permission to connect, so joining cardano-node is insufficient: the socat probe gets EACCES and waits forever even though Cardano is listening. Include
a producer-side socket ACL or group-writable mask in the documented setup; the UMask on this unit only affects DMQ's own socket.

• [P2] Bind the flake inputs in the NixOS example — /home/work/clients/iog/dmq-node/README.md:167-168
Copied into a NixOS module, this example fails with undefined variable 'inputs'. The ... accepts extra arguments but does not bind their names, even
when the caller supplies inputs via specialArgs. Bind inputs explicitly and show how it is passed, or put the import in the flake's nixosSystem.modules
list where the input is already in scope.

• [P2] Resolve relative Shelley genesis paths against the Cardano config — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:23-24
Passing a flat config read from Cardano's published mainnet-config.json fails here: its ShelleyGenesisFile is mainnet-shelley-genesis.json. Cardano
resolves that relative to the config file, but builtins.readFile rejects the relative string. Accept a config path or base directory for resolution, or
show callers how to normalize this field to a Nix path before passing the attrset.

• [P2] Accept Cardano configurations without a Shelley genesis hash — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:30-30
Valid private-network configs, including Cardano's testnet template, omit ShelleyGenesisHash. Both cardano-node and DMQ.Genesis.readGenesis support
this, but the module throws during evaluation. An explicitly null hash already works because configFile filters it out. Treat an absent hash the same
way while preserving verification whenever a hash is supplied.

• [P2] Keep the configured Cardano socket visible inside the unit — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:284-285
A listening, group-writable socket at /tmp/cardano-node.socket is still invisible to the probe because PrivateTmp gives it a different /tmp. ProtectHome
similarly hides sockets under /home and /run/user. In either case the unit reports itself active but never starts DMQ. Expose the configured socket's
directory to the unit, or reject these locations at evaluation with guidance to use a shared path under /run.

• [P2] Account for per-instance Cardano genesis overrides — /home/work/clients/iog/dmq-node/README.md:172-173
If extraNodeConfig or extraNodeInstanceConfig 0 overrides the genesis, nodeConfig here is only the base configuration. The Cardano service merges the
overrides before starting instance 0, while DMQ derives its network magic from the original genesis and can fail the handshake on the very socket
selected below. Show how to pass the effective config, or qualify this example for nodes without genesis overrides.

• [P2] Check the outer type of topology and settings — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:151-152
For example, topology = ./topology.json; passes json.type, but json.generate writes a JSON string containing the store path, not the topology object.
The system evaluates successfully and readTopologyFile then fails on every start. Restrict object-valued options (topology, traceOptions, and
extraSettings) to types.attrsOf json.type, or handle topology files explicitly rather than serializing their paths.

• [P2] Handle privileged ports for the default service account — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:135-138
On a host with the standard net.ipv4.ip_unprivileged_port_start=1024, setting port = 443 passes evaluation and can open the firewall, but the non-root
DMQ process has no CAP_NET_BIND_SERVICE. It fails at bind and restarts indefinitely. Grant the capability conditionally for privileged ports or reject
that configuration explicitly.

• [P3] Limit networkMagic to an unsigned 32-bit value — /home/work/clients/iog/dmq-node/nix/nixos/dmq-node-service.nix:84-84
types.ints.unsigned accepts 4294967296, but the binary rejects the resulting NetworkMagic because it decodes to Word32. This turns an option error into
a restart loop after activation. Use types.ints.u32 to report it during Nix evaluation instead.

Fail on unwritable or sandbox-hidden node sockets and relative genesis paths;
optional genesis hash, object-typed JSON options, u32 magic, bind cap below 1024.
@manveru

manveru commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all nine addressed in 2be7731:

  • [P1] socket write access — The module stays out of cardano-node's unit. The cardanoNodeSocketGroup docs and the README now name the three producer-side fixes (systemdSocketActivation, cardano-parts' shareNodeSocket, UMask = "0007"), and the README example enables socket activation. The wait script now fails the start with a hint when the socket exists but is not writable, instead of waiting forever.
  • [P2] inputs in the README — The example now shows the module in a flake's nixosSystem { modules = [ … ]; }.
  • [P2] relative genesis path — Rejected at evaluation with the value and an override example (// { ShelleyGenesisFile = ./mainnet-shelley-genesis.json; }); an attrset no longer knows where its config file was.
  • [P2] missing ShelleyGenesisHash — Now optional, as in cardano-node and readGenesis; a supplied hash is still verified.
  • [P2] socket under /tmp, /home, /run/user — Asserted against at evaluation. The hidden directories are derived from the same attrset that sets PrivateTmp/ProtectHome.
  • [P2] per-instance genesis overrides — Documented on cardanoNodeConfig, with the merge expression to pass instead. The proper fix is for the cardano-node module to expose its effective instance config; we'll propose that upstream.
  • [P2] outer type of topology etc. — topology, traceOptions and extraSettings are now attrsOf json.type; a path fails evaluation, and the docs point to lib.importJSON.
  • [P2] privileged ports — CAP_NET_BIND_SERVICE is granted (ambient and bounding set) only for ports below 1024; otherwise the bounding set is empty.
  • [P3] networkMagic — types.ints.u32.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants