name: "Update cachix cache for development environment"

on:
  push:
    branches: [ master, main ]

permissions:
  contents: read

jobs:
  r-update-cachix:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4

      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@main
  
      - uses: cachix/cachix-action@v15
        with:
          name: CACHE_NAME
          # If you chose signing key for write access
          # signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
          # If you chose API tokens for write access OR if you have a private cache
          authToken: '${{ secrets.CACHIX_AUTH }}'
  
      - run: nix-build PATH_TO_DEFAULT_NIX
          
      - run: nix-store -qR --include-outputs $(nix-instantiate PATH_TO_DEFAULT_NIX) | cachix push CACHE_NAME
      - run: nix-shell --run "echo OK"
