name: "Automated flake inputs update"
on:
  schedule:
    # Every week on Friday.
    - cron: '0 0 * * 5'
env:
  NIXPKGS_ALLOW_INSECURE: "1"
  NIXPKGS_ALLOW_BROKEN: "1"
  NIXPKGS_ALLOW_UNFREE: "1"

  # GitHub bot
  GIT_AUTHOR_NAME: "github-actions[bot]"
  GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: cachix/install-nix-action@v16
        with:
          # TODO: This is a terrible idea, pls switch to stable channel at some point.
          nix_path: nixpkgs=channel:nixos-unstable
          extra_nix_config: |
            keep-going = true
      - name: Update flake inputs
        run: |
          nix flake update --commit-lock-file \
            --commit-lockfile-summary 'flake.lock: update inputs'
      - name: Build custom packages
        run: nix build --impure --file ./pkgs
      - name: Build NixOS configurations
        run: nix build --impure .#nixosConfigurations.ni.config.system.build.toplevel
      - name: Push updates to remote
        run: |
          git remote remove origin
          git remote add origin https://${{ secrets.GITHUB_TOKEN }}@github.com/foo-dogsquared/nixos-config.git
          git push --set-upstream origin master --tags