diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index dd26b79..c37e1d7 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -272,17 +272,28 @@ in # setpriv because root must not write into hermesHome — luna could plant a # symlink there. The key arrives on an fd opened while still root, so it # never lands in argv or the journal and her uid needs no /run/secrets access. - setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \ - ${pkgs.runtimeShell} -c ' - set -eu - envf=$1 - umask 077 - key=$(cat) - [ -e "$envf" ] || : > "$envf" - { grep -v "^ELEVENLABS_API_KEY=" "$envf" || true - printf "ELEVENLABS_API_KEY=%s\n" "$key"; } > "$envf.new" - mv -f "$envf.new" "$envf" - ' _ ${hermesHome}/.env < ${config.sops.secrets.elevenlabs_api_key.path} + # + # API_SERVER_KEY is in the same boat, confirmed the same way: with it set + # only in the container env the server came up (so API_SERVER_ENABLED/HOST + # DID pass through) but answered every bearer token with + # "Invalid gateway API key" — the passthrough list carries the plain + # API_SERVER_* vars and drops the secret one. + write_env_key() { + setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \ + ${pkgs.runtimeShell} -c ' + set -eu + envf=$1 + name=$2 + umask 077 + key=$(cat) + [ -e "$envf" ] || : > "$envf" + { grep -v "^$name=" "$envf" || true + printf "%s=%s\n" "$name" "$key"; } > "$envf.new" + mv -f "$envf.new" "$envf" + ' _ ${hermesHome}/.env "$1" + } + write_env_key ELEVENLABS_API_KEY < ${config.sops.secrets.elevenlabs_api_key.path} + write_env_key API_SERVER_KEY < ${config.sops.secrets.hermes_api_server_key.path} if [ -d ${hermesHome}/.config ]; then chown ${hermesUid}:${hermesGid} ${hermesHome}/.config diff --git a/hosts/mars/secrets.nix b/hosts/mars/secrets.nix index a20cb03..46deba0 100644 --- a/hosts/mars/secrets.nix +++ b/hosts/mars/secrets.nix @@ -40,6 +40,18 @@ sops.secrets.gitea_hermes_webhook_secret = { restartUnits = [ "hermes-agent-webhook-routes.service" ]; }; + # Bearer token for the OpenAI-compatible API server (see the env template + # below). Same value in secrets/terra.yaml, where luna-voiced reads it. + # API_SERVER_HOST=0.0.0.0 for the same reason the dashboard binds it (see + # hermes-agent.nix): the container is --network=host and nothing opens 8642 + # in the firewall, so it is reachable over tailscale0 only — LAN-closed. + # prepare-dirs writes it into luna's .env (the container env alone does not + # reach the gateway — see hermes-agent.nix); the container then has to come + # back up to read it. + sops.secrets.hermes_api_server_key.restartUnits = [ + "hermes-agent-prepare-dirs.service" + "podman-hermes-agent.service" + ]; sops.templates."hermes-agent.env".content = '' OPENCODE_GO_API_KEY=${config.sops.placeholder.opencode_go_api_key} TELEGRAM_BOT_TOKEN=${config.sops.placeholder.telegram_bot_token} @@ -49,6 +61,10 @@ WEBHOOK_PORT=8644 HERMES_DASHBOARD_OIDC_CLIENT_SECRET=${config.sops.placeholder.hermes_dashboard_oidc_client_secret} ELEVENLABS_API_KEY=${config.sops.placeholder.elevenlabs_api_key} + API_SERVER_ENABLED=true + API_SERVER_HOST=0.0.0.0 + API_SERVER_PORT=8642 + API_SERVER_KEY=${config.sops.placeholder.hermes_api_server_key} ''; # luna's gitea push token (services/dev/gitea.nix provisions the account +