nixos: describe both servers as NixOS systems

Start of the move from Ansible to NixOS. Services run as native NixOS
services where nixpkgs has a module and as Podman containers otherwise;
there is no Docker.

Shared: users with their Debian UIDs, SSH with the Ansible role's crypto
settings, nftables firewall, WireGuard (ops is the hub), sops-nix
secrets per host, the restic backup script with its schedule and
retention, mail on unit failure.

asxpio-services: Xray, SillyTavern, Minecraft (Paper) and the ACME
forwarder natively; XMPP stays in containers because the server is a
custom build.

asxpio-ops: Postgres, Garage and Forgejo natively. Roles, buckets, keys
and grants move here from the storage repo's init scripts.

Services that own data wait for /var/lib/.data-in-place, so an install
never creates empty state where a restore is about to land.
migration/*-data.sh move the Debian-era data into the new layout.

hosts/rehearsal turns the two hosts into a test pair with its own keys
and dummy secrets. Everything here ran there, Postgres, Garage, Forgejo,
Minecraft and SillyTavern on a restored copy of production data. Three
differences from the containers showed up and are handled: Garage
rejects a 0440 credential file, Geyser needs libcrypto and netlink,
SillyTavern ignores the module's listen flags.

Production is untouched: both servers still run Debian under Ansible.

Assisted-by: Claude:fable-5-2
This commit is contained in:
Sergei Poljanski 2026-11-16 22:59:59 +04:00
commit be68c5adef
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

60
nixos/migration/ops-data.sh Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env bash
# asxpio-ops: move the data of the Debian/Docker layout to where the
# NixOS services keep it, then let them start.
#
# ops-data.sh <old root>
#
# <old root> is /old-root after an in-place conversion (the dumps then
# come from the last thing done before it: `restic-backup run`, which
# leaves nothing behind, so take them by hand into
# <old root>/var/backups/restic-stage), or the target of a restic restore.
# Moves within one filesystem, so it is quick; run it once, as root, on a
# host whose services are still waiting for /var/lib/.data-in-place.
set -euo pipefail
src=${1:?usage: ops-data.sh <old root>}
stage=$src/var/backups/restic-stage
[ ! -e /var/lib/.data-in-place ] || { echo "services already have data (/var/lib/.data-in-place exists)" >&2; exit 1; }
for f in "$stage/pg_dumpall.sql" "$stage/forgejo-gitea.db" "$src/opt/forgejo/data/git/repositories"; do
[ -e "$f" ] || { echo "missing: $f" >&2; exit 1; }
done
echo "== Forgejo"
fj=/var/lib/forgejo
install -d -o git -g git -m 750 $fj $fj/data $fj/custom
mv "$src/opt/forgejo/data/git/repositories" $fj/repositories
mv "$src/opt/forgejo/data/git/lfs" $fj/data/lfs
for d in "$src"/opt/forgejo/data/gitea/data/*; do
case "$(basename "$d")" in
home | ssh | tmp | sessions | queues | indexers) ;; # rebuilt, or the container's own
*) mv "$d" $fj/data/ ;;
esac
done
[ ! -d "$src/opt/forgejo/data/gitea/public" ] || mv "$src/opt/forgejo/data/gitea/public" $fj/custom/public
# The online copy taken by the backup hook, not the live file
cp "$stage/forgejo-gitea.db" $fj/data/forgejo.db
chown -R git:git $fj
echo "== Garage"
install -d -m 700 /var/lib/garage
mv "$src/var/lib/docker/volumes/storage_garage_meta/_data" /var/lib/garage/meta
mv "$src/var/lib/docker/volumes/storage_garage_data/_data" /var/lib/garage/data
echo "== Starting"
touch /var/lib/.data-in-place
systemctl start postgresql.service
echo "== Postgres"
# The dump recreates the roles with their old passwords; postgres-roles
# then sets the ones from sops
runuser -u postgres -- psql -q postgres < "$stage/pg_dumpall.sql" > /var/log/pg-restore.log 2>&1 || true
echo "errors in /var/log/pg-restore.log: $(grep -c ERROR /var/log/pg-restore.log || true)"
systemctl restart postgres-roles.service
systemctl start garage.service garage-bootstrap.service forgejo.service
echo "== Forgejo: hooks and SSH keys for the new paths"
forgejo-admin regenerate hooks
forgejo-admin regenerate keys
echo "== Done. Check: systemctl --failed; garage status; a git clone over SSH and HTTPS"