feat(terra): Quickshell lock screen, Star Citizen, NexusMods, TeamSpeak

Also jellyfin-mpv-shim, mangohud logging, portal-backed xdg-open,
systemd-resolved with fallback DNS, and keyring under the user manager.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 00:37:40 +01:00
co-authored by Claude Opus 5.5
parent 7a68716c1c
commit b02d698c1a
22 changed files with 866 additions and 170 deletions
+114 -74
View File
@@ -38,9 +38,10 @@ let
# it's inside Hermes's own write-safe root (HERMES_WRITE_SAFE_ROOT).
dropboxDir = "/mnt/jupiter/AppData/hermes-dropbox";
# v2026.9.14, pinned by index digest rather than floating
# v0.22.3, pinned by index digest rather than floating
# :latest, so bumping Hermes is an explicit edit here, not silent drift.
hermesImage = "docker.io/nousresearch/hermes-agent@sha256:99641e57ec762c59e54cb44aa6746b7fc68c18b3c5ddb088af54234c613d9294";
# Its Python is 3.14 — the in-process STT venv below must match it.
hermesImage = "docker.io/nousresearch/hermes-agent@sha256:2f305c9bdc81731f48664586d23cb6a6f838a15ad7be1bfabe0c3c269d8e09b9";
# Kept identical to jupiter's instance purely so nothing else needs to
# change if state ever gets migrated over.
@@ -78,9 +79,6 @@ let
builtins.readFile ./gitea-pr-review-prompt.md
);
# 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
@@ -97,12 +95,26 @@ let
kittenttsReqs = pkgs.writeText "kittentts-requirements.txt" (
builtins.readFile ./kittentts/requirements.txt
);
# STT add-on: faster-whisper (CPU) for Telegram voice-note transcription,
# same side-venv, appended by the provisioning unit. Keeps one venv + one
# stamp for the whole local-audio stack. See kittentts/stt-requirements.txt.
# STT: faster-whisper (CPU) for voice-note transcription, in its own venv:
# Hermes imports it in-process, so it must be built for the IMAGE's Python
# (3.14), while KittenTTS runs its venv's own 3.13 interpreter as a command.
# Same provisioning unit and stamp. See kittentts/stt-requirements.txt.
kittenttsSttReqs = pkgs.writeText "kittentts-stt-requirements.txt" (
builtins.readFile ./kittentts/stt-requirements.txt
);
# stt.local.model "base", staged into the same offline HF cache: re-delivery
# replaces that whole tree, so an unpinned download would be wiped with it.
whisperRev = "ebe41f70d5b6dfa9166e2c581c45c9c0cfc57b66";
whisperFile = name: hash: pkgs.fetchurl {
url = "https://huggingface.co/Systran/faster-whisper-base/resolve/${whisperRev}/${name}";
inherit hash;
};
whisperModel = pkgs.linkFarm "faster-whisper-base" {
"config.json" = whisperFile "config.json" "sha256-VqbYEQ0xHxnI8EceVigyx1J/FGtWcnW/yln898GE2po=";
"model.bin" = whisperFile "model.bin" "sha256-0BwwFIgcnG8xM8GC89KIfrbKHHiadTjFwAcZaFegpqk=";
"tokenizer.json" = whisperFile "tokenizer.json" "sha256-+3tjGR6bsEUILHn9dCoxBqEsmVE6sw30oNR/pstv0Ks=";
"vocabulary.txt" = whisperFile "vocabulary.txt" "sha256-NM4/4cUEECez+NQpEicJk/mG28S7NM8n+VHjSh5FORM=";
};
kittenttsStub = pkgs.writeText "kitten-tts-stub.py" (
builtins.readFile ./kittentts/kitten-misaki-stub.py
);
@@ -145,10 +157,12 @@ in
users.groups.hermes.gid = 983;
users.users.darman.extraGroups = [ "hermes" ];
# `hermes <args>` == `sudo podman exec -it hermes-agent hermes <args>`. sudo
# is needed because oci-containers runs rootful podman, a separate
# namespace from darman's own rootless one.
programs.zsh.shellAliases.hermes = "sudo podman exec -it hermes-agent hermes";
# `hermes <args>` runs the CLI in the container. sudo is needed because
# oci-containers runs rootful podman, a separate namespace from darman's own
# rootless one. `-u hermes`: run as root, `hermes pm`/`plugins` leave
# root-owned state under /opt/data/installs that the gateway then can't
# write ("install state is not writable by this user"; 2026-10-21).
programs.zsh.shellAliases.hermes = "sudo podman exec -it -u hermes -w /opt/data hermes-agent hermes";
systemd.tmpfiles.rules = [
"d ${stateDir} 0750 root hermes -"
@@ -330,6 +344,11 @@ in
mv -f "$f.new" "$f"
' _ ${hermesHome}/honcho.json
write_env_key API_SERVER_KEY < ${config.sops.secrets.hermes_api_server_key.path}
write_env_key MATRIX_ACCESS_TOKEN < ${config.sops.secrets.matrix_access_token.path}
# Not a secret, but with gateway.multiplex_profiles on the authorization check
# reads only the profile's .env; from the container env it answered with a
# pairing code instead.
printf %s "@darman:mgaction.town" | write_env_key MATRIX_ALLOWED_USERS
# Pinned: overwritten every start, so dashboard edits and her own approved
# edits don't survive (a broken one corrupted it on 2026-09-24). Persona
@@ -410,12 +429,22 @@ in
HF_HOME = "/opt/data/kittentts-hf";
HF_HUB_OFFLINE = "1";
# STT (local whisper): expose the side-venv's site-packages to Hermes's
# STT (local whisper): expose the STT venv's site-packages to Hermes's
# own interpreter so faster-whisper imports in-process. PYTHONPATH dirs
# don't run .pth auto-imports, but faster-whisper has no dead imports —
# it imports cleanly from a plain path injection (unlike kittentts,
# which is driven through the command wrapper for exactly that reason).
PYTHONPATH = "/opt/data/kittentts-venv/lib/python3.13/site-packages";
PYTHONPATH = "/opt/data/stt-venv/lib/python3.14/site-packages";
# Matrix as @luna:mgaction.town, alongside Telegram (which keeps cron
# delivery). Device ID must match the token's; E2EE state is in
# /opt/data/platforms/matrix/store.
MATRIX_HOMESERVER = "https://matrix.mgaction.town";
MATRIX_USER_ID = "@luna:mgaction.town";
MATRIX_DEVICE_ID = "HERMES";
MATRIX_E2EE_MODE = "optional";
# First start bootstraps cross-signing and writes its recovery key here once.
MATRIX_RECOVERY_KEY_OUTPUT_FILE = "/opt/data/matrix-recovery-key";
};
environmentFiles = [ config.sops.templates."hermes-agent.env".path ];
cmd = [ "gateway" "run" ];
@@ -431,7 +460,11 @@ in
# prepare-dirs is an inactive oneshot, and switch-to-configuration only
# restarts ACTIVE units — so editing its script otherwise lands nowhere
# until something else happens to restart the container.
restartTriggers = [ config.systemd.services.hermes-agent-prepare-dirs.script ];
# Same for the KittenTTS/STT provisioner, which the restart pulls in first.
restartTriggers = [
config.systemd.services.hermes-agent-prepare-dirs.script
config.systemd.services.hermes-agent-kittentts-provision.script
];
};
# The two Gitea webhook routes, written as config (not via `hermes webhook
@@ -480,7 +513,7 @@ in
# sticks until the next restart.
#
# Routes not named here are left alone (the merge below is per-key);
# retire one with `sudo podman exec hermes-agent hermes webhook remove <name>`.
# retire one with `hermes webhook remove <name>` (the alias above).
systemd.services.hermes-agent-webhook-routes = {
description = "Write Hermes's Gitea webhook route config";
wantedBy = [ "multi-user.target" ];
@@ -568,35 +601,6 @@ in
'';
};
# Hermes discovers memory providers under $HERMES_HOME/plugins; the target
# is a store path, readable in the container via the /nix/store ro mount.
# wantedBy, not requiredBy: a failure leaves Hermes on built-in memory.
systemd.services.hermes-agent-mnemosyne-plugin = {
description = "Link Mnemosyne provider into the Hermes plugin dir";
before = [ "podman-hermes-agent.service" ];
wantedBy = [ "podman-hermes-agent.service" ];
after = [ "hermes-agent-prepare-dirs.service" ];
requires = [ "hermes-agent-prepare-dirs.service" ];
path = [ pkgs.coreutils ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = ''
set -euo pipefail
pluginsDir=${hermesHome}/plugins
pluginDir=$pluginsDir/mnemosyne
target=${mnemosyneEnv}/${mnemosyneEnv.sitePackages}/hermes_memory_provider
[ -d "$target" ] || { echo "$target missing" >&2; exit 1; }
mkdir -p "$pluginsDir"
chown ${hermesUid}:${hermesGid} "$pluginsDir"
ln -sfn "$target" "$pluginDir.new"
mv -Tf "$pluginDir.new" "$pluginDir"
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
@@ -605,7 +609,7 @@ in
# .pth-registered stub (kitten-misaki-stub.py) that fails loudly if misaki
# is ever actually used.
#
# Provisioner invariants (shaped by the Mnemosyne + KittenTTS review rounds):
# Provisioner invariants (shaped by its review rounds):
# - 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.
@@ -624,7 +628,7 @@ in
# - 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.
# - Order after prepare-dirs (review #6).
#
# Trust boundary: the DELIVERED venv lives inside hermesHome
# (HERMES_WRITE_SAFE_ROOT), so luna can alter her own TTS engine — and a
@@ -639,17 +643,15 @@ 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. 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.
# layout. PLUS network-online ordering (review2 #3): this unit CAN
# download at boot, 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" ];
# diffutils: `cmp` in the fast path; missing, it silently re-delivers every boot.
path = [ pkgs.uv pkgs.coreutils pkgs.diffutils pkgs.util-linux pkgs.auto-patchelf pkgs.patchelf ];
path = [ pkgs.uv pkgs.coreutils pkgs.findutils pkgs.diffutils pkgs.util-linux pkgs.patchelf ];
serviceConfig = {
Type = "oneshot";
TimeoutStartSec = 600;
@@ -671,34 +673,59 @@ 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
# Copied, not uv's default hardlinks: patchelf edits files in place, so
# hardlinked venvs had rewritten the CACHED wheels — av's RPATH pointed
# into a long-deleted venv in every venv built after. Hence also a fresh
# cache dir (the old one was deleted 2026-10-21).
export UV_CACHE_DIR=$stageDir/uv-cache-v2 UV_LINK_MODE=copy
# Root-side staging of the DELIVERED TREE (venv + full HF hub layout
# 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
stageStt=$stageDir/stt-venv
sttVenv=${hermesHome}/stt-venv
stageHub=$stageDir/kittentts-hf
stageSnap=$stageDir/hf-model
whisperDir=models--Systran--faster-whisper-base
# 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} ${kittenttsSttReqs} ${kittenttsWheel} ${kittenttsStub} \
${kittenttsModelOnnx} ${kittenttsModelVoices} ${kittenttsModelConfig}
echo ${kittenttsRuntimeLibs}; } | sha256sum | cut -d' ' -f1)
echo ${kittenttsRuntimeLibs} ${pkgs.python314} ${whisperModel}; } | sha256sum | cut -d' ' -f1)
stampFile=$stageDir/provision.stamp
# Appends Nix's libstdc++/zlib to every ELF's RPATH. Not auto-patchelf: it
# resolved the wheels' own vendored libs (av.libs) to absolute STAGING
# paths, gone once the venv is copied into hermesHome — STT then failed
# with "libavformat-….so: cannot open shared object file" (2026-10).
# --force-rpath keeps DT_RPATH, which unlike DT_RUNPATH also covers the
# vendored libs' own deps (libctranslate2 -> its bundled libgomp).
add_nix_rpath() {
find "$1" -type f -name '*.so*' -print0 | while IFS= read -r -d "" so; do
patchelf --print-rpath "$so" >/dev/null 2>&1 || continue
patchelf --force-rpath --add-rpath ${pkgs.lib.replaceStrings [ " " ] [ ":" ] kittenttsRuntimeLibs} "$so"
done
}
# 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" ] \
&& [ -x "$stageStt/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" ] \
&& [ -x "$sttVenv/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
&& cmp -s "$stageSnap/voices.npz" "$snap/voices.npz" 2>/dev/null \
&& cmp -s ${whisperModel}/model.bin \
"${hermesHome}/kittentts-hf/hub/$whisperDir/snapshots/${whisperRev}/model.bin" 2>/dev/null; then
exit 0
fi
fi
@@ -724,16 +751,13 @@ in
|| ! [ -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}
uv venv "$stageVenv" --python ${pkgs.python313}/bin/python3 --quiet
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 \
${kittenttsWheelFile}
uv pip install --python "$stageVenv/bin/python" --quiet --no-deps \
${kittenttsWheelFile}
# Dead-import shim: .pth auto-loads kitten_tts_stub at interpreter
# start so `from misaki import en, espeak` resolves without the real
@@ -744,17 +768,18 @@ in
# 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}
add_nix_rpath "$stageVenv"
fi
# STT add-on: faster-whisper into the SAME venv (shares the
# numpy/onnxruntime pins; see kittentts/stt-requirements.txt).
UV_CACHE_DIR=$stageDir/uv-cache \
uv pip install --python "$stageVenv/bin/python" --quiet \
--requirement ${kittenttsSttReqs}
# av's bundled ffmpeg libs also need the stdc++/zlib link (already
# covered by the auto-patchelf pass above — rerun it so the newly
# installed ctranslate2/av binaries get RPATHs too).
auto-patchelf --paths "$stageVenv" --libs ${kittenttsRuntimeLibs}
# STT venv on the image's Python; the KittenTTS freeze as constraints keeps
# the shared numpy/onnxruntime/tokenizers pins.
if [ "$(cat "$stampFile" 2>/dev/null)" != "$inputHash" ] \
|| ! [ -x "$stageStt/bin/python" ]; then
rm -rf "$stageStt"
uv venv "$stageStt" --python ${pkgs.python314}/bin/python3 --quiet
uv pip install --python "$stageStt/bin/python" --quiet \
--requirement ${kittenttsSttReqs} --constraint ${kittenttsReqs}
add_nix_rpath "$stageStt"
fi
# Stage the full delivered hub tree (exact hf_hub_download layout:
@@ -768,6 +793,12 @@ in
# 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).
stageWhisper=$stageHub/hub/$whisperDir
mkdir -p "$stageWhisper/refs" "$stageWhisper/snapshots/${whisperRev}"
printf '%s' "${whisperRev}" > "$stageWhisper/refs/main"
for f in config.json model.bin tokenizer.json vocabulary.txt; do
install -m 0444 ${whisperModel}/$f "$stageWhisper/snapshots/${whisperRev}/$f"
done
# Root-side sanity: the staged interpreter must construct the model
# END-TO-END offline (review2 minor — import alone doesn't exercise
@@ -778,6 +809,8 @@ in
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; KittenTTS("KittenML/kitten-tts-mini-0.8"); print("kittentts offline build ok")' >/dev/null
HF_HOME=$stageHub HF_HUB_OFFLINE=1 \
"$stageStt/bin/python" -c 'from faster_whisper import WhisperModel; WhisperModel("base", device="cpu", compute_type="int8")'
# ---- deliver AS THE CONTAINER USER (review2 #4): root never writes
# into hermesHome, so no symlink race and no `chown` step. setpriv
@@ -787,14 +820,21 @@ in
setpriv --reuid=${hermesUid} --regid=${hermesGid} --clear-groups \
${pkgs.runtimeShell} -c '
set -eu
rm -rf "$1" "$2"
rm -rf "$1" "$2" "$5"
cp -a "$3" "$1"
cp -a "$4" "$2"
cp -a "$6" "$5"
# From the DELIVERED paths: the staging checks above passed while
# STT was broken, because only the copy had lost its libraries.
"$1/bin/python" -c "import numpy, onnxruntime"
"$5/bin/python" -c "import faster_whisper, av, ctranslate2"
' _ \
"${hermesHome}/kittentts-venv" \
"${hermesHome}/kittentts-hf" \
"$stageVenv" \
"$stageHub"
"$stageHub" \
"$sttVenv" \
"$stageStt"
# Stamp LAST, root-owned outside hermesHome — luna can delete it (which
# forces a cheap re-delivery on next boot), not tamper via symlink.