diff --git a/hosts/mars/configuration.nix b/hosts/mars/configuration.nix index 4d3e5d9..19f6456 100644 --- a/hosts/mars/configuration.nix +++ b/hosts/mars/configuration.nix @@ -9,6 +9,7 @@ ./disk-config.nix # disko: OS-disk partitions + filesystems ./secrets.nix # sops-nix: samba/tailscale/hermes secrets ./hermes-agent.nix + ./honcho.nix # luna's memory server (Postgres + Ollama embeddings) ./livesync-bridge.nix ./luna-sites.nix # luna's LAN web apps: http://mars.sol// ../../common.nix # shared base: user / ssh / nix / firewall diff --git a/hosts/mars/honcho.nix b/hosts/mars/honcho.nix new file mode 100644 index 0000000..fab87a8 --- /dev/null +++ b/hosts/mars/honcho.nix @@ -0,0 +1,128 @@ +{ config, pkgs, ... }: + +# Honcho memory server for luna (Hermes's memory provider, once switched in +# Hermes's own config). API + deriver from the official image; Postgres and +# Ollama (embeddings) run natively. Everything binds loopback only. +let + honchoImage = "ghcr.io/plastic-labs/honcho@sha256:c74955d6dbea6dda42c2dd9dd13dea726fcba36ba5c0b6bae4867f7ed762896d"; # v3.2.2 + honchoUid = 984; + honchoGid = 984; + + # :nitro = OpenRouter's fastest-provider routing; the default picks cheap, slow hosts. + fastModel = "z-ai/glm-5.3-flash:nitro"; + # Dreams maintain the peer cards, incl. her AI identity card. + smartModel = "deepseek/deepseek-v4-pro"; + embedModel = "qwen3-embedding:0.6b"; + + # Peer auth over the socket: the container runs as the host's honcho uid, + # so there is no DB password to manage. + env = { + DB_CONNECTION_URI = "postgresql+psycopg://honcho@/honcho?host=/run/postgresql"; + AUTH_USE_AUTH = "false"; + CACHE_ENABLED = "false"; + HOME = "/tmp"; + + LLM_OPENAI_BASE_URL = "https://openrouter.ai/api/v1"; + # Lowest reasoning GLM allows ("none" is rejected): hidden reasoning can + # eat the deriver's whole output budget before any JSON is written. + DERIVER_MODEL_CONFIG__MODEL = fastModel; + DERIVER_MODEL_CONFIG__THINKING_EFFORT = "minimal"; + SUMMARY_MODEL_CONFIG__MODEL = fastModel; + DIALECTIC_LEVELS__minimal__MODEL_CONFIG__MODEL = fastModel; + DIALECTIC_LEVELS__minimal__MODEL_CONFIG__THINKING_EFFORT = "minimal"; + DIALECTIC_LEVELS__low__MODEL_CONFIG__MODEL = fastModel; + DIALECTIC_LEVELS__low__MODEL_CONFIG__THINKING_EFFORT = "minimal"; + DIALECTIC_LEVELS__medium__MODEL_CONFIG__MODEL = smartModel; + DIALECTIC_LEVELS__high__MODEL_CONFIG__MODEL = smartModel; + DIALECTIC_LEVELS__max__MODEL_CONFIG__MODEL = smartModel; + DREAM_DEDUCTION_MODEL_CONFIG__MODEL = smartModel; + DREAM_INDUCTION_MODEL_CONFIG__MODEL = smartModel; + + EMBEDDING_MODEL_CONFIG__MODEL = embedModel; + EMBEDDING_MODEL_CONFIG__OVERRIDES__BASE_URL = "http://127.0.0.1:11434/v1"; + EMBEDDING_MODEL_CONFIG__OVERRIDES__API_KEY = "ollama"; + # Fixed at the first migration; changing it later means a fresh DB. + EMBEDDING_VECTOR_DIMENSIONS = "1024"; + EMBEDDING_MODEL_CONFIG__DIMENSIONS_MODE = "never"; + }; + + container = { + image = honchoImage; + user = "${toString honchoUid}:${toString honchoGid}"; + extraOptions = [ "--network=host" ]; + volumes = [ "/run/postgresql:/run/postgresql" ]; + environment = env; + environmentFiles = [ config.sops.templates."honcho.env".path ]; + }; + + deps = [ "postgresql-setup.service" "honcho-db-setup.service" "ollama.service" ]; +in +{ + users.users.honcho = { + isSystemUser = true; + uid = honchoUid; + group = "honcho"; + }; + users.groups.honcho.gid = honchoGid; + + services.postgresql = { + enable = true; + extensions = ps: [ ps.pgvector ]; + ensureDatabases = [ "honcho" ]; + ensureUsers = [{ + name = "honcho"; + ensureDBOwnership = true; + }]; + }; + + # CREATE EXTENSION needs a superuser; Honcho's migrations only re-assert it. + systemd.services.honcho-db-setup = { + description = "Enable pgvector in the honcho database"; + # ensureDatabases runs in postgresql-setup, not postgresql itself. + after = [ "postgresql-setup.service" ]; + requires = [ "postgresql-setup.service" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + User = "postgres"; + }; + script = '' + ${config.services.postgresql.package}/bin/psql -d honcho -c 'CREATE EXTENSION IF NOT EXISTS vector' + ''; + }; + + services.ollama = { + enable = true; + host = "127.0.0.1"; + loadModels = [ embedModel ]; + }; + + virtualisation.oci-containers.containers.honcho-api = container // { + # Image CMD binds 0.0.0.0 and skips migrations. Migrations create + # vector(1536); configure_embeddings resizes them (no-op once matching, + # refuses on populated tables). + entrypoint = "sh"; + cmd = [ + "-c" + "/app/.venv/bin/python scripts/provision_db.py && /app/.venv/bin/python scripts/configure_embeddings.py --yes && exec /app/.venv/bin/fastapi run --host 127.0.0.1 --port 8000 src/main.py" + ]; + }; + + virtualisation.oci-containers.containers.honcho-deriver = container // { + # Waits for the API, i.e. for the schema resize above. + entrypoint = "sh"; + cmd = [ + "-c" + "until /app/.venv/bin/python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2)\" 2>/dev/null; do sleep 2; done; exec /app/.venv/bin/python -m src.deriver" + ]; + }; + + systemd.services.podman-honcho-api = { + after = deps; + requires = deps; + }; + systemd.services.podman-honcho-deriver = { + after = [ "podman-honcho-api.service" ]; + requires = [ "podman-honcho-api.service" ]; + }; +} diff --git a/hosts/mars/secrets.nix b/hosts/mars/secrets.nix index d7b6220..6b72843 100644 --- a/hosts/mars/secrets.nix +++ b/hosts/mars/secrets.nix @@ -98,4 +98,13 @@ # markdown to disk. Also feeds the bridge's separate obfuscatePassphrase # field, since the plugin derives path obfuscation from the same value. sops.secrets.obsidian_luna_passphrase = { }; + + # Honcho (honcho.nix): OpenRouter key for its own LLM calls. + sops.secrets.openrouter_api_key = { }; + sops.templates."honcho.env" = { + content = '' + LLM_OPENAI_API_KEY=${config.sops.placeholder.openrouter_api_key} + ''; + restartUnits = [ "podman-honcho-api.service" "podman-honcho-deriver.service" ]; + }; } diff --git a/secrets/mars.yaml b/secrets/mars.yaml index e2d8930..26d6bb8 100644 --- a/secrets/mars.yaml +++ b/secrets/mars.yaml @@ -10,6 +10,7 @@ couchdb_luna_password: ENC[AES256_GCM,data:V91is2h7UskI1rtwMzQyduNXoDPTYNwa4sw9K obsidian_luna_passphrase: ENC[AES256_GCM,data:fqHtP3g4J40ddYL9lzCixrisdC/DEJJermE=,iv:FU6BGNcBnyP8Rz3dNBk0+K0aAQTDW6/0aVaFm1rBFkk=,tag:Mg1aKqh++2rmU8ROaVIgDw==,type:str] elevenlabs_api_key: ENC[AES256_GCM,data:2oJeClO4/SFsbLwRgMe3bFXrmuDX7YOc57VfSjElV5A3vaIQqfN9eHzo/cm0vISxYgUv,iv:eIeKQJ6odDnmGLjHSLV3HbErVnLr7tatOtV83TvB2QA=,tag:XPkXRfDJ2ZK98TYXKeK/CA==,type:str] hermes_api_server_key: ENC[AES256_GCM,data:Au80iziwdryFTCLnggC9DdjjZPrGPKpmRFgkXe/l9RQ7on9nXb1dvQ==,iv:hWvv4fLkhRgVTT2btI+TvpNBHfMOg9y4BQKn+ht7XDo=,tag:2dEZEys8vsTwc7w0ZiBK1w==,type:str] +openrouter_api_key: ENC[AES256_GCM,data:klv/11iORtM8nbUv7RB79AyVM996V8vCU6hrTqgREnTkRW3b5PcOWXl0XdW2fr5JW4lvm6V4qYUsP62cJuVyCL3d6qA2dZCdJQ==,iv:bKMYMpbP0xsipt79sMCKuJoh5T+9GiUKwDVNZe3Sa7Q=,tag:iNOy3X0cygMlkllyWTwphg==,type:str] sops: age: - enc: | @@ -30,7 +31,7 @@ sops: oyJ7PS3lW+PxH5AZkeeU7gXO/pz2oDku0aDOds7kaD3n0+qSWicQ+Q== -----END AGE ENCRYPTED FILE----- recipient: age1eapjg6tdrr0fuvmgs3q3nlvnjkaxez298qynqqqxt0lpcv0lrsyq7ayxjk - lastmodified: "2026-10-01T23:50:54Z" - mac: ENC[AES256_GCM,data:laNlbKw+0uylEUnTuVSCvZWrcb+hz6my/30J5orSK4jy0VsQR9Sae7js8FJWPzQC32MRiVl3Xo4UAwbLyUCzjlrhMnOZ5/xvVY68weRUVE9OCeUVk/8YIobRpmhAI6sZJCp4H6Sy7j9zmBuyPoF0pB2dKo+NaPnHsvIqO8/tce4=,iv:Ms5i2VU7xvrx1KGupmVOk95OfpcUEgAruWu0kMFoI9o=,tag:JcoGyCnabiM3h9eta6liFA==,type:str] + lastmodified: "2026-10-02T15:22:08Z" + mac: ENC[AES256_GCM,data:CQg/l8n+PjOurIGabN2fKpNv45v8/i9rUzTUoUANFi8BY9YrNWMeBkGEMDS03HyuzPMz+7dtgjVpopPpi7LcB3o0SUbW1x61izFMMP2XjBM08kmW0DT0kGKW2zqeqiogczJsgvKI7g5iZIpOGPvTRluZut8BZ7SCV5j8e1Jz9pA=,iv:XMMA5PVlNpvxXGC/v20V6MndRgQNbjfNrAj64OAAK4o=,tag:IQhHG/PaWI26pywXrY57Wg==,type:str] unencrypted_suffix: _unencrypted version: 3.13.3