# Self-hosted AI assistant

> Lisa, a declarative NixOS home server centralising my files with stable IDs, git memory, email, calendar and one MCP gateway for any AI agent.

- Role: Solo project
- When: Sept 2026 – present
- Stack: NixOS, TypeScript, Node.js, React, SQLite, MCP, WebAuthn, Syncthing, Restic, WebDAV, CalDAV
- Links: [cli-memoria on GitHub](https://github.com/PabloPC05/cli-memoria)
- Image: [Diagram: AI clients connect to one MCP endpoint on Lisa (NixOS server) serving files with stable IDs and encrypted backups, git memory, email, calendar and a passkey-only web dashboard](https://ppardocotos.com/_astro/self-hosted-assistant.en.Bl9G1Xzo.svg)
- URL: https://ppardocotos.com/projects/self-hosted-assistant

I switch AI clients constantly — Claude Code, claude.ai, Codex — and didn't want tools, files and memory scattered across cloud silos and isolated sessions. The constant is **Lisa**, a declarative **NixOS** home server that acts as my personal source of truth; the client and model are whatever fits that day.

## How the four pieces fit together

<div class="decisiones una-col">
<div class="decision">
<div class="cab"><b>1. The agent gateway — <a href="https://ppardocotos.com/projects/badulaque">Badulaque</a></b><span class="tag ok">−66% cost</span></div>
<p>One MCP endpoint with a key per agent and two tools — a server-enforced read-only tool and a write tool — running inside ephemeral <code>bubblewrap</code> sandboxes with agent-oriented CLIs. Real secrets never enter the sandbox: a proxy injects them on exit only towards their authorised domain.</p>
</div>
<div class="decision">
<div class="cab"><b>2. Shared memory — <a href="https://ppardocotos.com/projects/cli-memoria">cli-memoria</a></b><span class="tag ok">Apache-2.0</span></div>
<p>Around 300 pure-Markdown notes in git — no LFS, no OCR — shared across every agent, with lexical search (SQLite FTS5) and write rules enforced in code. Instead of embedding binaries, notes cite documents in the file store by stable ID.</p>
</div>
<div class="decision">
<div class="cab"><b>3. Files as source of truth, stable IDs and selective sync</b><span class="tag ruido">SQLite · Restic · Syncthing</span></div>
<p>Personal documents live on the server with no plaintext cloud mirror. A SQLite index assigns every document a <strong>permanent ID</strong> — tracked across renames via inode and SHA-256 — and maintains a cross-reference table with the memory: moving a file automatically updates its citations in notes. The CLI also reads PDFs, office formats and handwritten <code>.xopp</code> notebooks.</p>
<p style="margin-top:0.45rem">Coursework lives separately and syncs in a star topology via <strong>Syncthing</strong> from my laptop: the server keeps notes and PDFs (available to agents and mobile) while an isolated development VM keeps only code and git repositories, filtering build artefacts on every node. On-demand mobile and desktop access runs over <strong>WebDAV</strong>, and <strong>hourly encrypted restic backups</strong> replicate documents, coursework, memory and code off-site with weekly automated restore checks.</p>
</div>
<div class="decision">
<div class="cab"><b>4. Web dashboard and personal services</b><span class="tag ruido">React · Node · WebAuthn</span></div>
<p>One control panel for the whole server: unified email (Gmail, iCloud, Microsoft 365 and IMAP), file browser with encrypted backup status, memory viewer, health metrics, an on-demand remote browser I can take over anytime, and per-agent controls. Calendar, reminders and contacts sync over CalDAV and CardDAV without needing my laptop or phone awake. Dashboard login is <strong>passkey-only</strong> (Face ID / Touch ID), with passwords disabled.</p>
</div>
</div>

## How data flows

<div class="flujo">
<div class="paso"><b>Devices</b>Laptop and phone via selective Syncthing and on-demand WebDAV.</div>
<span class="flecha" aria-hidden="true">→</span>
<div class="paso caja"><b>Lisa (NixOS)</b><ul><li>files with stable IDs</li><li>git memory &amp; dashboard</li><li>Badulaque + code VM</li></ul></div>
<span class="flecha" aria-hidden="true">→</span>
<div class="paso"><b>AI agents</b>See only permitted data in ephemeral sandboxes and cite files by ID.</div>
<span class="flecha" aria-hidden="true">→</span>
<div class="paso"><b>Encrypted backup</b>Hourly restic off-site, unreadable without my local key.</div>
</div>

## Operations and security by design

<div class="decisiones">
<div class="decision">
<div class="cab"><b>Declarative with auto-rollback</b><span class="tag ok">NixOS flake</span></div>
<p>Both the server and its development VM are built from a single reproducible flake. Remote deployments activate with a timed, lock-serialised automatic rollback so a bad network or config change reverts cleanly on its own.</p>
</div>
<div class="decision">
<div class="cab"><b>Least privilege at every layer</b><span class="tag ok">Isolation</span></div>
<p>Each service runs under its own Unix user with systemd sandboxing; secrets stay out of git and the Nix store and are injected at startup. Administration is restricted to a private mesh VPN with key-only SSH.</p>
</div>
<div class="decision">
<div class="cab"><b>No reusable passwords</b><span class="tag ok">Passkeys · TLS</span></div>
<p>The dashboard enforces user-verified WebAuthn passkeys with single-use out-of-band recovery. Syncthing authenticates peers by TLS certificate with relays and global discovery off, and remote file access layers geo-restriction, brute-force blocking and login alerts.</p>
</div>
<div class="decision">
<div class="cab"><b>Zero plaintext cloud lock-in</b><span class="tag ok">E2E encrypted</span></div>
<p>No plaintext two-way sync with third-party clouds: if an external provider fails or changes terms, the canonical data stays at home and off-site backups remain end-to-end encrypted.</p>
</div>
</div>

The benchmarks and papers behind the gateway and memory architecture are collected in [this blog post](https://ppardocotos.com/blog/measuring-mcp-and-agent-memory).
