NixOS flake + system module for the Pi coding agent (pi.dev) on the cc-ci-orchestrator Hetzner host.
README.md

pi-orchestrator #

A small Nix flake that installs the Pi coding agent (the pi CLI from @earendil-works/pi-coding-agent) onto the cc-ci-orchestrator-hetzner NixOS host, and wires that install into the host's system flake so a normal nixos-rebuild turns it on.

Pi is a minimal, extensible agent harness — see pi.dev and the upstream README. This repo does not contain anything Pi-specific beyond the flake that installs it; the binary, the runtime config, and the agent sessions all live elsewhere (in the nix store and under ~/.pi/).

What's in here #

flake.nix        # packages.pi-coding-agent (from nixos-unstable) + a NixOS module
flake.lock       # pins nixos-unstable (currently 61b7c44c → pi-coding-agent 0.80.8)
agent-orchestrator/   # git submodule — the agent-orchestrator engine (tangled.org/notplants-bot.bsky.social/agent-orchestrator)
SECRETS.md       # where to find the gitignored Tangled creds (NOT in this repo)
.gitignore       # belt-and-braces guard against dropping secrets in here

Why a separate flake? #

pi-coding-agent is in nixos-unstable (pkgs/by-name/pi/pi-coding-agent/) but not in the nixpkgs rev the host flake (/srv/cc-ci-orch/flake.nix) is pinned to (24.11, rev 50ab793). Rather than bump the whole host to unstable, this flake pins unstable independently and exposes a NixOS module the host imports. The cost is a second nixpkgs evaluation; the win is zero churn to the host's existing pinned deps (sops-nix, buildGo125Module, etc.).

How to rebuild with Pi turned on #

The host is built from the flake at /srv/cc-ci-orch#cc-ci-orchestrator-hetzner, not /etc/nixos (which is an intentional landmine — see its header comment). Everything below operates on /srv/cc-ci-orch after this flake has been wired in there (input pi-orchestrator, module pi-orchestrator.nixosModules.pi-coding-agent, and programs.pi-coding-agent.enable = true; in nix/hosts/cc-ci-orchestrator-hetzner/configuration.nix).

1. Build first, switch only if it builds #

Always dry-build before switching — this host has reboot-bricked before from a bad rebuild (see /etc/nixos/configuration.nix's header). The build writes a store path; it does not touch the running system.

# from anywhere, as the loops user (passwordless sudo via wheel)
nix build /srv/cc-ci-orch#nixosConfigurations.cc-ci-orchestrator-hetzner.config.system.build.toplevel \
  --no-link --print-out-paths

A path prints (/nix/store/...-nixos-system-nixos-...); no error → safe to switch. The build above has already been verified to produce a closure that contains /run/current-system/sw/bin/pi.

2. Switch the running system #

sudo nixos-rebuild switch --flake /srv/cc-ci-orch#cc-ci-orchestrator-hetzner

This atomically swaps /run/current-system to the new closure and restarts any changed systemd units. Existing services (opencode-web, cc-ci-loops, lichen-orchestrator, the lm instances, etc.) are unaffected unless their definitions changed — and the only change in this rebuild is the addition of pi to environment.systemPackages.

3. Verify #

which pi                          # → /run/current-system/sw/bin/pi
pi --version                     # → 0.80.8 (or whatever flake.lock pins)
readlink -f $(which pi)          # → /nix/store/...-pi-coding-agent-0.80.8/bin/pi

If pi isn't on PATH, log out and back in (the per-shell PATH cache needs to refresh) or run hash -r.

Rollback (if anything looks wrong) #

sudo nixos-rebuild switch --rollback         # back to the previous /run/current-system generation
# or, to roll forward again:
sudo nixos-rebuild switch --flake /srv/cc-ci-orch#cc-ci-orchestrator-hetzner

NixOS keeps every generation; --rollback is instant and safe.

What the rebuild does NOT touch #

  • /etc/nixos/ — left alone (it's the dead nixos-infect tree).
  • /srv/cc-ci/, /srv/lichen-orchestrator/, the lm tmux sessions — no path or service changes.
  • The bot's SSH key, the Tangled session cookie — both live outside any path this rebuild writes.
  • The standalone claude and opencode binaries in ~/.local/bin/ — untouched; pi is an additive install alongside them, not a replacement.

How to use pi.dev #

Pi is a minimal agent harness: it gives the model four tools (read, write, edit, bash) and otherwise stays out of the way. It does not ship sub-agents, plan mode, or permission popups by default — those are extensions or packages you add yourself.

First run: authenticate #

Pi supports 15+ providers (Anthropic, OpenAI, Google, Azure, Bedrock, Mistral, Groq, Cerebras, xAI, OpenRouter, Ollama, …). On first launch it will walk you through picking one and entering an API key, or you can pre-seed:

pi                            # interactive TUI — first run prompts for provider + key
# or non-interactive:
pi -p "Add a hello.txt that says hi" --model anthropic/claude-sonnet-4

The model id format is <provider>/<model>. Cycle favorites with Ctrl+P, switch mid-session with /model or Ctrl+L. API keys live in ~/.pi/agent/ (per-provider files; mode 600).

This host already has provider creds in two places you can reuse if you'd rather not re-enter them:

  • /srv/cc-ci/.testenv — the env file opencode-web.service reads (Anthropic/OpenAI/etc keys as ANTHROPIC_API_KEY=… style lines). set -a; . /srv/cc-ci/.testenv; set +a to load them into a shell before launching pi.
  • ~/.local/share/opencode/auth.json — opencode's creds (mode 600), if you want to copy a key out by provider.

Common commands (inside the TUI) #

Key / command Action
/help all commands
/model switch model (or Ctrl+L)
Ctrl+P cycle favorite models
/tree navigate the session tree (sessions are branched trees, not linear)
/export export current session to HTML
/share upload to a GitHub gist, get a shareable URL
/reload reload extensions/skills/prompts after editing them
Enter send a steering message (delivered after the current tool, interrupts the rest)
Alt+Enter send a follow-up (waits until the agent finishes)
/exit or Ctrl-D quit

Project instructions #

Pi loads AGENTS.md on startup from (in order) ~/.pi/agent/, parent directories, and the current directory. To give Pi project-specific rules, drop an AGENTS.md next to what you're working on. To replace or append to the default system prompt per-project, use SYSTEM.md.

Running in tmux (survives disconnects) #

Pi is a TUI; if your SSH drops, the TUI dies. Run it in tmux like the other agents on this host:

tmux new -s pi
cd /srv/some-project
pi
# detach: Ctrl-b then d
# reattach: tmux attach -t pi

Non-interactive / scripted use #

pi -p "Summarize this repo"                    # print mode — one-shot, exits
pi --mode json -p "List the tests"             # JSON event stream for scripts / RPC integrations

See the docs for the RPC and SDK modes (embed Pi in another app).

Where state lives #

  • ~/.pi/agent/ — config, AGENTS.md, models.json, auth (per-provider API keys)
  • ~/.pi/sessions/ — session tree files (one file per session, branches included)
  • PI_CODING_AGENT_DIR env var — override the config dir
  • PI_CODING_AGENT_SESSION_DIR env var — override the session dir

The nixpkgs wrapper sets PI_SKIP_VERSION_CHECK=1 and PI_TELEMETRY=0, so Pi will not phone home for update checks or telemetry. It also puts ripgrep and fd on Pi's PATH so its file-search tools work out of the box.

Updating Pi #

Bump the pinned nixpkgs in this flake to a newer unstable rev (which pulls in a newer pi-coding-agent), then rebuild the host:

cd /srv/pi-orchestrator
nix flake update                    # updates flake.lock to latest nixos-unstable
nix eval .#pi-coding-agent.version  # check the new version
git add flake.lock && git commit -m "Bump pi-coding-agent to <version>"
git push

# then rebuild the host as in §"How to rebuild":
nix build /srv/cc-ci-orch#nixosConfigurations.cc-ci-orchestrator-hetzner.config.system.build.toplevel \
  --no-link --print-out-paths
sudo nixos-rebuild switch --flake /srv/cc-ci-orch#cc-ci-orchestrator-hetzner

The flake.lock in this repo is the source of truth — the host flake follows whatever pi-orchestrator input this repo's main branch points at.

Repo layout on the host #

/srv/pi-orchestrator/        this repo (the flake you're reading)
  agent-orchestrator/        submodule → tangled.org/notplants-bot.bsky.social/agent-orchestrator
/srv/cc-ci-orch/             the HOST flake — imports pi-orchestrator as a flake input
  flake.nix                  adds pi-orchestrator input + nixosModules.pi-coding-agent
  nix/hosts/cc-ci-orchestrator-hetzner/configuration.nix
                             sets programs.pi-coding-agent.enable = true
/srv/lichen-orchestrator/    sibling orchestrator; hosts the Tangled creds (see SECRETS.md)

See SECRETS.md for where the gitignored Tangled credentials (SSH key, session cookie) live on this host, and how to refresh them.