name: Nix on Mac
permissions:
  contents: write
on:
  push:
    branches:
      - "main"
      - "v*"
    tags:
      - "v*"
  workflow_call:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  aarch64-darwin---default:
    name: Build aarch64-darwin.default
    runs-on:
      - warp-macos-13-arm64-6x
    needs:
      - aarch64-darwin---rosenpass
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build
        run: nix build .#packages.aarch64-darwin.default --print-build-logs
  aarch64-darwin---release-package:
    name: Build aarch64-darwin.release-package
    runs-on:
      - warp-macos-13-arm64-6x
    needs:
      - aarch64-darwin---rosenpass
      - aarch64-darwin---rp
      - aarch64-darwin---rosenpass-oci-image
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build
        run: nix build .#packages.aarch64-darwin.release-package --print-build-logs
  aarch64-darwin---rosenpass:
    name: Build aarch64-darwin.rosenpass
    runs-on:
      - warp-macos-13-arm64-6x
    needs: []
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build
        run: nix build .#packages.aarch64-darwin.rosenpass --print-build-logs
  aarch64-darwin---rp:
    name: Build aarch64-darwin.rp
    runs-on:
      - warp-macos-13-arm64-6x
    needs: []
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build
        run: nix build .#packages.aarch64-darwin.rp --print-build-logs
  aarch64-darwin---rosenpass-oci-image:
    name: Build aarch64-darwin.rosenpass-oci-image
    runs-on:
      - warp-macos-13-arm64-6x
    needs:
      - aarch64-darwin---rosenpass
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build
        run: nix build .#packages.aarch64-darwin.rosenpass-oci-image --print-build-logs
  aarch64-darwin---check:
    name: Run Nix checks on aarch64-darwin
    runs-on:
      - warp-macos-13-arm64-6x
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v17
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Check
        run: nix flake check . --print-build-logs
