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
1 changed files with 434 additions and 210 deletions
|
|
@ -1,8 +1,17 @@
|
|||
name: nixos
|
||||
|
||||
# Every push: evaluate each host, so a broken config never reaches main.
|
||||
# Deploying from here is added when the first host runs NixOS
|
||||
# (MIGRATION.md, step 4); until then hosts are switched by hand.
|
||||
# Every push: evaluate every host, so a broken config never reaches main.
|
||||
# main: build and switch each production host that already runs NixOS.
|
||||
# A host still on Debian is skipped (it is checked for /etc/NIXOS first),
|
||||
# so this job cannot touch a server before its conversion.
|
||||
#
|
||||
# Secret: SSH_DEPLOY_KEY (user deploy). Service secrets are decrypted on
|
||||
# the hosts by sops-nix; CI holds none of them.
|
||||
#
|
||||
# Switching asxpio-services can restart the runner that runs this job:
|
||||
# the change lands, the job shows as cancelled, the next run confirms.
|
||||
|
||||
run-name: "${{ github.ref == 'refs/heads/main' && 'deploy' || 'evaluate' }}: ${{ github.ref_name }}"
|
||||
|
||||
on:
|
||||
push:
|
||||
|
|
@ -12,7 +21,7 @@ on:
|
|||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
evaluate:
|
||||
nixos:
|
||||
runs-on: nix-latest
|
||||
env:
|
||||
NIX_CONFIG: |
|
||||
|
|
@ -26,10 +35,56 @@ jobs:
|
|||
- name: Checkout
|
||||
uses: actions/checkout@v7.0.1
|
||||
|
||||
# Job containers are unprivileged, so Nix cannot sandbox builds in
|
||||
# them. Evaluating catches config errors; the build itself happens
|
||||
# on each server during the deploy.
|
||||
- name: Evaluate
|
||||
working-directory: nixos
|
||||
run: |
|
||||
for host in asxpio-ops asxpio-services rehearsal; do
|
||||
for host in asxpio-ops asxpio-services rehearsal-ops rehearsal-services; do
|
||||
nix eval --raw ".#nixosConfigurations.$host.config.system.build.toplevel.drvPath"
|
||||
echo
|
||||
done
|
||||
|
||||
- name: Set up SSH
|
||||
if: github.ref == 'refs/heads/main'
|
||||
env:
|
||||
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
|
||||
run: |
|
||||
umask 077
|
||||
mkdir -p ~/.ssh
|
||||
printf '%s\n' "$SSH_DEPLOY_KEY" > ~/.ssh/id_ed25519
|
||||
cp known_hosts ~/.ssh/known_hosts
|
||||
# The runner's own host is reached through asxpio-ops: a job
|
||||
# container connecting to its host arrives from a bridge address
|
||||
# that sshd refuses.
|
||||
cat > ~/.ssh/config <<'EOF'
|
||||
Host asxpio-ops
|
||||
HostName 10.10.0.10
|
||||
User deploy
|
||||
Host asxpio-services
|
||||
HostName 10.10.0.20
|
||||
User deploy
|
||||
ProxyJump asxpio-ops
|
||||
EOF
|
||||
|
||||
- name: Deploy
|
||||
if: github.ref == 'refs/heads/main'
|
||||
working-directory: nixos
|
||||
# Ops first: services reaches it for WireGuard, logs and Forgejo
|
||||
run: |
|
||||
# Tools from the flake's dev shell: the same pinned nixpkgs
|
||||
for host in asxpio-ops asxpio-services; do
|
||||
os=$(nix develop -c ssh "$host" 'test -e /etc/NIXOS && echo nixos || echo other')
|
||||
if [ "$os" != nixos ]; then
|
||||
echo "$host: not NixOS yet, skipped"
|
||||
continue
|
||||
fi
|
||||
echo "== $host"
|
||||
nix develop -c nixos-rebuild switch --flake ".#$host" \
|
||||
--target-host "$host" --build-host "$host" --sudo
|
||||
done
|
||||
|
||||
- name: Remove credentials
|
||||
if: always()
|
||||
run: rm -f ~/.ssh/id_ed25519
|
||||
|
|
|
|||
Loading…
Reference in a new issue