# See shb.skarabox.com/misc.html
name: Update Flake Lock

on:
  schedule:
    - cron: '0 */3 * * *' # runs every 3 hours at :00

  workflow_dispatch:
    inputs:
      bisect_future:
        description: "Bisect in the future instead of the past"
        required: false
        default: "false"

jobs:
  lockfile:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
      - name: Install Nix
        uses: cachix/install-nix-action@v31
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Cache nixpkgs mirror
        uses: actions/cache@v5
        with:
          path: .cache/nixpkgs.git
          key: nixpkgs-mirror-v1
      - name: Update flake.lock
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
          BISECT_FUTURE: ${{ inputs.bisect_future }}
        run: |
          git config user.email "update-flake-lock-pr@selfhostblocks.com"
          git config user.name "Update Flake Lock PR"
          if [ "$BISECT_FUTURE" = false ]; then
            BISECT_FUTURE=
          elif [ -n "$BISECT_FUTURE" ]; then
            BISECT_FUTURE=future
          fi
          nix run .#update-flake-lock-pr $BISECT_FUTURE

