name: Nix

on:
  pull_request:
    types: [opened, synchronize, reopened]
    paths:
      - ".github/workflows/nix.yml"
      - "assets/**"
      - "build.rs"
      - "Cargo.lock"
      - "Cargo.toml"
      - "flake.lock"
      - "flake.nix"
      - "nix/**"
      - "skills/**"
      - "vendor/**"
  push:
    branches: [master]
    paths:
      - ".github/workflows/nix.yml"
      - "assets/**"
      - "build.rs"
      - "Cargo.lock"
      - "Cargo.toml"
      - "flake.lock"
      - "flake.nix"
      - "nix/**"
      - "skills/**"
      - "vendor/**"

permissions:
  contents: read

concurrency:
  group: nix-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  flake-check:
    name: flake check
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - name: Checkout
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
        with:
          persist-credentials: false

      - name: Install Nix
        uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6
        with:
          extra_nix_config: |
            experimental-features = nix-command flakes
            always-allow-substitutes = true

      - name: Run Nix flake check
        run: |
          nix flake check --print-build-logs
          nix flake check --all-systems --no-build --print-build-logs
