From 2785267b1b1441148f6f3195e6b68a98962c606b Mon Sep 17 00:00:00 2001
From: Gaetan Lepage <gaetan@glepage.com>
Date: Wed, 3 Jan 2024 17:25:20 +0100
Subject: [PATCH] plugins/treesitter: add an option to control if gcc should be
 installed

---
 plugins/languages/treesitter/treesitter.nix | 25 ++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/plugins/languages/treesitter/treesitter.nix b/plugins/languages/treesitter/treesitter.nix
index 4c8a56e071..1f0fb2d89e 100644
--- a/plugins/languages/treesitter/treesitter.nix
+++ b/plugins/languages/treesitter/treesitter.nix
@@ -30,6 +30,20 @@ in {
         description = "Either \"all\" or a list of languages";
       };
 
+      gccPackage = mkOption {
+        type = with types; nullOr package;
+        default =
+          if cfg.nixGrammars
+          then null
+          else pkgs.gcc;
+        example = null;
+        description = ''
+          Which package (if any) to be added as the GCC compiler.
+          This is required to build grammars if you are not using `nixGrammars`.
+          To disable the installation of GCC, set this option to `null`.
+        '';
+      };
+
       parserInstallDir = mkOption {
         type = types.nullOr types.str;
         default =
@@ -199,11 +213,12 @@ in {
         if cfg.nixGrammars
         then [(cfg.package.withPlugins (_: cfg.grammarPackages))]
         else [cfg.package];
-      extraPackages = with pkgs; [
-        tree-sitter
-        nodejs
-        gcc
-      ];
+      extraPackages = with pkgs;
+        [
+          tree-sitter
+          nodejs
+        ]
+        ++ optional (cfg.gccPackage != null) cfg.gccPackage;
 
       options = mkIf cfg.folding {
         foldmethod = "expr";