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. run-name: "${{ github.ref == 'refs/heads/main' && 'deploy' || 'evaluate' }}: ${{ github.ref_name }}" on: push: paths: - 'nixos/**' - '.forgejo/workflows/nixos.yaml' workflow_dispatch: jobs: nixos: runs-on: nix-latest env: NIX_CONFIG: | experimental-features = nix-command flakes build-users-group = sandbox = false steps: - name: Prepare container for actions run: nix-env -iA nixpkgs.nodejs_22 - 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-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