Changing CMake compiler depending on the platform

Hello, I’m trying to contribute a language server(luau-lsp) into nixpkgs.
Right now the darwin builds are failing and I want to try changing the compiler version to see if it changes anything but I can’t figure how to do this.

Here is the package.nix file

{ fetchFromGitHub
, stdenv
, lib
, cmake
, gcc9
}:
stdenv.mkDerivation rec {
  pname = "luau-lsp";
  version = "1.28.1";

  src = fetchFromGitHub {
    owner = "JohnnyMorganz";
    repo = "luau-lsp";
    rev = version;
    hash = "sha256-5+m5tLX0DRHrV6yI/SXc39orpAu1DlBmpNQ/rt7LUjQ=";
    fetchSubmodules = true;
  };

  # Build fails if this is false
  dontUseCmakeConfigure = true;

  nativeBuildInputs = [ cmake gcc9 ];

  buildPhase = ''
    mkdir build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    cmake --build . --target Luau.LanguageServer.CLI --config Release
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp ./luau-lsp $out/bin/luau-lsp
  '';

  meta = {
    description = "Language Server for Luau";
    homepage = "https://github.com/JohnnyMorganz/luau-lsp";
    downloadPage = "https://github.com/JohnnyMorganz/luau-lsp/releases/tag/${version}";
    license = lib.licenses.mit;
    platforms = lib.platforms.all;
    badPlatforms = lib.platforms.darwin;
    maintainers = with lib.maintainers; [ eggflaw ];
    mainProgram = "luau-lsp";
  };
}

How can I use a specific compiler depending on the platform?
I want GCC 9 for Linux and Clang ( or AppleClang ) 14 for Mac.

My pull request

I got it to work with this setup:

nativeBuildInputs = [ cmake ]
    ++ lib.optional stdenv.isLinux gcc9
    ++ lib.optional stdenv.isDarwin clang_14;