From f1406a30bb33908e2572b931abebb8bb71452bd3 Mon Sep 17 00:00:00 2001 From: Kalle Jepsen Date: Tue, 28 Nov 2023 11:12:34 +0100 Subject: [PATCH] languages: add terraform language support --- configuration.nix | 1 + modules/languages/default.nix | 1 + modules/languages/terraform.nix | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 modules/languages/terraform.nix diff --git a/configuration.nix b/configuration.nix index f45cb0a..f12fc88 100644 --- a/configuration.nix +++ b/configuration.nix @@ -74,6 +74,7 @@ inputs: let dart.enable = isMaximal; elixir.enable = false; bash.enable = isMaximal; + terraform.enable = isMaximal; }; vim.visuals = { diff --git a/modules/languages/default.nix b/modules/languages/default.nix index be87361..41c204e 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -21,6 +21,7 @@ in { ./java.nix ./lua.nix ./php.nix + ./terraform.nix ]; options.vim.languages = { diff --git a/modules/languages/terraform.nix b/modules/languages/terraform.nix new file mode 100644 index 0000000..db2e525 --- /dev/null +++ b/modules/languages/terraform.nix @@ -0,0 +1,46 @@ +{ + pkgs, + config, + lib, + ... +}: let + inherit (lib) nvim mkEnableOption mkOption types mkIf mkMerge; + + cfg = config.vim.languages.terraform; +in { + options.vim.languages.terraform = { + enable = mkEnableOption "Terraform/HCL support"; + + treesitter = { + enable = mkEnableOption "Terraform treesitter" // {default = config.vim.languages.enableTreesitter;}; + package = nvim.types.mkGrammarOption pkgs "terraform"; + }; + + lsp = { + enable = mkEnableOption "Terraform LSP support (terraform-ls)" // {default = config.vim.languages.enableLSP;}; + + package = mkOption { + description = "terraform-ls package"; + type = with types; package; + default = pkgs.terraform-ls; + }; + }; + }; + config = mkIf cfg.enable (mkMerge [ + (mkIf cfg.treesitter.enable { + vim.treesitter.enable = true; + vim.treesitter.grammars = [cfg.treesitter.package]; + }) + + (mkIf cfg.lsp.enable { + vim.lsp.lspconfig.enable = true; + vim.lsp.lspconfig.sources.terraform-ls = '' + lspconfig.terraformls.setup { + capabilities = capabilities, + on_attach=default_on_attach, + cmd = {"${cfg.lsp.package}/bin/terraform-ls", "serve"}, + } + ''; + }) + ]); +}