From 461d6cc441f041ac9028e2810d1ac0730c0795d9 Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sun, 20 Sep 2026 18:35:13 +0200 Subject: [PATCH] fix(mars): deliver the ElevenLabs key through Hermes' .env The image's s6 init hands the gateway a fixed set of container env vars; ELEVENLABS_API_KEY is not one of them, so --env-file alone left text_to_speech reporting it unset even though the var was in the container config and the resolver read os.environ fine. prepare-dirs now merges the single line into ${hermesHome}/.env (HERMES_HOME=/opt/data), as uid 986 so root never writes into hermesHome, with the key on an fd opened as root so it stays out of argv and the journal. Co-Authored-By: Claude Opus 5 --- hosts/mars/hermes-agent.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index fe489f9..8e5f688 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -181,7 +181,7 @@ in wants = [ "network-online.target" ]; after = [ "network-online.target" ]; unitConfig.RequiresMountsFor = [ "/mnt/jupiter" ]; - path = [ pkgs.git pkgs.tea pkgs.curl pkgs.coreutils pkgs.yq-go ]; + path = [ pkgs.git pkgs.tea pkgs.curl pkgs.coreutils pkgs.yq-go pkgs.gnugrep pkgs.util-linux ]; serviceConfig.Type = "oneshot"; # Everything here is either local or bounded to ~30s by the probe loop, so # anything past two minutes is a hang, not slowness. @@ -265,6 +265,25 @@ in chmod --reference="$conf" "$conf.new" mv -f "$conf.new" "$conf" + # The image's s6 init hands the gateway a fixed set of container env vars, + # and ELEVENLABS_API_KEY isn't among them (OPENCODE_GO_API_KEY is) — so the + # key only reaches Hermes via .env, which load_env() reads directly. + # Re-asserted every start: a sops rotation must win over a stale line. + # 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} + if [ -d ${hermesHome}/.config ]; then chown ${hermesUid}:${hermesGid} ${hermesHome}/.config fi