name: "Update flake inputs"
on:
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * 5' # Every week on Friday.
jobs:
  update:
    runs-on: ubuntu-latest
    env:
      NIXPKGS_ALLOW_BROKEN: "1"
      NIXPKGS_ALLOW_UNFREE: "1"
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v3
      - uses: DeterminateSystems/nix-installer-action@v4
      - name: Update flake inputs
        run: |
          nix flake update --commit-lock-file --commit-lockfile-summary "flake.lock: update inputs"
        env:
          GIT_AUTHOR_NAME: github-actions[bot]
          GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
          GIT_COMMITTER_NAME: github-actions[bot]
          GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
      - name: Build custom packages
        run: nix build --dry-run --impure --file ./pkgs
      - name: Build NixOS configurations
        run: nix build --dry-run --impure .#images.{ni,plover,bootstrap}
      - name: Push changes to remote
        run: |
          git remote remove origin
          git remote add origin https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
          git push --set-upstream origin master