# https://github.com/thiagokokada/nix-configs
name: build-nixos-configuration-and-populate
on:
  workflow_dispatch: # Do not run unless i run it manually

jobs:
  build-nixosConfiguration:
    runs-on: ubuntu-latest
    steps:
      - uses: easimon/maximize-build-space@v10
        with:
          overprovision-lvm: true
          remove-android: true
          remove-codeql: true
          remove-docker-images: true
          remove-dotnet: true
          remove-haskell: true
          root-reserve-mb: 512
          swap-size-mb: 1024

      - uses: actions/checkout@v4

      - name: Install Nix
        uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable-small
          extra_nix_config: |
            substituters = https://cache.garnix.io https://nyx.chaotic.cx https://cache.nixos.org/ https://nixpkgs-unfree.cachix.org https://numtide.cachix.org https://dotfiles-pkgs.cachix.org
            trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g= nyx.chaotic.cx-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8= chaotic-nyx.cachix.org-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8= nixpkgs-unfree.cachix.org-1:hqvoInulhbV4nJ9yJOEr+4wxhDV4xq2d1DK7S6Nj6rs= numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE= dotfiles-pkgs.cachix.org-1:0TnsAyYE0P2BXv9s7gqqCpkf2SNt4cXKPh/66enbwnk=

      - uses: DeterminateSystems/magic-nix-cache-action@main

      - uses: cachix/cachix-action@v15
        with:
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
          name: sforza-config

      - name: Set default git branch (to reduce log spam)
        run: git config --global init.defaultBranch flake-parts

      - name: "Build nixosConfiguration for: sforza"
        run: |-
          nix build --print-build-logs '.#nixosConfigurations.sforza.config.system.build.toplevel'
