ci: evaluate only, comin deploys
All checks were successful
nixos / nixos (push) Successful in 21s

comin on each host pulls main and switches, so the CI deploy job, its
SSH configuration and the known_hosts it used go. CI keeps evaluating
every host on every push and no longer holds a key to the servers;
SSH_DEPLOY_KEY can be removed from the repository secrets.

Assisted-by: Claude:opus-5-5
This commit is contained in:
Sergei Poljanski 2026-11-17 11:39:40 +04:00
commit 29dcc8915a
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

View file

@ -1,17 +1,10 @@
name: nixos
# 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.
# Deploying is not CI's job: each host pulls main itself (comin,
# nixos/modules/comin.nix). CI holds no credentials for the servers.
run-name: "${{ github.ref == 'refs/heads/main' && 'deploy' || 'evaluate' }}: ${{ github.ref_name }}"
run-name: "evaluate: ${{ github.ref_name }}"
on:
push:
@ -37,7 +30,7 @@ jobs:
# 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.
# on each server.
- name: Evaluate
working-directory: nixos
run: |
@ -45,54 +38,3 @@ jobs:
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"
# nixos-rebuild runs the activation as a fixed transient unit;
# while an earlier one still runs (it waits for one-shot units
# it started), a new switch fails with a misleading sudo error
for i in $(seq 1 120); do
nix develop -c ssh "$host" 'systemctl is-active -q nixos-rebuild-switch-to-configuration.service' || break
echo "$host: an earlier activation is still running, waiting"
sleep 10
done
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