diff options
-rw-r--r-- | common/vim.nix | 18 | ||||
-rw-r--r-- | usecases/desktop/development.nix | 39 |
2 files changed, 32 insertions, 25 deletions
diff --git a/common/vim.nix b/common/vim.nix index 850eaf3..83ac31b 100644 --- a/common/vim.nix +++ b/common/vim.nix | |||
@@ -5,6 +5,8 @@ inputs: | |||
5 | let | 5 | let |
6 | inherit (pkgs.unstable) vimPlugins wrapNeovim; | 6 | inherit (pkgs.unstable) vimPlugins wrapNeovim; |
7 | 7 | ||
8 | luaFormat = inputs.self.lib.generators.lua { }; | ||
9 | |||
8 | neovim-unwrapped = inputs.neovim-master.defaultPackage.${config.nixpkgs.system}; | 10 | neovim-unwrapped = inputs.neovim-master.defaultPackage.${config.nixpkgs.system}; |
9 | 11 | ||
10 | cfg = config.vim; | 12 | cfg = config.vim; |
@@ -18,7 +20,7 @@ let | |||
18 | ${(concatStringsSep | 20 | ${(concatStringsSep |
19 | "\n" | 21 | "\n" |
20 | (mapAttrsToList | 22 | (mapAttrsToList |
21 | (variable: value: "vim.g.${variable} = ${value}") | 23 | (variable: value: "vim.g.${variable} = ${luaFormat.generate value}") |
22 | cfg.variables))} | 24 | cfg.variables))} |
23 | 25 | ||
24 | -- vim.lua from the NixOS configuration | 26 | -- vim.lua from the NixOS configuration |
@@ -104,13 +106,9 @@ in | |||
104 | options.vim = with lib; { | 106 | options.vim = with lib; { |
105 | 107 | ||
106 | variables = mkOption { | 108 | variables = mkOption { |
107 | type = types.attrsOf types.str; | 109 | type = types.attrsOf luaFormat.type; |
108 | default = {}; | 110 | default = {}; |
109 | description = '' | 111 | description = "Extra global variables to add at the beginning of the vim configuration."; |
110 | Extra global variables to add at the beginning of the vim configuration. | ||
111 | |||
112 | Remember to escape strings with single-quotes. | ||
113 | ''; | ||
114 | }; | 112 | }; |
115 | 113 | ||
116 | extraPlugins = mkOption { | 114 | extraPlugins = mkOption { |
@@ -148,9 +146,9 @@ in | |||
148 | vim = { | 146 | vim = { |
149 | wrappedPackage = myNeovim; | 147 | wrappedPackage = myNeovim; |
150 | variables = { | 148 | variables = { |
151 | dominant_color = "'${config.theme.colors.dominant}'"; | 149 | dominant_color = "${config.theme.colors.dominant}"; |
152 | ripgrep_path = "'${pkgs.ripgrep}/bin/rg'"; | 150 | ripgrep_path = "${pkgs.ripgrep}/bin/rg"; |
153 | fd_path = "'${pkgs.fd}/bin/fd'"; | 151 | fd_path = "${pkgs.fd}/bin/fd"; |
154 | }; | 152 | }; |
155 | }; | 153 | }; |
156 | 154 | ||
diff --git a/usecases/desktop/development.nix b/usecases/desktop/development.nix index 5d9697f..fad2596 100644 --- a/usecases/desktop/development.nix +++ b/usecases/desktop/development.nix | |||
@@ -13,15 +13,30 @@ let | |||
13 | 13 | ||
14 | inherit (pkgs.unstable.python3Packages) python-language-server; | 14 | inherit (pkgs.unstable.python3Packages) python-language-server; |
15 | 15 | ||
16 | luaFormat = inputs.self.lib.generators.lua { }; | ||
17 | |||
16 | in | 18 | in |
17 | { | 19 | { |
18 | options = with lib; { | 20 | options = with lib; with luaFormat.lib; { |
19 | vim.lsp = mkOption { | 21 | vim.lsp = mkOption { |
20 | description = '' | 22 | description = '' |
21 | Configure Neovim to use these LSP servers; | 23 | Configure Neovim to use these LSP servers; |
22 | ''; | 24 | ''; |
23 | # TODO: change that to submodule with cmd, settings, capabilities, etc. | 25 | type = with types; attrsOf (submodule { |
24 | type = with types; attrsOf (listOf str); | 26 | freeformType = luaFormat.type; |
27 | |||
28 | options = { | ||
29 | capabilities = mkOption { | ||
30 | default = mkRaw "capabilities"; | ||
31 | }; | ||
32 | cmd = mkOption { | ||
33 | type = with types; listOf str; | ||
34 | }; | ||
35 | on_attach = mkOption { | ||
36 | default = mkRaw "on_attach"; | ||
37 | }; | ||
38 | }; | ||
39 | }); | ||
25 | default = { }; | 40 | default = { }; |
26 | }; | 41 | }; |
27 | }; | 42 | }; |
@@ -46,24 +61,18 @@ in | |||
46 | ]; | 61 | ]; |
47 | 62 | ||
48 | variables = { | 63 | variables = { |
49 | rust_analyzer_path = "'${rust-analyzer-unwrapped}/bin/rust-analyzer'"; | 64 | rust_analyzer_path = "${rust-analyzer-unwrapped}/bin/rust-analyzer"; |
50 | }; | 65 | }; |
51 | 66 | ||
52 | lsp = { | 67 | lsp = { |
53 | clangd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; | 68 | clangd.cmd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; |
54 | elixirls = [ "${elixir_ls}/bin/elixir-ls" ]; | 69 | elixirls.cmd = [ "${elixir_ls}/bin/elixir-ls" ]; |
55 | pyls = [ "${python-language-server}/bin/pyls" ]; | 70 | pyls.cmd = [ "${python-language-server}/bin/pyls" ]; |
56 | }; | 71 | }; |
57 | 72 | ||
58 | luaConfig = with lib; let | 73 | luaConfig = with lib; let |
59 | toLua = list: "{ ${concatMapStringsSep ", " (elem: "'${escape [ "'" ] elem}'") list} }"; | 74 | toLua = luaFormat.generate; |
60 | lspconfigFor = name: cmd: '' | 75 | lspconfigFor = name: settings: "lspconfig['${name}'].setup ${toLua settings}"; |
61 | lspconfig["${name}"].setup { | ||
62 | capabilities = capabilities, | ||
63 | cmd = ${toLua cmd}, | ||
64 | on_attach = on_attach, | ||
65 | } | ||
66 | ''; | ||
67 | lspconfig = concatStringsSep | 76 | lspconfig = concatStringsSep |
68 | "\n" | 77 | "\n" |
69 | (mapAttrsToList lspconfigFor config.vim.lsp); | 78 | (mapAttrsToList lspconfigFor config.vim.lsp); |