No description
Find a file
YMRTECH 6445aede20 Hardened NixOS deployment layer for Hermes Agent
Three rules, each derived from a failure that is invisible until it is
expensive:

1. A credential in services.hermes-agent.settings is rendered from a nix
   store path and is therefore readable by every user on the host, in every
   generation. The module detects a credential pasted into settings by name
   and value shape, flags it by attribute path, and leaves upstream's
   key_env-by-environment-variable pattern alone. A guardtest configuration
   in the flake proves it fires on api_key and not on key_env.

2. Upstream defaults stateDir to /var/lib/hermes, which forces
   ProtectHome=false and lets the gateway read every home on the host. The
   module defaults state to /var/lib/hermes-agent so ProtectHome can stay
   raised, and lowers it with a warning if state moves back under /home.

3. The hardening table is the subset proven not to break a gateway that
   executes git, ssh, python and arbitrary tools. Every deliberate exclusion
   (namespace and device controls, MemoryDenyWriteExecute) is documented with
   the failure it would cause. A strict profile exists for deployments that
   execute nothing, and warns when selected.

Verified by evaluation, not by comment: both profiles render the expected
serviceConfig, ReadWritePaths carries no duplicate after removing a state
directory declaration upstream already makes, and nix flake check builds the
assertions for both profiles.
2026-11-12 12:19:18 -06:00
modules Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
tests Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
.gitignore Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
flake.lock Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
flake.nix Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
LICENSE Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00
README.md Hardened NixOS deployment layer for Hermes Agent 2026-11-12 12:19:18 -06:00

hermes-agent-nixos

A NixOS module that puts a Hermes Agent gateway behind the systemd controls that actually bind it — and writes down why each control that is not applied is deliberately absent.

Upstream already ships a working services.hermes-agent module. This is the layer around it: one hardening table, one rule about where secrets live, and one default about where state lives.

Unsupported, best effort. Issues are read and answered; there is no SLA, no response-time promise, and no guarantee that a future upstream release keeps working. MIT licensed. Not affiliated with, endorsed by, or supported by Nous Research.

Why this exists

Three things go wrong when an agent gateway is deployed declaratively, and all three are invisible until they are expensive.

1. A credential ends up in the nix store. services.hermes-agent.settings is rendered into the agent's config file out of a store path. A pasted API key there is readable by every user on the host, in every generation, for as long as the store survives. The correct pattern is upstream's own: the setting names an environment variable (key_env = "SOME_API_KEY") and the value is supplied to the unit at start. This module detects the wrong pattern and says so at evaluation time, by name and by path.

2. State sits in a home directory, so ProtectHome has to be off. Upstream defaults stateDir to /var/lib/hermes and the unit's HOME follows it, which forces ProtectHome=false — the gateway can then read every user's home on the host. Moving state to /var/lib/hermes-agent costs one setting and buys the control back. That is the default here.

3. The hardening table is copied from something that is not an agent. A gateway that executes git, ssh, python and arbitrary tools cannot be syscall-filtered the way a database can. A strict profile lifted from a daemon that never shells out produces a unit that dies at the first tool call, and the operator then deletes the whole table — which is worse than never having written it. So there are two profiles, and the exclusions are documented rather than silent.

Install

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    hermes-agent.url = "github:NousResearch/hermes-agent";
    hermes-agent.inputs.nixpkgs.follows = "nixpkgs";

    hermes-agent-nixos.url = "git+https://git.ymrtech.com/ymrtech/hermes-agent-nixos";
    hermes-agent-nixos.inputs.nixpkgs.follows = "nixpkgs";
    hermes-agent-nixos.inputs.hermes-agent.follows = "hermes-agent";
  };

  outputs = { nixpkgs, hermes-agent, hermes-agent-nixos, ... }: {
    nixosConfigurations.agent = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        hermes-agent.nixosModules.default
        hermes-agent-nixos.nixosModules.default
        ./configuration.nix
      ];
    };
  };
}
{
  services.hermes-agent = {
    enable = true;
    settings.model.default = "your-provider/your-model";
    # A provider block, as upstream documents it. Note key_env, not a key.
    # settings.<provider>.key_env = "SOME_API_KEY";
  };

  ymr.hermesAgent = {
    enable = true;
    profile = "standard";
    stateDir = "/var/lib/hermes-agent";
    runtimeEnvFile = "/var/lib/hermes-agent/runtime.env";
  };
}

The environment file is not created by this module, on purpose: a declared file with a declared key is still a key in the store wearing a different hat. Create it out of band — sops-nix, agenix, a secret manager, or by hand — owned by the service user at mode 0640.

What standard applies, and why

Control Why
ProtectSystem = "strict" The whole host filesystem is read-only inside the unit, root included. This is the one control a privileged process cannot walk around.
ReadWritePaths Upstream already declares the state directory and its workspace/ subdirectory from stateDir. This module adds only extraWritablePaths, and a check asserts the state path is still present — so an upstream change that drops it fails loudly instead of producing a unit that cannot write. ReadWritePaths unions with the unit's own declarations, so naming a path here can never remove one the service needs.
ProtectHome = "tmpfs" Homes are invisible, which is only possible because state left the home directory. Lowered to false with a warning if you put state back under /home or /root.
NoNewPrivileges = true No setuid escalation out of a tool call.
PrivateTmp = true Private /tmp and /var/tmp; tool scratch files are not shared with other units.
ProtectKernelTunables, ProtectKernelModules, ProtectKernelLogs, ProtectControlGroups The agent has no business loading modules, writing sysctls, reading the kernel log, or editing cgroups.
RestrictSUIDSGID, RestrictRealtime, LockPersonality, ProtectClock, ProtectHostname Cheap, and none of them interfere with tool execution.
UMask = "0007" Group-readable state, nothing world-readable.

What is deliberately absent

Each of these is a real control that a stricter deployment could use. None of them are applied, in either profile, for the stated reason.

Control Why it is off
RestrictNamespaces, PrivateUsers A Nix build inside the agent's sandbox uses user namespaces. Either one breaks nix build from a tool call — the most common thing an agent on a NixOS host does.
MemoryDenyWriteExecute Node needs W+X mappings for V8's JIT. Nearly every tool wrapper runs node.
PrivateDevices A GPU, a serial device or /dev/kvm disappears. Kept off rather than made configurable-by-hope.
RemoveIPC Breaks shared memory against other units on a mixed host.
ProtectProc = "invisible" Hides sibling processes. Some wrappers read /proc for their children; the failure mode is a hang, not an error.
LockdownMode, SystemCallArchitectures = "native" Left to the host, which knows its own userland and preloads.

The strict profile adds SystemCallFilter = [ "@system-service" ], SystemCallErrorNumber = "EPERM", an empty CapabilityBoundingSet and RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]. It is appropriate only where the agent does not build anything and does not create namespaces; the module warns about that when you select it.

Verify what you actually got

The profile is evaluated, not asserted in a comment. Inspect the rendered unit:

nix eval .#nixosConfigurations.selftest.config.systemd.services.\"hermes-agent\".serviceConfig
nix eval .#nixosConfigurations.selftest-strict.config.systemd.services.\"hermes-agent\".serviceConfig
nix flake check    # runs the assertions over both profiles

Known limits

  • This is not a jail. An agent that executes arbitrary tools is a code execution surface by design. These controls bound what a compromised tool call can reach; they do not make it safe to point at anything you would not run yourself.
  • No health check, no backup, no edge. A probe is only worth shipping once its path is known to exist; session history is not the valuable artifact — settings, skills and procedures are, and those belong in git.
  • Container mode is out of scope. Upstream's OCI mode manages its own sandbox; the module refuses strict there and warns.