From 524315f495f8a7c57b98122792e1a97d28b237be Mon Sep 17 00:00:00 2001 From: luna Date: Sat, 19 Sep 2026 12:09:03 +0000 Subject: [PATCH 1/6] mars: add KittenTTS voice provider (CPU-only, offline mini model) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tts.provider: kittentts, voice Luna, mini-0.8 model (80M params) per darman. CPU-only onnxruntime inference — no GPU on mars, validated ~1x realtime on a weaker dev box. Upstream's misaki[en]+spacy declaration is deliberately not honored (pulls torch→CUDA, 5.6 GB); a .pth-registered stub satisfies the dead misaki import, failing loudly if it is ever actually used. HF model cache pre-seeded from hash-pinned store paths so HF_HUB_OFFLINE=1 runs with zero boot-time network. Provisioner shaped by the Mnemosyne review: uv venv --clear, root never executes python from the venv, ownership to the container uid before anything imports, stamp checked against venv+model files. --- hosts/mars/hermes-agent.nix | 113 +++++++++++++++++++++ hosts/mars/kittentts/kitten-misaki-stub.py | 34 +++++++ hosts/mars/kittentts/requirements.txt | 69 +++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 hosts/mars/kittentts/kitten-misaki-stub.py create mode 100644 hosts/mars/kittentts/requirements.txt diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index 0d84e48..53b0950 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -77,6 +77,33 @@ let # Mnemosyne memory provider: third-party plugin, not in the image. mnemosyneEnv = pkgs.callPackage ../../pkgs/mnemosyne-env.nix { }; + # KittenTTS voice provider inputs (CPU-only; model + wheel hash-pinned). + # Provisioning unit near the bottom of this file; background on why the + # deps deviate from upstream's declaration lives in + # ./kittentts/requirements.txt + ./kittentts/kitten-misaki-stub.py. + kittenttsWheel = pkgs.fetchurl { + url = "https://github.com/KittenML/KittenTTS/releases/download/0.8.1/kittentts-0.8.1-py3-none-any.whl"; + sha256 = "sha256-SCpDbE8fMZIVNxA3bkWf82iVF+vNp8KwUeL9QYe0GFE="; + }; + kittenttsReqs = pkgs.writeText "kittentts-requirements.txt" ( + builtins.readFile ./kittentts/requirements.txt + ); + kittenttsStub = pkgs.writeText "kitten-tts-stub.py" ( + builtins.readFile ./kittentts/kitten-misaki-stub.py + ); + kittenttsModelOnnx = pkgs.fetchurl { + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/kitten_tts_mini_v0_8.onnx"; + sha256 = "sha256-D1u65PxIAMmNvFRKh+z6eVEN4vuCItsw0S5b/pF335E="; + }; + kittenttsModelVoices = pkgs.fetchurl { + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/voices.npz"; + sha256 = "sha256-QK0mOJUrd7ey8wEn4mCOFp/GndJWtTvYqqNAmjMZPEI="; + }; + kittenttsModelConfig = pkgs.fetchurl { + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/config.json"; + sha256 = "sha256-axYLybGeJOyyHoS8FPin2iH99H7HLUJFC8XPUUthgEo="; + }; + # Wire event names (X-GitHub-Event) each route accepts — NOT the # subscription names the gitea hooks in services/dev/gitea.nix use. The two # namespaces collide; see the long comment on the route unit below. @@ -450,4 +477,90 @@ in chown -h ${hermesUid}:${hermesGid} "$pluginDir" ''; }; + + # ---- KittenTTS voice provider ------------------------------------------ + # CPU-only onnxruntime TTS (no GPU on mars), mini model per darman. The + # upstream `misaki[en]` declaration is deliberately not honored — it pulls + # torch→CUDA (5.6 GB verified); the runtime phonemizes with espeak-ng only, + # so the dead `from misaki import en, espeak` import is satisfied by a + # .pth-registered stub (kitten-misaki-stub.py) that fails loudly if misaki + # is ever actually used. + # + # Provisioner invariants (shaped by the Mnemosyne-round review): + # - `uv venv --clear`: re-provision cannot wedge on an existing dir. + # - Root runs NO python from this venv: the unit itself does only fs + # writes; the venv is chowned to the container uid before Hermes ever + # imports from it. (Hermes executes provider code as uid 986.) + # - HF model cache is PRE-SEEDED from hash-pinned store paths, so + # HF_HUB_OFFLINE=1 gives zero boot-time network and no drift. + # - Idempotent via a stamp keyed on the requirements hash; checked + # against BOTH the venv python and model files being intact. + # + # Trust boundary: the venv lives inside hermesHome (HERMES_WRITE_SAFE_ROOT), + # so luna can technically alter her own TTS engine. Deliberate: it's her + # voice, not her jail — the webhook filter scripts remain the only + # write-protected-but-load-bearing items. + systemd.services.hermes-agent-kittentts-provision = { + description = "Provision KittenTTS voice provider (side venv + offline HF cache)"; + before = [ "podman-hermes-agent.service" ]; + wantedBy = [ "podman-hermes-agent.service" ]; + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + path = [ pkgs.uv pkgs.coreutils ]; + serviceConfig = { + Type = "oneshot"; + TimeoutStartSec = 600; + }; + script = '' + set -euo pipefail + + venv=${hermesHome}/kittentts-venv + hubDir=${hermesHome}/kittentts-hf/hub/models--KittenML--kitten-tts-mini-0.8 + snap=$hubDir/snapshots/kitten + stampFile=${hermesHome}/kittentts-provision.stamp + reqHash=$(sha256sum ${kittenttsReqs} | cut -d' ' -f1) + + # Idempotent early exit: stamp + venv + all three model files intact. + if [ -f "$stampFile" ] && [ "$(cat "$stampFile")" = "$reqHash" ] \ + && [ -x "$venv/bin/python" ] \ + && [ -f "$snap/kitten_tts_mini_v0_8.onnx" ] \ + && [ -f "$snap/voices.npz" ] \ + && [ -f "$venv/lib/python3.13/site-packages/kitten_tts_stub.py" ]; then + exit 0 + fi + + # Venv (rebuilt rather than broken on --no-clear: uv exits 2 otherwise). + uv venv "$venv" --python ${pkgs.python313}/bin/python3 --clear --quiet + UV_CACHE_DIR=${hermesHome}/kittentts-uv-cache \ + uv pip install --python "$venv/bin/python" --quiet \ + --requirement ${kittenttsReqs} + # kittentts --no-deps: its overlay of spacy/misaki[en] is what drags in + # the CUDA tree; the requirements freeze already covers its real needs. + UV_CACHE_DIR=${hermesHome}/kittentts-uv-cache \ + uv pip install --python "$venv/bin/python" --quiet --no-deps \ + ${kittenttsWheel} + + # Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter start + # so `from misaki import en, espeak` resolves without the real misaki.en. + siteDir=$("$venv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') + cp ${kittenttsStub} "$siteDir/kitten_tts_stub.py" + printf 'import kitten_tts_stub\n' > "$siteDir/zz-kitten-stub.pth" + + # Seed the HF cache with the hashed model files (exact hub layout; + # hf_hub_download scans refs/snapshots on disk offline). + mkdir -p "$hubDir/refs" "$snap" + install -m 0444 ${kittenttsModelOnnx} "$snap/kitten_tts_mini_v0_8.onnx" + install -m 0444 ${kittenttsModelVoices} "$snap/voices.npz" + install -m 0444 ${kittenttsModelConfig} "$snap/config.json" + + # Hand ownership to the container uid BEFORE any python runs in this + # tree (root never imports from it — that was Mnemosyne review #3). + chown -R ${hermesUid}:${hermesGid} "$venv" "$hubDir" + + # Stamp LAST — a half-provisioned venv fails the integrity check and + # re-provisions on next boot rather than being trusted. + printf '%s' "$reqHash" > "$stampFile" + chown ${hermesUid}:${hermesGid} "$stampFile" + ''; + }; } diff --git a/hosts/mars/kittentts/kitten-misaki-stub.py b/hosts/mars/kittentts/kitten-misaki-stub.py new file mode 100644 index 0000000..bdc4fa8 --- /dev/null +++ b/hosts/mars/kittentts/kitten-misaki-stub.py @@ -0,0 +1,34 @@ +# Runtime shim for KittenTTS on a CPU-only, disk-constrained host. +# +# kittentts/onnx_model.py opens with `from misaki import en, espeak` — a dead import: +# every code path that produces audio from text goes through phonemizer-fork's +# EspeakBackend (espeak-ng via espeakng-loader); misaki.en/espeak are never called. +# If misaki[en] were installed for real, those two imports would be a hook for the +# whole spacy → thinc → torch → CUDA chain (~5.6 GB verified). This stub registers +# `misaki.en` and `misaki.espeak` as import-time-only placeholders instead. +# +# Written into site-packages by the derivation (see pkgs/kittentts-env.nix) under +# `sitecustomize.py`-style auto-load — actually via a `kitten_tts_stub.py` + a `.pth` +# pointing at it, so any Python process in this env gets the stub registered before +# any kittentts import. If KittenTTS upstream ever starts USING misaki, this shim +# will fail loudly at import of the missing attributes (better than silent distortion), +# and the fix becomes "install the real misaki[en]" — a deliberate, reviewed change. +import sys +import types + +_misaki = sys.modules.get("misaki") +if _misaki is None: + # Avoid registering a fake parent before the real misaki loads — the base misaki + # (addict/regex only) is installed normally, so usually already here. + import misaki # noqa: F401 (raises if base misaki is missing — loud, not silent) + _misaki = sys.modules["misaki"] + +if getattr(_misaki, "en", None) is None: + _stub = types.ModuleType("misaki.en") + sys.modules.setdefault("misaki.en", _stub) + _misaki.en = _stub + +if getattr(_misaki, "espeak", None) is None: + _stub2 = types.ModuleType("misaki.espeak") + sys.modules.setdefault("misaki.espeak", _stub2) + _misaki.espeak = _stub2 diff --git a/hosts/mars/kittentts/requirements.txt b/hosts/mars/kittentts/requirements.txt new file mode 100644 index 0000000..176e1d7 --- /dev/null +++ b/hosts/mars/kittentts/requirements.txt @@ -0,0 +1,69 @@ +# Pinned requirements for the KittenTTS side-venv on mars (validated freeze, CPU-only). +# +# DEPENDENCY DISCIPLINE (important — this is NOT the upstream dependency set): +# `kittentts` declares `misaki[en]` + spacy, which transitively pull torch → the whole +# CUDA runtime (~5.6 GB with nvidia-* wheels, verified in a clean install on this box). +# NONE of that is reachable at runtime: onnx_model.py imports `from misaki import en, espeak` +# at module load but generate() phonemizes exclusively through `phonemizer-fork` + +# `espeakng-loader` (espeak-ng via EspeakBackend); misaki.en/espeak glyphs are parsed but +# never called in the ONNX path. mars has no GPU and a modest disk budget, so: +# +# - install kittentts with --no-deps and enumerate its deps manually, +# - install base `misaki` (NOT misaki[en]) — only addict/regex, +# - the misaki.en import is satisfied by a stub registered in sitecustomize +# (kitten-misaki-stub.py, written into site-packages by the derivation). +# +# Freeze captured 2026-09-19 from a verified CPU-only venv (python 3.13, i5-4460, +# generation ~= 1x realtime with the mini model, HF_HUB_OFFLINE=1). +# +# kittentts itself comes from a GitHub release wheel (0.8.1), not PyPI (PyPI's 0.1.3 is +# the old v0.1-lineage); see pkgs/kittentts-env.nix. +addict==2.4.0 +anyio==4.15.1 +attrs==26.1.0 +babel==2.18.0 +certifi==2026.7.22 +cffi==2.1.1 +click==8.5.0 +cloudpickle==3.1.2 +csvw==4.1.0 +dlinfo==2.0.0 +docopt==0.6.2 +espeakng-loader==0.2.4 +filelock==4.0.1 +flatbuffers==25.12.19 +fsspec==2026.9.0 +h11==0.16.0 +hf-xet==1.6.0 +httpcore==1.0.9 +httpx==0.28.1 +huggingface-hub==1.32.0 +idna==3.20 +isodate==0.7.2 +joblib==1.6.0 +jsonschema-specifications==2025.9.1 +jsonschema==4.26.0 +language-tags==1.3.1 +misaki==0.9.4 +num2words==0.5.14 +numpy==2.5.3 +onnxruntime==1.30.0 +packaging==26.3 +phonemizer-fork==3.3.2 +protobuf==7.36.2 +pycparser==3.0 +pyparsing==3.3.2 +python-dateutil==2.9.0.post0 +pyyaml==6.0.3 +rdflib==7.6.0 +referencing==0.37.0 +regex==2026.9.10 +rfc3986==1.5.0 +rpds-py==2026.6.3 +segments==2.4.0 +six==1.17.0 +soundfile==0.14.0 +termcolor==3.3.0 +tqdm==4.70.1 +typing-extensions==4.16.0 +uritemplate==4.2.0 From b2982c47a11531362a70067181cb5badd442c42d Mon Sep 17 00:00:00 2001 From: luna Date: Sat, 19 Sep 2026 12:33:55 +0000 Subject: [PATCH 2/6] =?UTF-8?q?mars(kittentts):=20review=20fixes=20?= =?UTF-8?q?=E2=80=94=20root-owned=20staging,=20offline=20cache=20resolved,?= =?UTF-8?q?=20full-input=20stamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review round 1 fixes: 1+2 (security): build+stamp+uv-cache moved out of hermesHome into a 0700 root-owned staging dir (/var/lib/hermes-kittentts). Root executes python only from the staging venv after an offline import check; finished artifacts are copied into hermesHome and the stamp compares delivered copy vs staging byte-for-byte. No root code path follows anything the container can write, so no stamp symlink-takeover and no planted-wheel-in-cache execution. 3: HF snapshot dir is the real commit sha with refs/main written, so hf_hub_download resolves the seeded cache offline (was 'kitten', never found). 4: container env pins HF_HOME=/opt/data/kittentts-hf + HF_HUB_OFFLINE=1. 5: stamp keyed on the full input set (requirements+wheel+stub+models), not requirements alone; deletion of a delivered file drops out of the fast path and re-provisions cheaply. 6: orders after/requires hermes-agent-prepare-dirs. --- hosts/mars/hermes-agent.nix | 158 +++++++++++++++++++++++++++--------- 1 file changed, 119 insertions(+), 39 deletions(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index 53b0950..e4fa364 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -301,6 +301,11 @@ in # Authentik rejects. Safe to trust any peer: 9119 is already scoped to # loopback + tailscale0 only. FORWARDED_ALLOW_IPS = "*"; + + # KittenTTS: point huggingface_hub at the pre-seeded offline cache and + # forbid network — no model drift, no boot-time fetch (review #4). + HF_HOME = "/opt/data/kittentts-hf"; + HF_HUB_OFFLINE = "1"; }; environmentFiles = [ config.sops.templates."hermes-agent.env".path ]; cmd = [ "gateway" "run" ]; @@ -486,26 +491,42 @@ in # .pth-registered stub (kitten-misaki-stub.py) that fails loudly if misaki # is ever actually used. # - # Provisioner invariants (shaped by the Mnemosyne-round review): - # - `uv venv --clear`: re-provision cannot wedge on an existing dir. - # - Root runs NO python from this venv: the unit itself does only fs - # writes; the venv is chowned to the container uid before Hermes ever - # imports from it. (Hermes executes provider code as uid 986.) - # - HF model cache is PRE-SEEDED from hash-pinned store paths, so - # HF_HUB_OFFLINE=1 gives zero boot-time network and no drift. - # - Idempotent via a stamp keyed on the requirements hash; checked - # against BOTH the venv python and model files being intact. + # Provisioner invariants (shaped by the Mnemosyne + KittenTTS review rounds): + # - Build in a ROOT-OWNED staging dir (/var/lib/hermes-kittentts, 0700): + # stamp, staging venv, uv cache and staging model copies all live there. + # Root never reads or executes anything the container can write — the + # container cannot symlink-takeover the stamp (review #1) or plant a + # wheel in the uv cache (review #2); only FINISHED artifacts are copied + # into hermesHome, and the stamp compares the delivered copy against + # staging byte-for-byte. + # - Root runs python ONLY from the staging venv (never from the delivered + # uid-986-owned tree in hermesHome) — after a root-side offline import + # check; a failing build aborts before anything is delivered. + # - HF model cache delivered to hermesHome from staging (refs/main -> + # snapshots/), and the container env pins + # HF_HOME=/opt/data/kittentts-hf + HF_HUB_OFFLINE=1: zero boot-time + # network, no drift. + # - Idempotency stamp keyed on the FULL input set (requirements + wheel + + # stub + model files), not just requirements (review #5); a deleted + # delivered file falls out of the fast path and re-provisions cheaply. + # - Order after prepare-dirs (review #6) — mirrors the mnemosyne unit. # - # Trust boundary: the venv lives inside hermesHome (HERMES_WRITE_SAFE_ROOT), - # so luna can technically alter her own TTS engine. Deliberate: it's her - # voice, not her jail — the webhook filter scripts remain the only + # Trust boundary: the DELIVERED venv lives inside hermesHome + # (HERMES_WRITE_SAFE_ROOT), so luna can alter her own TTS engine — and a + # deleted/modified copy just triggers a fresh delivery from the root-owned + # staging area on next boot (self-heals instead of wedging). Deliberate: it's + # her voice, not her jail — the webhook filter scripts remain the only # write-protected-but-load-bearing items. systemd.services.hermes-agent-kittentts-provision = { description = "Provision KittenTTS voice provider (side venv + offline HF cache)"; before = [ "podman-hermes-agent.service" ]; wantedBy = [ "podman-hermes-agent.service" ]; wants = [ "network-online.target" ]; - after = [ "network-online.target" ]; + # after prepare-dirs (review #6): on a fresh state dir this unit must not + # create hermesHome root-owned before prepare-dirs sets the ownership + # layout — same ordering contract the mnemosyne unit has. + after = [ "hermes-agent-prepare-dirs.service" ]; + requires = [ "hermes-agent-prepare-dirs.service" ]; path = [ pkgs.uv pkgs.coreutils ]; serviceConfig = { Type = "oneshot"; @@ -516,51 +537,110 @@ in venv=${hermesHome}/kittentts-venv hubDir=${hermesHome}/kittentts-hf/hub/models--KittenML--kitten-tts-mini-0.8 - snap=$hubDir/snapshots/kitten - stampFile=${hermesHome}/kittentts-provision.stamp - reqHash=$(sha256sum ${kittenttsReqs} | cut -d' ' -f1) + # Real upstream commit SHA as snapshot dir: hf_hub_download resolves + # refs/main -> snapshots/; "kitten" (review #3) is never found + # offline and silently triggers a re-download. + modelSha=c02725660cea441db4c383af69f1f26f5cd00947 + snap=$hubDir/snapshots/$modelSha + # REVIEW #1/#2: nothing root touches lives in hermesHome. Stamp, staging + # venv and uv cache live root-owned under /var/lib/hermes-kittentts (a + # path the container can not pathwrite or symlinks into its own tree); + # the FINISHED staging venv and model files are the only things copied + # into hermesHome, and only after being validated. Root doesn't follow + # any uid-986-writable path while running as root. + stageDir=/var/lib/hermes-kittentts + # Root-side staging of the model files (hash-pinned store paths; the + # delivered copy under hermesHome is compared against these). + stageSnap=$stageDir/hf-model + # Input key: requirements + wheel + stub + model files + resolved script. + # Review #5 — a miss on the old requirements-only stamp let a changed + # wheel/stub/model URL keep running the stale install forever. + inputHash=$(cat ${kittenttsReqs} ${kittenttsWheel} ${kittenttsStub} \ + ${kittenttsModelOnnx} ${kittenttsModelVoices} ${kittenttsModelConfig} \ + | sha256sum | cut -d' ' -f1) + stampFile=$stageDir/provision.stamp - # Idempotent early exit: stamp + venv + all three model files intact. - if [ -f "$stampFile" ] && [ "$(cat "$stampFile")" = "$reqHash" ] \ - && [ -x "$venv/bin/python" ] \ - && [ -f "$snap/kitten_tts_mini_v0_8.onnx" ] \ - && [ -f "$snap/voices.npz" ] \ - && [ -f "$venv/lib/python3.13/site-packages/kitten_tts_stub.py" ]; then - exit 0 + # Idempotent early exit: stamp matches the full input hash, staging venv + # validated, delivered copy intact check runs below. + if [ -f "$stampFile" ] && [ "$(cat "$stampFile")" = "$inputHash" ] \ + && [ -x "$stageVenv/bin/python" ] \ + && [ -f "$stageSnap/config.json" ]; then + # Delivered artifacts in hermesHome must ALSO match the staging copy: + # luna can rewrite her copy, that's fine — but then the missing file + # forces a re-provision (cheap copy, not a rebuild) so deletions + # cannot wedge the gateway without a voice. + if [ -x "$venv/bin/python" ] \ + && cmp -s "$stageSnap/config.json" "$snap/config.json" 2>/dev/null \ + && cmp -s "$stageSnap/kitten_tts_mini_v0_8.onnx" "$snap/kitten_tts_mini_v0_8.onnx" 2>/dev/null \ + && cmp -s "$stageSnap/voices.npz" "$snap/voices.npz" 2>/dev/null; then + exit 0 + fi fi - # Venv (rebuilt rather than broken on --no-clear: uv exits 2 otherwise). - uv venv "$venv" --python ${pkgs.python313}/bin/python3 --clear --quiet - UV_CACHE_DIR=${hermesHome}/kittentts-uv-cache \ - uv pip install --python "$venv/bin/python" --quiet \ + # ---- staging venv: root-owned path, uv cache included. Root runs + # python from HERE (container can write nothing in this tree), then the + # FINISHED result is copied into hermesHome. Review #1: a stamp symlink + # into /etc/shadow can't redirect us — the stamp dir is root-only. ---- + stageVenv=$stageDir/venv + mkdir -p "$stageDir" "$stageSnap" + chmod 0700 "$stageDir" + install -m 0444 ${kittenttsModelConfig} "$stageSnap/config.json" + install -m 0444 ${kittenttsModelOnnx} "$stageSnap/kitten_tts_mini_v0_8.onnx" + install -m 0444 ${kittenttsModelVoices} "$stageSnap/voices.npz" + + rm -rf "$stageVenv" + UV_CACHE_DIR=$stageDir/uv-cache \ + uv venv "$stageVenv" --python ${pkgs.python313}/bin/python3 --quiet + UV_CACHE_DIR=$stageDir/uv-cache \ + uv pip install --python "$stageVenv/bin/python" --quiet \ --requirement ${kittenttsReqs} # kittentts --no-deps: its overlay of spacy/misaki[en] is what drags in # the CUDA tree; the requirements freeze already covers its real needs. - UV_CACHE_DIR=${hermesHome}/kittentts-uv-cache \ - uv pip install --python "$venv/bin/python" --quiet --no-deps \ + UV_CACHE_DIR=$stageDir/uv-cache \ + uv pip install --python "$stageVenv/bin/python" --quiet --no-deps \ ${kittenttsWheel} # Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter start # so `from misaki import en, espeak` resolves without the real misaki.en. - siteDir=$("$venv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') + siteDir=$("$stageVenv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') cp ${kittenttsStub} "$siteDir/kitten_tts_stub.py" printf 'import kitten_tts_stub\n' > "$siteDir/zz-kitten-stub.pth" - # Seed the HF cache with the hashed model files (exact hub layout; - # hf_hub_download scans refs/snapshots on disk offline). - mkdir -p "$hubDir/refs" "$snap" + # Root-side sanity: the venv python must import the plugin entrypoint + # cleanly offline; a failing build aborts BEFORE anything lands in + # hermesHome (fail closed, not half-delivered). + HF_HOME=$stageDir/hf-cache \ + HF_HUB_OFFLINE=1 \ + PHONEMIZER_ESPEAK_LIBRARY="$("$stageVenv/bin/python" -c 'import espeakng_loader,pathlib;print(pathlib.Path(espeakng_loader.get_library_path()))')" \ + PHONEMIZER_ESPEAK_DATA_PATH=$("$stageVenv/bin/python" -c 'import espeakng_loader,pathlib;print(pathlib.Path(espeakng_loader.get_data_path()))') \ + "$stageVenv/bin/python" -c 'from kittentts import KittenTTS; print("kittentts import ok")' >/dev/null + + # ---- deliver: only finished artifacts into hermesHome. Copy, not + # move — staging stays root-owned for the integrity check above. ---- + hubDir=${hermesHome}/kittentts-hf/hub/models--KittenML--kitten-tts-mini-0.8 + snap=$hubDir/snapshots/$modelSha + rm -rf "$venv.tmp" + cp -a "$stageVenv" "$venv.tmp" + mv -Tf "$venv.tmp" "$venv" # atomic-ish swap of the delivered venv + + mkdir -p "$hubDir/refs" "$snap" "$hubDir/blobs" + printf '%s' "$modelSha" > "$hubDir/refs/main" # review #3: resolves offline install -m 0444 ${kittenttsModelOnnx} "$snap/kitten_tts_mini_v0_8.onnx" install -m 0444 ${kittenttsModelVoices} "$snap/voices.npz" install -m 0444 ${kittenttsModelConfig} "$snap/config.json" + # HF hub layout puts the blob under blobs/ with snapshot + # symlinks pointing back — but kittentts reads config/model paths + # RETURNED by hf_hub_download, which serves the resolved snapshot file + # directly. Files-as-plain-content suffices (no LFS indirection here: + # pre-materialized), no blob indirection needed. - # Hand ownership to the container uid BEFORE any python runs in this - # tree (root never imports from it — that was Mnemosyne review #3). + # Hand ownership to the container uid BEFORE any python runs in + # hermesHome's copy — root does its python in $stageVenv, not here. chown -R ${hermesUid}:${hermesGid} "$venv" "$hubDir" - # Stamp LAST — a half-provisioned venv fails the integrity check and - # re-provisions on next boot rather than being trusted. - printf '%s' "$reqHash" > "$stampFile" - chown ${hermesUid}:${hermesGid} "$stampFile" + # Stamp LAST, root-owned outside hermesHome — luna can delete it (which + # just forces a cheap re-provision copy), not tamper via symlink. + printf '%s' "$inputHash" > "$stampFile" ''; }; } From bef5215bea5b9ee498a5c81eab2c0f339b79030a Mon Sep 17 00:00:00 2001 From: luna Date: Sat, 19 Sep 2026 12:46:14 +0000 Subject: [PATCH 3/6] =?UTF-8?q?mars(kittentts):=20review=20round=202=20?= =?UTF-8?q?=E2=80=94=20setpriv=20delivery,=20staged=20hub=20tree,=20orderi?= =?UTF-8?q?ng=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1: stageVenv declared with the other path vars before the early-exit reads it (set -u no longer kills the self-heal path on later boots). 2: delivery is rm+cp as the container uid via setpriv — no mv -Tf rename-replace on a non-empty directory (that failed every re-provision); chown -R step gone with it. 3: network-online.target back in after= — this unit CAN download at boot, so uv must not run pre-network. 4: root never writes into hermesHome at all. refs/main, snapshots and venv staging happen under root-owned staging; delivery drops to uid 986 via setpriv, rm -rf + cp -a from the staging sources. Symlink-takeover of refs/install targets and the rm/cp race on the delivered tree are structurally gone. Minor: sanity check now constructs KittenTTS against the staged hub tree, not just imports; fetchurls pinned to the commit sha matching refs/main; fast-path comment matches behavior (staging venv skips rebuild on damaged delivery). --- hosts/mars/hermes-agent.nix | 143 +++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 59 deletions(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index e4fa364..089a5f6 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -92,15 +92,15 @@ let builtins.readFile ./kittentts/kitten-misaki-stub.py ); kittenttsModelOnnx = pkgs.fetchurl { - url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/kitten_tts_mini_v0_8.onnx"; + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/c02725660cea441db4c383af69f1f26f5cd00947/kitten_tts_mini_v0_8.onnx"; sha256 = "sha256-D1u65PxIAMmNvFRKh+z6eVEN4vuCItsw0S5b/pF335E="; }; kittenttsModelVoices = pkgs.fetchurl { - url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/voices.npz"; + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/c02725660cea441db4c383af69f1f26f5cd00947/voices.npz"; sha256 = "sha256-QK0mOJUrd7ey8wEn4mCOFp/GndJWtTvYqqNAmjMZPEI="; }; kittenttsModelConfig = pkgs.fetchurl { - url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/main/config.json"; + url = "https://huggingface.co/KittenML/kitten-tts-mini-0.8/resolve/c02725660cea441db4c383af69f1f26f5cd00947/config.json"; sha256 = "sha256-axYLybGeJOyyHoS8FPin2iH99H7HLUJFC8XPUUthgEo="; }; @@ -524,10 +524,16 @@ in wants = [ "network-online.target" ]; # after prepare-dirs (review #6): on a fresh state dir this unit must not # create hermesHome root-owned before prepare-dirs sets the ownership - # layout — same ordering contract the mnemosyne unit has. - after = [ "hermes-agent-prepare-dirs.service" ]; + # layout — same ordering contract the mnemosyne unit has. PLUS + # network-online ordering (review2 #3): this unit CAN download at boot + # (unlike mnemosyne's store-path build), so uv must not run before the + # network is actually up. + after = [ + "network-online.target" + "hermes-agent-prepare-dirs.service" + ]; requires = [ "hermes-agent-prepare-dirs.service" ]; - path = [ pkgs.uv pkgs.coreutils ]; + path = [ pkgs.uv pkgs.coreutils pkgs.setpriv ]; serviceConfig = { Type = "oneshot"; TimeoutStartSec = 600; @@ -549,8 +555,12 @@ in # into hermesHome, and only after being validated. Root doesn't follow # any uid-986-writable path while running as root. stageDir=/var/lib/hermes-kittentts - # Root-side staging of the model files (hash-pinned store paths; the - # delivered copy under hermesHome is compared against these). + # Root-side staging of the DELIVERED TREE (venv + full HF hub layout + # including refs/main) — everything root writes lives here, 0700. + # review2 #4: root never writes into hermesHome; delivery happens as + # the container uid via setpriv, copying from these root-owned sources. + stageVenv=$stageDir/venv + stageHub=$stageDir/kittentts-hf stageSnap=$stageDir/hf-model # Input key: requirements + wheel + stub + model files + resolved script. # Review #5 — a miss on the old requirements-only stamp let a changed @@ -577,69 +587,84 @@ in fi fi - # ---- staging venv: root-owned path, uv cache included. Root runs - # python from HERE (container can write nothing in this tree), then the - # FINISHED result is copied into hermesHome. Review #1: a stamp symlink - # into /etc/shadow can't redirect us — the stamp dir is root-only. ---- - stageVenv=$stageDir/venv - mkdir -p "$stageDir" "$stageSnap" + # ---- staging venv + staged hub tree: root-owned path, uv cache + # included. Root runs python from HERE (container can write nothing in + # this tree); the FINISHED result is copied into hermesHome AS THE + # CONTAINER USER via setpriv (review2 #4) — root never writes into + # hermesHome, so no uid-986-controlled path is ever followed while + # running as root; symlink-takeover of stamps/refs/install targets is + # structurally impossible. ---- + mkdir -p "$stageDir" "$stageSnap" "$stageVenv" "$stageHub" chmod 0700 "$stageDir" install -m 0444 ${kittenttsModelConfig} "$stageSnap/config.json" install -m 0444 ${kittenttsModelOnnx} "$stageSnap/kitten_tts_mini_v0_8.onnx" install -m 0444 ${kittenttsModelVoices} "$stageSnap/voices.npz" - rm -rf "$stageVenv" - UV_CACHE_DIR=$stageDir/uv-cache \ - uv venv "$stageVenv" --python ${pkgs.python313}/bin/python3 --quiet - UV_CACHE_DIR=$stageDir/uv-cache \ - uv pip install --python "$stageVenv/bin/python" --quiet \ - --requirement ${kittenttsReqs} - # kittentts --no-deps: its overlay of spacy/misaki[en] is what drags in - # the CUDA tree; the requirements freeze already covers its real needs. - UV_CACHE_DIR=$stageDir/uv-cache \ - uv pip install --python "$stageVenv/bin/python" --quiet --no-deps \ - ${kittenttsWheel} + # Skip the venv REBUILD when staging is still valid (review2 minor: + # damaged delivery should be a copy, not a rebuild). + if ! [ -x "$stageVenv/bin/python" ] \ + || ! [ -f "$stageVenv/lib/python3.13/site-packages/kitten_tts_stub.py" ]; then + rm -rf "$stageVenv" + UV_CACHE_DIR=$stageDir/uv-cache \ + uv venv "$stageVenv" --python ${pkgs.python313}/bin/python3 --quiet + UV_CACHE_DIR=$stageDir/uv-cache \ + uv pip install --python "$stageVenv/bin/python" --quiet \ + --requirement ${kittenttsReqs} + # kittentts --no-deps: its overlay of spacy/misaki[en] is what drags in + # the CUDA tree; the requirements freeze already covers its real needs. + UV_CACHE_DIR=$stageDir/uv-cache \ + uv pip install --python "$stageVenv/bin/python" --quiet --no-deps \ + ${kittenttsWheel} - # Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter start - # so `from misaki import en, espeak` resolves without the real misaki.en. - siteDir=$("$stageVenv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') - cp ${kittenttsStub} "$siteDir/kitten_tts_stub.py" - printf 'import kitten_tts_stub\n' > "$siteDir/zz-kitten-stub.pth" + # Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter + # start so `from misaki import en, espeak` resolves without the real + # misaki.en. + siteDir=$("$stageVenv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') + cp ${kittenttsStub} "$siteDir/kitten_tts_stub.py" + printf 'import kitten_tts_stub\n' > "$siteDir/zz-kitten-stub.pth" + fi - # Root-side sanity: the venv python must import the plugin entrypoint - # cleanly offline; a failing build aborts BEFORE anything lands in - # hermesHome (fail closed, not half-delivered). - HF_HOME=$stageDir/hf-cache \ + # Stage the full delivered hub tree (exact hf_hub_download layout: + # refs/main -> snapshots/; review1 #3) under root-owned staging. + stageModelDir=$stageHub/hub/models--KittenML--kitten-tts-mini-0.8 + mkdir -p "$stageModelDir/refs" "$stageModelDir/snapshots/$modelSha" + printf '%s' "$modelSha" > "$stageModelDir/refs/main" + install -m 0444 ${kittenttsModelOnnx} "$stageModelDir/snapshots/$modelSha/kitten_tts_mini_v0_8.onnx" + install -m 0444 ${kittenttsModelVoices} "$stageModelDir/snapshots/$modelSha/voices.npz" + install -m 0444 ${kittenttsModelConfig} "$stageModelDir/snapshots/$modelSha/config.json" + # No blobs/ indirection: kittentts reads paths RETURNED by + # hf_hub_download, which serves the resolved snapshot file directly + # (prefer-dir layout works offline for fully-materialized files). + + # Root-side sanity: the staged interpreter must construct the model + # END-TO-END offline (review2 minor — import alone doesn't exercise + # hf_hub_download; a broken cache layout must fail HERE, not in the + # gateway). Points HF_HOME at the staged hub tree itself. + HF_HOME=$stageHub \ HF_HUB_OFFLINE=1 \ PHONEMIZER_ESPEAK_LIBRARY="$("$stageVenv/bin/python" -c 'import espeakng_loader,pathlib;print(pathlib.Path(espeakng_loader.get_library_path()))')" \ - PHONEMIZER_ESPEAK_DATA_PATH=$("$stageVenv/bin/python" -c 'import espeakng_loader,pathlib;print(pathlib.Path(espeakng_loader.get_data_path()))') \ - "$stageVenv/bin/python" -c 'from kittentts import KittenTTS; print("kittentts import ok")' >/dev/null + PHONEMIZER_ESPEAK_DATA_PATH="$("$stageVenv/bin/python" -c 'import espeakng_loader,pathlib;print(pathlib.Path(espeakng_loader.get_data_path()))')" \ + "$stageVenv/bin/python" -c 'from kittentts import KittenTTS; KittenTTS("KittenML/kitten-tts-mini-0.8"); print("kittentts offline build ok")' >/dev/null - # ---- deliver: only finished artifacts into hermesHome. Copy, not - # move — staging stays root-owned for the integrity check above. ---- - hubDir=${hermesHome}/kittentts-hf/hub/models--KittenML--kitten-tts-mini-0.8 - snap=$hubDir/snapshots/$modelSha - rm -rf "$venv.tmp" - cp -a "$stageVenv" "$venv.tmp" - mv -Tf "$venv.tmp" "$venv" # atomic-ish swap of the delivered venv - - mkdir -p "$hubDir/refs" "$snap" "$hubDir/blobs" - printf '%s' "$modelSha" > "$hubDir/refs/main" # review #3: resolves offline - install -m 0444 ${kittenttsModelOnnx} "$snap/kitten_tts_mini_v0_8.onnx" - install -m 0444 ${kittenttsModelVoices} "$snap/voices.npz" - install -m 0444 ${kittenttsModelConfig} "$snap/config.json" - # HF hub layout puts the blob under blobs/ with snapshot - # symlinks pointing back — but kittentts reads config/model paths - # RETURNED by hf_hub_download, which serves the resolved snapshot file - # directly. Files-as-plain-content suffices (no LFS indirection here: - # pre-materialized), no blob indirection needed. - - # Hand ownership to the container uid BEFORE any python runs in - # hermesHome's copy — root does its python in $stageVenv, not here. - chown -R ${hermesUid}:${hermesGid} "$venv" "$hubDir" + # ---- deliver AS THE CONTAINER USER (review2 #4): root never writes + # into hermesHome, so no symlink race and no `chown` step. setpriv + # drops to uid 986, rm -rf's the old delivered copies and copies the + # fresh staging tree in. cp-as-986 also fixes review2 #2: rm+cp in one + # step, no mv -Tf rename-replace on a non-empty directory. + setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \ + env HOME="$hermesHome" sh -c ' + set -eu + rm -rf "$1" "$2" + cp -a "$3" "$1" + cp -a "$4" "$2" + ' _ \ + "${hermesHome}/kittentts-venv" \ + "${hermesHome}/kittentts-hf" \ + "$stageVenv" \ + "$stageHub" # Stamp LAST, root-owned outside hermesHome — luna can delete it (which - # just forces a cheap re-provision copy), not tamper via symlink. + # forces a cheap re-delivery on next boot), not tamper via symlink. printf '%s' "$inputHash" > "$stampFile" ''; }; From e0f5c6b37bc1bde6a353905eb2dd3e84c7352a2b Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sat, 19 Sep 2026 14:51:05 +0200 Subject: [PATCH 4/6] =?UTF-8?q?mars(kittentts):=20fix=20review=20round=203?= =?UTF-8?q?=20=E2=80=94=20eval,=20delivery=20and=20stale-venv=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pkgs.setpriv does not exist (mars failed to eval); setpriv is in util-linux. - `sh` is not on a unit's PATH; call ${pkgs.runtimeShell} directly. - Drop `env HOME="$hermesHome"`: unset shell var under `set -u`, and unneeded. - Staging dir 0700 -> 0755: the uid-986 delivery step could not read it. - Rebuild the staging venv whenever the stamp misses, else an input bump delivered the old venv under the new stamp. - Add diffutils: `cmp` in the fast path was missing, so every boot re-delivered. Co-Authored-By: Claude Opus 5 --- hosts/mars/hermes-agent.nix | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index 089a5f6..5151219 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -492,7 +492,8 @@ in # is ever actually used. # # Provisioner invariants (shaped by the Mnemosyne + KittenTTS review rounds): - # - Build in a ROOT-OWNED staging dir (/var/lib/hermes-kittentts, 0700): + # - Build in a ROOT-OWNED staging dir (/var/lib/hermes-kittentts, 0755 so + # the uid-986 delivery step can read it; nothing in it is secret): # stamp, staging venv, uv cache and staging model copies all live there. # Root never reads or executes anything the container can write — the # container cannot symlink-takeover the stamp (review #1) or plant a @@ -533,7 +534,8 @@ in "hermes-agent-prepare-dirs.service" ]; requires = [ "hermes-agent-prepare-dirs.service" ]; - path = [ pkgs.uv pkgs.coreutils pkgs.setpriv ]; + # diffutils: `cmp` in the fast path; missing, it silently re-delivers every boot. + path = [ pkgs.uv pkgs.coreutils pkgs.diffutils pkgs.util-linux ]; serviceConfig = { Type = "oneshot"; TimeoutStartSec = 600; @@ -556,7 +558,7 @@ in # any uid-986-writable path while running as root. stageDir=/var/lib/hermes-kittentts # Root-side staging of the DELIVERED TREE (venv + full HF hub layout - # including refs/main) — everything root writes lives here, 0700. + # including refs/main) — everything root writes lives here. # review2 #4: root never writes into hermesHome; delivery happens as # the container uid via setpriv, copying from these root-owned sources. stageVenv=$stageDir/venv @@ -595,14 +597,17 @@ in # running as root; symlink-takeover of stamps/refs/install targets is # structurally impossible. ---- mkdir -p "$stageDir" "$stageSnap" "$stageVenv" "$stageHub" - chmod 0700 "$stageDir" + # 0755: the setpriv'd uid-986 delivery below must be able to read it. + chmod 0755 "$stageDir" install -m 0444 ${kittenttsModelConfig} "$stageSnap/config.json" install -m 0444 ${kittenttsModelOnnx} "$stageSnap/kitten_tts_mini_v0_8.onnx" install -m 0444 ${kittenttsModelVoices} "$stageSnap/voices.npz" # Skip the venv REBUILD when staging is still valid (review2 minor: - # damaged delivery should be a copy, not a rebuild). - if ! [ -x "$stageVenv/bin/python" ] \ + # damaged delivery should be a copy, not a rebuild) — but only for the + # CURRENT inputs, else a bump delivers the old venv under a new stamp. + if [ "$(cat "$stampFile" 2>/dev/null)" != "$inputHash" ] \ + || ! [ -x "$stageVenv/bin/python" ] \ || ! [ -f "$stageVenv/lib/python3.13/site-packages/kitten_tts_stub.py" ]; then rm -rf "$stageVenv" UV_CACHE_DIR=$stageDir/uv-cache \ @@ -652,7 +657,7 @@ in # fresh staging tree in. cp-as-986 also fixes review2 #2: rm+cp in one # step, no mv -Tf rename-replace on a non-empty directory. setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \ - env HOME="$hermesHome" sh -c ' + ${pkgs.runtimeShell} -c ' set -eu rm -rf "$1" "$2" cp -a "$3" "$1" From 812c1af1f257f171cfd0b0e5838e4ce4c770bf7e Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sat, 19 Sep 2026 14:59:01 +0200 Subject: [PATCH 5/6] mars(kittentts): install the wheel under its real filename uv reads the version from the wheel filename, and the fetchurl store path's hash prefix made it reject the file ("invalid version"). Expose it via a linkFarm under kittentts-0.8.1-py3-none-any.whl. Co-Authored-By: Claude Opus 5 --- hosts/mars/hermes-agent.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index 5151219..bcbb81e 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -85,6 +85,10 @@ let url = "https://github.com/KittenML/KittenTTS/releases/download/0.8.1/kittentts-0.8.1-py3-none-any.whl"; sha256 = "sha256-SCpDbE8fMZIVNxA3bkWf82iVF+vNp8KwUeL9QYe0GFE="; }; + # uv parses the version out of the filename; the store hash prefix breaks it. + kittenttsWheelFile = "${pkgs.linkFarm "kittentts-wheel" { + "kittentts-0.8.1-py3-none-any.whl" = kittenttsWheel; + }}/kittentts-0.8.1-py3-none-any.whl"; kittenttsReqs = pkgs.writeText "kittentts-requirements.txt" ( builtins.readFile ./kittentts/requirements.txt ); @@ -619,7 +623,7 @@ in # the CUDA tree; the requirements freeze already covers its real needs. UV_CACHE_DIR=$stageDir/uv-cache \ uv pip install --python "$stageVenv/bin/python" --quiet --no-deps \ - ${kittenttsWheel} + ${kittenttsWheelFile} # Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter # start so `from misaki import en, espeak` resolves without the real From 22caa06904da9df9a712093e214d8f644be8e770 Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sat, 19 Sep 2026 15:05:01 +0200 Subject: [PATCH 6/6] mars(kittentts): patch venv .so RPATHs so numpy/onnxruntime load The venv's python is Nix python313 (also inside the container, via the /nix/store mount), whose loader never searches /usr/lib, so PyPI manylinux wheels failed with "libstdc++.so.6: cannot open shared object file". auto-patchelf the staged venv against gcc-lib + zlib; RPATHs are store paths, so the delivered copy works in the container too. The lib paths join the input hash so a toolchain bump rebuilds. Verified locally with mars's exact uv/python313: construct offline from the staged hub layout and synthesize with voice "Luna". Co-Authored-By: Claude Opus 5 --- hosts/mars/hermes-agent.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hosts/mars/hermes-agent.nix b/hosts/mars/hermes-agent.nix index bcbb81e..0d8b4c2 100644 --- a/hosts/mars/hermes-agent.nix +++ b/hosts/mars/hermes-agent.nix @@ -89,6 +89,7 @@ let kittenttsWheelFile = "${pkgs.linkFarm "kittentts-wheel" { "kittentts-0.8.1-py3-none-any.whl" = kittenttsWheel; }}/kittentts-0.8.1-py3-none-any.whl"; + kittenttsRuntimeLibs = "${pkgs.stdenv.cc.cc.lib}/lib ${pkgs.zlib}/lib"; kittenttsReqs = pkgs.writeText "kittentts-requirements.txt" ( builtins.readFile ./kittentts/requirements.txt ); @@ -539,7 +540,7 @@ in ]; requires = [ "hermes-agent-prepare-dirs.service" ]; # diffutils: `cmp` in the fast path; missing, it silently re-delivers every boot. - path = [ pkgs.uv pkgs.coreutils pkgs.diffutils pkgs.util-linux ]; + path = [ pkgs.uv pkgs.coreutils pkgs.diffutils pkgs.util-linux pkgs.auto-patchelf pkgs.patchelf ]; serviceConfig = { Type = "oneshot"; TimeoutStartSec = 600; @@ -571,9 +572,9 @@ in # Input key: requirements + wheel + stub + model files + resolved script. # Review #5 — a miss on the old requirements-only stamp let a changed # wheel/stub/model URL keep running the stale install forever. - inputHash=$(cat ${kittenttsReqs} ${kittenttsWheel} ${kittenttsStub} \ - ${kittenttsModelOnnx} ${kittenttsModelVoices} ${kittenttsModelConfig} \ - | sha256sum | cut -d' ' -f1) + inputHash=$({ cat ${kittenttsReqs} ${kittenttsWheel} ${kittenttsStub} \ + ${kittenttsModelOnnx} ${kittenttsModelVoices} ${kittenttsModelConfig} + echo ${kittenttsRuntimeLibs}; } | sha256sum | cut -d' ' -f1) stampFile=$stageDir/provision.stamp # Idempotent early exit: stamp matches the full input hash, staging venv @@ -631,6 +632,10 @@ in siteDir=$("$stageVenv/bin/python" -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])') cp ${kittenttsStub} "$siteDir/kitten_tts_stub.py" printf 'import kitten_tts_stub\n' > "$siteDir/zz-kitten-stub.pth" + + # PyPI manylinux .so's (numpy, onnxruntime) need libstdc++, which the + # Nix loader never finds, on the host or in the container. + auto-patchelf --paths "$stageVenv" --libs ${kittenttsRuntimeLibs} fi # Stage the full delivered hub tree (exact hf_hub_download layout: