docs: the full migration plan; ci: deploy NixOS hosts
All checks were successful
nixos / nixos (push) Successful in 55s
All checks were successful
nixos / nixos (push) Successful in 55s
MIGRATION.md is now the complete plan for moving production from Ansible and Terraform to NixOS and OpenTofu: what was rehearsed and how, the preparation that needs no downtime, one runbook per host with its checks and rollback, the clean-up including the branch renames, and the rules for running restored production data on test servers. The NixOS workflow now deploys on main, ops first, building on each host. It checks /etc/NIXOS before touching a host, so it skips both servers until their conversion and cannot reach a Debian one. known_hosts moves to the repository root for it. Renovate learns the Nix files: version comments, the runner's job images and flake.lock (weekly). The Ansible patterns stay until Ansible is gone. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
fa46d26f89
commit
ebbf458983
2 changed files with 434 additions and 210 deletions
|
|
@ -2,32 +2,43 @@
|
|||
|
||||
Each server's whole system, as one flake. A server is created by OpenTofu
|
||||
(`../terraform`), converts itself to NixOS on first boot, and gets its
|
||||
configuration from here. Moving the services over from `../ansible` is in
|
||||
progress: see `../MIGRATION.md` for what already lives here.
|
||||
configuration from here. Production is moving over from `../ansible`;
|
||||
the plan and its state are in `../MIGRATION.md`.
|
||||
|
||||
```
|
||||
flake.nix inputs (nixpkgs 26.05, unstable for a few packages, sops-nix), hosts, dev shell
|
||||
modules/hetzner.nix disk, boot and network of a Hetzner Cloud VM
|
||||
modules/base.nix users, SSH, fail2ban, firewall, journal cap, Nix settings
|
||||
modules/wireguard.nix the admin network; ops is the hub
|
||||
modules/podman.nix Podman, for what has no native NixOS service
|
||||
modules/backup.nix nightly restic backup, `restic-backup` command
|
||||
modules/alert.nix mail when a unit fails
|
||||
hosts/asxpio-ops/ what only asxpio-ops has
|
||||
hosts/asxpio-services/ what only asxpio-services has, one file per service
|
||||
hosts/rehearsal/ overrides that turn the two hosts into a test pair
|
||||
migration/ one-off scripts that move Debian-era data into place
|
||||
secrets/*.yaml sops-encrypted, one file per host
|
||||
flake.nix inputs (nixpkgs 26.05, unstable for a few packages, sops-nix), hosts, dev shell
|
||||
modules/hetzner.nix disk, boot and network of a Hetzner Cloud VM
|
||||
modules/base.nix users, SSH, fail2ban, firewall, journal cap, Nix settings
|
||||
modules/wireguard.nix the admin network; ops is the hub
|
||||
modules/podman.nix Podman, and the Docker CLI on its socket
|
||||
modules/backup.nix nightly restic backup, `restic-backup` command
|
||||
modules/alert.nix mail when a unit fails
|
||||
modules/monitoring-agent.nix node, container and security metrics, logs to Loki
|
||||
hosts/asxpio-ops/ Traefik, Forgejo, Postgres, Garage, monitoring, app stacks
|
||||
hosts/asxpio-services/ runners, Minecraft, XMPP, Xray, SillyTavern, one file each
|
||||
hosts/rehearsal/ overrides that turn the two hosts into a test pair
|
||||
migration/ one-off scripts: Debian-era data into place, rehearsal clean-up
|
||||
secrets/*.yaml sops-encrypted, one file per host
|
||||
```
|
||||
|
||||
Services run as native NixOS services wherever nixpkgs has a module;
|
||||
the rest are Podman containers declared here. There is no Docker.
|
||||
the rest are Podman containers declared here (XMPP) or deployed by their
|
||||
own repositories (the app stacks on ops). There is no Docker daemon:
|
||||
`docker` is the Docker CLI talking to Podman's socket, so `docker ps`,
|
||||
`docker compose` and the apps' CI deploys work as they did.
|
||||
|
||||
Each service file also says what it adds to the backup
|
||||
(`asxpio.backup`), which ports and users the security baseline should
|
||||
expect (`asxpio.security`), and whether it waits for restored data
|
||||
(`asxpio.waitForData`).
|
||||
|
||||
All tools used below come from the dev shell: `nix develop ./nixos`.
|
||||
|
||||
## Changing something
|
||||
|
||||
Edit, push a branch (CI evaluates every host), then switch the host:
|
||||
Edit, push a branch (CI evaluates every host), merge to `main`: CI
|
||||
builds each host on itself and switches to it, ops first. A host that
|
||||
does not run NixOS yet is skipped. By hand, over WireGuard:
|
||||
|
||||
```sh
|
||||
nixos-rebuild switch --flake .#asxpio-services \
|
||||
|
|
@ -36,8 +47,11 @@ nixos-rebuild switch --flake .#asxpio-services \
|
|||
|
||||
Only units whose definition changed restart. Undo with
|
||||
`nixos-rebuild switch --rollback` on the host, or pick the previous
|
||||
generation in the boot menu (Hetzner console). Update all packages with
|
||||
`nix flake update`, then commit `flake.lock`.
|
||||
generation in the boot menu (Hetzner console). Package updates come from
|
||||
Renovate (`flake.lock` weekly, pinned images and versions as they are
|
||||
released); by hand: `nix flake update`, commit `flake.lock`.
|
||||
|
||||
Try anything risky on the rehearsal pair first (below).
|
||||
|
||||
## Building the servers from scratch
|
||||
|
||||
|
|
@ -170,9 +184,17 @@ hcloud server create --name rehearsal-services --type cx23 --image debian-13 --l
|
|||
|
||||
Then, per server: put its age recipient in `.sops.yaml` (`&rehearsal_*`)
|
||||
and `sops updatekeys secrets/rehearsal-<role>.yaml`; put its addresses in
|
||||
`hosts/rehearsal/<role>.nix`; `nixos-rebuild switch --flake
|
||||
`hosts/rehearsal/<role>.nix` (and ops's public key in services' file,
|
||||
the other way round for WireGuard); `nixos-rebuild switch --flake
|
||||
.#rehearsal-<role> --target-host root@<ip> --build-host root@<ip>`;
|
||||
reboot once; `touch /var/lib/.data-in-place`.
|
||||
reboot once.
|
||||
|
||||
With test data: `touch /var/lib/.data-in-place`. With a restored copy of
|
||||
production: restore last night's snapshot to `/restore`, run
|
||||
`migration/ops-data.sh /restore` or `services-data.sh /restore`, and on
|
||||
ops `migration/rehearsal-sanitize-forgejo.sh` before the runner starts.
|
||||
Read the rehearsal rules in `../MIGRATION.md` first: restored data
|
||||
carries production credentials.
|
||||
|
||||
## How the first boot works, and its limits
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
restic
|
||||
rclone
|
||||
jq
|
||||
openssh
|
||||
];
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue