Anyone with the repo and the secrets should be able to rebuild the servers. nixos/README.md covers building from nothing, reinstalling in place and the rehearsal pair; RESTORE.md covers restoring from the restic backups; MIGRATION.md is the plan and runbook for moving production over, with what was learned on the test servers. CI evaluates every host on a push under nixos/. It does not deploy yet: no production host runs NixOS. Assisted-by: Claude:fable-5-2
11 KiB
Moving from Ansible to NixOS
Plan and runbook. Delete this file when the last step is done.
Goal: both servers run NixOS built from nixos/; services are
native NixOS services where nixpkgs has a module and Podman containers
otherwise; no Docker, no Ansible. The servers themselves stay (they are
billed below list price): each is converted in place.
Where things stand (2026-11-16)
Both servers still run Debian and are still deployed by Ansible from
main. Nothing below has touched them.
On branch nix, each item verified on the rehearsal pair
(nixos/README.md):
- OpenTofu renders one cloud-init for both servers; a new or rebuilt server becomes NixOS by itself in about three minutes. OpenTofu plans no change to the live servers.
- The same conversion run by hand on a Debian host with Docker data
keeps everything on disk (under
/old-root), SSH host keys included. - Base system: users with their Debian UIDs, SSH with the same crypto settings, fail2ban, nftables firewall, journal cap, Podman.
- Secrets in sops, per host; the production files already hold the WireGuard keys, the Xray config, the restic password, the S3 keys and the alert mail account.
- WireGuard: hub on ops, spoke on services, IPv4 and IPv6 through the tunnel, NAT on the hub.
- asxpio-services: Xray, SillyTavern, Minecraft (Paper, with Geyser) and the ACME forwarder as native services; XMPP as Podman containers (ejabberd started with test secrets; not started on production data).
- asxpio-ops: Postgres 18.7, Garage 2.5.0 and Forgejo 17.0.1 as native services, with roles, buckets, keys and grants set from sops.
- Backup: the same script, schedule and retention; a run with hooks and a restore were done against local repositories.
- Real data: last night's backups of both hosts were restored onto
the rehearsal pair and moved into the new layout with
nixos/migration/*-data.sh. Forgejo served the repositories, Postgres had the 13 tables and the read-onlybingorole, Garage the buckets and objects, Minecraft the world (Java and Bedrock ports), SillyTavern its users. Restore times: ops 6.3 GiB in under a minute, services 25 GiB in three and a half.
Found by rehearsing, fixed in the config: Garage refuses a credential
file with mode 0440; Geyser needs libcrypto and netlink, which the
container had and the NixOS unit did not; SillyTavern ignores the
module's listen flags.
Still to port, in this order:
- asxpio-services:
s3_replicate, the monitoring agent, both CI runners (against the rehearsal Forgejo). - asxpio-ops: Traefik, monitoring,
crawler_alert,xmpp_cert_sync, the app stacks on Podman with their new database and S3 addresses. - Retire the
storagerepo once ops is converted: Postgres and Garage are defined here now.
What each service becomes
Versions: nixpkgs 26.05 on 2026-11-16 against what runs today.
| Today (Ansible role, container) | On NixOS | Data move |
|---|---|---|
base, ssh_hardening, swap |
modules/base.nix, host files (done) |
none |
wireguard |
networking.wireguard + sops |
keys from the vault; same keys, so peers do not change |
traefik 3.7.19 |
native services.traefik (3.7.16), routes as Nix instead of container labels |
acme.json |
forgejo 17.0.1 |
native services.forgejo (17.0.1) |
/opt/forgejo/data to /var/lib/forgejo, SQLite as is |
| storage: Postgres 18.7 | native services.postgresql (18.7) |
pg_dumpall, load (the image is musl, the package glibc: no reuse of the data directory) |
| storage: Garage 2.5.0 | native services.garage with a 2.x package (the default is 1.3.1: pin it) |
metadata and data directories as is |
monitoring: Prometheus, Grafana, Loki, blackbox |
native modules | Grafana DB, Prometheus TSDB optional; Loki chunks are in S3 |
monitoring_agent: Alloy, node-exporter, cAdvisor |
native services.alloy, services.prometheus.exporters.node; cAdvisor against Podman |
none |
restic_backup |
services.restic.backups, same repositories, hooks and schedule |
none (repositories continue) |
s3_replicate, crawler_alert, xmpp_cert_sync |
systemd units from Nix | none |
forgejo_runner, forgejo_runner_interop 13.2.1 |
native services.gitea-actions-runner (forgejo-runner 13.2.1), jobs in Podman |
re-register or copy .runner |
xray 26.11.9 |
native services.xray |
config from the vault |
sillytavern 1.19.0 |
native services.sillytavern |
data directory |
minecraft (Paper on temurin 21) |
native services.minecraft-server with papermc |
world directory; check the Paper build matches the world |
xmpp (anotherim-server, apushd, tackygram) |
Podman containers: the server is a custom build, not nixpkgs' ejabberd | volumes |
acme_forward (nginx) |
native services.nginx, or dropped if XMPP certs move to security.acme |
none |
| App stacks: asxpio, datacenterbingo, blog, czsk, vhpbot | Podman, started by their own CI as today, through the Docker-compatible socket; a flake per app is a later project in each app's repo | none (/opt/<app>) |
Traefik has a native module, so it stays. Its Docker provider reads
labels from Podman's socket as well; routes for native services go in
the file provider, written from Nix. Caddy (services.caddy) would be
the simpler native choice, but changing proxy and operating system in
one move doubles what can go wrong: reconsider after step 6.
Steps
-
Secrets (done for what is ported). sops-nix:
nixos/secrets/<host>.yaml, encrypted for an admin age key and each host's SSH host key. Values move over from the Ansible vault as their services move. The vault password leaves CI at the end. -
Network and access first (done): WireGuard, firewall, SSH. An admin reaches a converted host the usual way.
-
Port asxpio-services (no chicken-and-egg: Forgejo and CI live or depend on ops), service by service from the table, each one tried on the rehearsal pair. Before the conversion, restore last night's backup of the host onto the rehearsal server and check each service comes up on real data (versions differ slightly from the containers: table above).
-
Convert asxpio-services (runbook below). Add the deploy job to
.forgejo/workflows/nixos.yaml: onmain,nixos-rebuild switch --target-hostas userdeploy. Remove the services roles fromansible/site.yaml. -
Port asxpio-ops the same way. Order inside the host: Postgres and Garage, Forgejo, Traefik, monitoring, then the app stacks on Podman. Rehearse the app deploy workflows against Podman before the day.
-
Convert asxpio-ops (runbook below), from a workstation: its own CI cannot deploy the host it runs through.
-
Clean up. Delete
ansible/,deploy.yaml, the vault secret in CI,/old-rooton both hosts, the Postgres 17 volume, this file. Then make the branch the default:git push origin main:retired/ansible # keep the old line # Forgejo: Settings -> Branches -> default branch: nix; unprotect main git push origin --delete main git push origin nix:main # Forgejo: default branch: main; then git push origin --delete nix git branch -m main retired/ansible && git branch -m nix mainDo this last: until then
mainis what deploys the hosts.
Each step ends with both hosts working, so the work can stop between any two.
Converting a host in place
Tested end to end on 2026-11-16 (cx23, Debian 13, Docker 29.9.3): the conversion took three and a half minutes, containers and volumes were intact afterwards. Expect 15 to 30 minutes of downtime per host, depending on how much data changes format (table above).
Before:
- Announce the window; no CI job running.
restic-backup runon the host and check both repositories.- Take a Hetzner snapshot of the server. This is the rollback: rebuilding from it returns the Debian system as it was, on the same server.
- Stop the services so nothing writes during the move
(
docker stop -t 120 minecraftfirst on services), then stop Docker. Take the dumps the new services load:pg_dumpallon ops.
Convert (as root on the host; the same commands cloud-init runs):
-
Write
/etc/nixos/bootstrap.nixwith the content fromterraform/cloud-init/nixos.yaml.tftpl(tofu output user_datashows it with the values filled in). -
Run the
runcmdline from the same file. The host reboots into a bare NixOS. Reach it as root: ops on its public address, services through ops over the private network. -
nixos-rebuild switch --flake .#<host>(seenixos/README.md). Services that own data stay stopped: the marker file is missing. -
Move the data and start everything, then reboot once:
ssh root@<host> 'bash -s /old-root' < nixos/migration/<ops|services>-data.shOn ops the script loads the Postgres dump from
/old-root/var/backups/restic-stage: putpg_dumpall.sqland asqlite3 .backupof Forgejo's database (forgejo-gitea.db) there in step 4. What the script does not move stays in/old-root:/home,/root/backups, the app stacks'/opt/<app>. -
Verify: WireGuard up, every service of the host answers,
systemctl --failedempty, one CI run, one backup run.
After a week without surprises: rm -rf /old-root, delete the snapshot.
Rollback, at any point after step 6: hcloud server disable-protection <host> rebuild, rebuild from the snapshot, tofu apply.
Rules for the rehearsal pair
- Restored data carries production credentials inside it. Anything that
would use them outward is kept from starting in
hosts/rehearsal/: XMPP and the Telegram gateway, Forgejo's mail, mirrors and webhooks, Minecraft's Discord plugin. On 2026-11-16 that plugin was missed on the first start: the bot logged in from the test server for about 15 seconds and cleared its slash commands on shutdown. Check a service's plugins and integrations before its first start on real data. - A Hetzner firewall limits SSH to the admin; the backup credentials are
on the servers only in
/runand only during a restore. - Delete the servers when testing ends: they hold production data.
Risks
- Lock-out. A converted host without WireGuard is reachable only as described in step 6. Step 2 exists to remove that risk; the Hetzner console is the last resort.
- ops is small. 18 GB free today; the Nix store takes 3 to 5 GB and
/old-rootanother 2 GB plus the old container images. Prune images before, delete/old-root/var/lib/dockerearly. - App deploys on Podman. The app workflows call
docker compose; compose against Podman's socket mostly works, healthcheck waits and network names are where it differs. Rehearse (step 5). - The CI runner on Podman starts job containers through the socket;
the earlier attempt (branch
nixos-services) had this working piece by piece but never under a full pipeline. - First-boot method. nixos-infect depends on the scripted initrd,
which upstream is retiring (
nixos/README.md, last section).