treesitter: ensure_installed to none if using nix

This is a temporary workaround for an upstream bug which causes
nvim-treesitter to complain about a read-only installation directory
This commit is contained in:
Pedro Alves 2022-09-12 13:04:24 +01:00
parent 88fb867da5
commit bd6f978d51

View file

@ -15,35 +15,37 @@ in
description = "Install grammars with Nix (beta)"; description = "Install grammars with Nix (beta)";
}; };
ensureInstalled = mkOption { ensureInstalled = mkOption {
type = with types; oneOf [ (enum ["all"]) (listOf str) ]; type = with types; oneOf [ (enum [ "all" ]) (listOf str) ];
default = "all"; default = "all";
description = "Either \"all\" or a list of languages"; description = "Either \"all\" or a list of languages";
}; };
ignoreInstall = mkOption { ignoreInstall = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [ ];
description = "List of parsers to ignore installing (for \"all\")"; description = "List of parsers to ignore installing (for \"all\")";
}; };
disabledLanguages = mkOption { disabledLanguages = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [ ];
description = "A list of languages to disable"; description = "A list of languages to disable";
}; };
customCaptures = mkOption { customCaptures = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Custom capture group highlighting"; description = "Custom capture group highlighting";
}; };
incrementalSelection = let incrementalSelection =
let
keymap = default: mkOption { keymap = default: mkOption {
type = types.str; type = types.str;
inherit default; inherit default;
}; };
in { in
{
enable = mkEnableOption "Incremental selection based on the named nodes from the grammar"; enable = mkEnableOption "Incremental selection based on the named nodes from the grammar";
keymaps = { keymaps = {
initSelection = keymap "gnn"; initSelection = keymap "gnn";
@ -59,16 +61,18 @@ in
}; };
}; };
config = let config =
let
tsOptions = { tsOptions = {
highlight = { highlight = {
enable = cfg.enable; enable = cfg.enable;
disable = if (cfg.disabledLanguages != []) then cfg.disabledLanguages else null; disable = if (cfg.disabledLanguages != [ ]) then cfg.disabledLanguages else null;
custom_captures = if (cfg.customCaptures != {}) then cfg.customCaptures else null; custom_captures = if (cfg.customCaptures != { }) then cfg.customCaptures else null;
}; };
incremental_selection = if cfg.incrementalSelection.enable then { incremental_selection =
if cfg.incrementalSelection.enable then {
enable = true; enable = true;
keymaps = { keymaps = {
init_selection = cfg.incrementalSelection.keymaps.initSelection; init_selection = cfg.incrementalSelection.keymaps.initSelection;
@ -78,21 +82,23 @@ in
}; };
} else null; } else null;
indent = if cfg.indent then { indent =
if cfg.indent then {
enable = true; enable = true;
} else null; } else null;
ensure_installed = cfg.ensureInstalled; ensure_installed = if cfg.nixGrammars then [ ] else cfg.ensureInstalled;
ignore_install = cfg.ignoreInstall; ignore_install = cfg.ignoreInstall;
}; };
in mkIf cfg.enable { in
mkIf cfg.enable {
programs.nixvim = { programs.nixvim = {
extraConfigLua = '' extraConfigLua = ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions}) require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
''; '';
extraPlugins = with pkgs; if cfg.nixGrammars then extraPlugins = with pkgs; if cfg.nixGrammars then
[ (vimPlugins.nvim-treesitter.withPlugins(_: tree-sitter.allGrammars)) ] [ (vimPlugins.nvim-treesitter.withPlugins (_: tree-sitter.allGrammars)) ]
else [ vimPlugins.nvim-treesitter ]; else [ vimPlugins.nvim-treesitter ];
extraPackages = [ pkgs.tree-sitter pkgs.nodejs ]; extraPackages = [ pkgs.tree-sitter pkgs.nodejs ];