nix-config/.gitea/workflows/nix-rebuild-server1.yml
smayzy 8676253432
All checks were successful
nix flake show / show-flake (push) Successful in 29s
remove space to try to triger the workflow
2025-08-09 17:10:19 +02:00

40 lines
1.2 KiB
YAML

name: rebuild server1
run-name: ${{ gitea.actor }} triggered server1 rebuild
on:
workflow_run:
workflows: ["nix flake show"]
types:
- completed
jobs:
deploy:
if: ${{ gitea.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: ssh to server1 and rebuild
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER1_HOST }}
username: root
key: ${{ secrets.SERVER1_KEY }}
script: |
set -e
echo "Pulling repo ..."
cd /home/smayzy/nix-config
git pull
echo "Rebuilding system ..."
old_gen="$(readlink /run/current-system)"
if nixos-rebuild switch --flake .#server1 --show-trace; then
echo "Deployment successful"
else
if [ "$(readlink /run/current-system)" != "$old_gen" ]; then
echo "Build failed after activation — rolling back..."
nixos-rebuild switch --rollback
else
echo "Build failed before activation — staying on current config"
fi
exit 1
fi