name: Build
on:
  push:
    branches: ['master']
    paths:
      - 'flake.lock'
      - 'home/programs/nvim/plugins.nix'
      - '.forgejo/workflows/build.yml'
  schedule:
    - cron: '20 4 * * *'
jobs:
  build-amd64-linux:
    runs-on: nix-amd64
    steps:
      - uses: actions/checkout@v4
        with:
          ref: master
      - name: Cache Login
        run: |
          echo "Logging in ..."
          attic login --set-default attic ${{ secrets.ATTIC_ENDPOINT }} ${{ secrets.ATTIC_TOKEN }}
      - name: Build attic-server
        run: |
          nix build '.#nixosConfigurations.tanker.pkgs.attic-server'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build attic-client
        run: |
          nix build '.#nixosConfigurations.tanker.pkgs.attic-client'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build deploy-rs
        run: |
          nix build '.#deploy-rs'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build nginx
        run: |
          nix build '.#nixosConfigurations.tanker.config.services.nginx.package'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build neovim
        run: |
          nix build '.#nixosConfigurations.tanker.config.home-manager.users.daniel.programs.neovim.finalPackage'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
  build-arm64-linux:
    runs-on: nix-arm64
    steps:
      - uses: actions/checkout@v4
        with:
          ref: master
      - name: Cache Login
        run: |
          echo "Logging in ..."
          attic login --set-default attic ${{ secrets.ATTIC_ENDPOINT }} ${{ secrets.ATTIC_TOKEN }}
      - name: Build attic-client
        run: |
          nix build '.#nixosConfigurations.argon.pkgs.attic-client'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build deploy-rs
        run: |
          nix build '.#deploy-rs'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build nginx
        run: |
          nix build '.#nixosConfigurations.argon.config.services.nginx.package'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
      - name: Build neovim
        run: |
          nix build '.#nixosConfigurations.argon.config.home-manager.users.daniel.programs.neovim.finalPackage'
          attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')