name: Nix Build

on: 
  pull_request:
  push:
    paths-ignore:
     - "README.md"
     - ".gitignore"
     - "Makefile"
     - ".gitattributes"
  workflow_run:
    workflows: [update-flake]
    types: [completed]
  workflow_dispatch:

jobs:
  build-nixos:
    runs-on: ubuntu-latest
    steps: 
      - name: "Maximize Disk Space"
        uses: easimon/maximize-build-space@v8
        with:
          root-reserve-mb: 8192
          swap-size-mb: 1024
          build-mount-path: /nix
          remove-dotnet: "true"
          remove-android: "true"
          remove-haskell: "true"
          remove-codeql: "true"
          remove-docker-images: "true"
      
      - uses: actions/checkout@v4
      
      - name: "Install Nix ❄️"
        uses: cachix/install-nix-action@v26
        with:
          nix_path: nixpkgs=channel:nixos-unstable

      - name: "Install Cachix ❄️"
        uses: cachix/cachix-action@v14
        with:
          name: zackartz
          authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
         
        
      - name: "Build NixOS config ❄️"
        env:
          CACHIX_SIGNING_KEY: "${{ secrets.CACHIX_SIGNING_KEY }}"
        run: |
          nix build .\#nixosConfigurations."earth".config.system.build.toplevel 
