From e9ad2f8ac8b396c3aaaa88f4b8000de7e9e1a080 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 7 Feb 2024 07:24:44 +0300 Subject: [PATCH 1/2] languages/nim: init --- configuration.nix | 1 + modules/languages/default.nix | 1 + modules/languages/nim.nix | 106 ++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 modules/languages/nim.nix diff --git a/configuration.nix b/configuration.nix index f12fc88..db9feff 100644 --- a/configuration.nix +++ b/configuration.nix @@ -75,6 +75,7 @@ inputs: let elixir.enable = false; bash.enable = isMaximal; terraform.enable = isMaximal; + nim.enable = isMaximal; }; vim.visuals = { diff --git a/modules/languages/default.nix b/modules/languages/default.nix index 41c204e..e6910f3 100644 --- a/modules/languages/default.nix +++ b/modules/languages/default.nix @@ -20,6 +20,7 @@ in { ./svelte.nix ./java.nix ./lua.nix + ./nim.nix ./php.nix ./terraform.nix ]; diff --git a/modules/languages/nim.nix b/modules/languages/nim.nix new file mode 100644 index 0000000..6cddce1 --- /dev/null +++ b/modules/languages/nim.nix @@ -0,0 +1,106 @@ +{ + pkgs, + config, + lib, + ... +}: let + inherit (builtins) attrNames; + inherit (lib) isList nvim mkEnableOption mkOption types mkIf mkMerge; + cfg = config.vim.languages.nim; + + defaultServer = "nimlsp"; + servers = { + nimlsp = { + package = pkgs.nimlsp; + lspConfig = '' + lspconfig.nimls.setup{ + capabilities = capabilities; + on_attach = default_on_attach; + cmd = ${ + if isList cfg.lsp.package + then nvim.lua.expToLua cfg.lsp.package + else '' + {"${cfg.lsp.package}/bin/nimlsp"} + '' + }; + } + ''; + }; + }; + + defaultFormat = "nimpretty"; + formats = { + nimpretty = { + package = pkgs.nim; + nullConfig = '' + table.insert( + ls_sources, + null_ls.builtins.formatting.nimpretty.with({ + command = "${pkgs.nim}/bin/nimpretty", + }) + ) + ''; + }; + }; +in { + options.vim.languages.nim = { + enable = mkEnableOption "Nim language support"; + + treesitter = { + enable = mkOption { + description = "Enable Nim treesitter"; + type = types.bool; + default = config.vim.languages.enableTreesitter; + }; + package = nvim.types.mkGrammarOption pkgs "nim"; + }; + + lsp = { + enable = mkEnableOption "Nim LSP support" // {default = config.vim.languages.enableLSP;}; + + server = mkOption { + description = "Nim LSP server to use"; + type = types.str; + default = defaultServer; + }; + package = mkOption { + description = "Nim LSP server package, or the command to run as a list of strings"; + example = ''[lib.getExe pkgs.nimlsp]''; + type = with types; either package (listOf str); + default = servers.${cfg.lsp.server}.package; + }; + }; + + format = { + enable = mkEnableOption "Nim formatting" // {default = config.vim.languages.enableFormat;}; + + type = mkOption { + description = "Nim formatter to use"; + type = with types; enum (attrNames formats); + default = defaultFormat; + }; + package = mkOption { + description = "Nim formatter package"; + type = types.package; + default = formats.${cfg.format.type}.package; + }; + }; + }; + + 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.nim-lsp = servers.${cfg.lsp.server}.lspConfig; + }) + + (mkIf cfg.format.enable { + vim.lsp.null-ls.enable = true; + vim.lsp.null-ls.sources.nim-format = formats.${cfg.format.type}.nullConfig; + }) + ]); +} From 6346617a50f796118690f6f7ea288414d2679ee2 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 10 Feb 2024 12:55:20 +0300 Subject: [PATCH 2/2] languages/nim: assert on darwin systems due to nimlsp not working properly on darwin --- configuration.nix | 2 +- modules/languages/nim.nix | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configuration.nix b/configuration.nix index 41526de..1875eaa 100644 --- a/configuration.nix +++ b/configuration.nix @@ -68,7 +68,7 @@ inputs: let elixir.enable = isMaximal; bash.enable = isMaximal; terraform.enable = isMaximal; - nim.enable = isMaximal; + nim.enable = false; tailwind.enable = isMaximal; clang = { enable = isMaximal; diff --git a/modules/languages/nim.nix b/modules/languages/nim.nix index 6cddce1..7297ada 100644 --- a/modules/languages/nim.nix +++ b/modules/languages/nim.nix @@ -88,6 +88,15 @@ in { }; config = mkIf cfg.enable (mkMerge [ + { + assertions = [ + { + assertion = !pkgs.stdenv.isDarwin; + message = "Nim language support is only available on Linux"; + } + ]; + } + (mkIf cfg.treesitter.enable { vim.treesitter.enable = true; vim.treesitter.grammars = [cfg.treesitter.package];