From 8027f6d8fed5bfeb51049e147b99fbaaafeefddf Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Fri, 27 Oct 2023 06:06:33 +0000 Subject: [PATCH] Add package for nixvim configuration --- flake.lock | 6 +- flake.nix | 6 +- sets/nvim.nix | 313 +++++++++++++++++++++---------------------- sets/workstation.nix | 7 +- 4 files changed, 165 insertions(+), 167 deletions(-) diff --git a/flake.lock b/flake.lock index 55a70ce..f8a0d42 100644 --- a/flake.lock +++ b/flake.lock @@ -338,11 +338,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1698328085, - "narHash": "sha256-32Vk8PCa57B4mIXdVTbDrKoHBO5FTm5ZaSwiph9PwIo=", + "lastModified": 1698386104, + "narHash": "sha256-/QwUn8G1ERjl82RFFTTI/2ulOTV9Mbeog97old9tZl0=", "owner": "nix-community", "repo": "nixvim", - "rev": "e1138cda396c7b925989cf6158496787051cf3f7", + "rev": "315bc508ee0bfb62b6608f8f445126158ca2cc35", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 7cdd87f..7386133 100644 --- a/flake.nix +++ b/flake.nix @@ -78,7 +78,11 @@ }; in { formatter = pkgs.nixfmt; - packages = { jlink = pkgs.callPackage ./externals/packages/jlink { }; }; + packages = { + jlink = pkgs.callPackage ./externals/packages/jlink { }; + nvim = inputs.nixvim.legacyPackages."${system}".makeNixvim + (import ./sets/nvim.nix { inherit pkgs inputs; }); + }; }); } diff --git a/sets/nvim.nix b/sets/nvim.nix index 25a36b4..694a22f 100644 --- a/sets/nvim.nix +++ b/sets/nvim.nix @@ -1,180 +1,171 @@ -{ pkgs, inputs, ... }: +{ pkgs, ... }: { - imports = [ inputs.nixvim.nixosModules.nixvim ]; + vimAlias = true; - environment.sessionVariables = { - EDITOR = "nvim"; - VISUAL = "nvim"; - }; - programs.nixvim = { - enable = true; - vimAlias = true; - - # Basic editing / QoL - editorconfig.enable = true; - colorschemes.kanagawa.enable = true; - plugins = { - nix.enable = true; - fugitive.enable = true; - gitgutter.enable = true; - lualine.enable = true; - typst-vim.enable = true; - telescope = { - enable = true; - keymaps = { - "tgf" = "git_files"; - "tb" = "buffers"; - "tl" = "live_grep"; - "ts" = "grep_string"; - "tf" = "find_files"; - "tt" = "builtin"; - - gd = "lsp_definitions"; - gt = "lsp_type_definitions"; - gr = "lsp_references"; - gi = "lsp_implementations"; - gcd = "diagnostics"; - gsd = "lsp_document_symbols"; - gsw = "lsp_workspace_symbols"; - gci = "lsp_incoming_calls"; - gco = "lsp_outgoing_calls"; - - "tgs" = "git_status"; - "tgb" = "git_branches"; - "tgc" = "git_commits"; - }; - }; - }; - extraPlugins = with pkgs.vimPlugins; [ - vim-fetch - vim-fish - vim-flatbuffers - vim-nftables - vim-protobuf - vim-toml - ]; - options = { - hidden = true; - backup = false; - writebackup = false; - cmdheight = 2; - shortmess = "filnxtToOFc"; - signcolumn = "yes"; - number = true; - }; - - # LSP - plugins.rust-tools = { + # Basic editing / QoL + editorconfig.enable = true; + colorschemes.kanagawa.enable = true; + plugins = { + nix.enable = true; + fugitive.enable = true; + gitgutter.enable = true; + lualine.enable = true; + typst-vim.enable = true; + telescope = { enable = true; - server.standalone = false; - }; - plugins.clangd-extensions.enable = true; - plugins.lsp = { - enable = true; - servers = { - clangd.enable = true; - java-language-server.enable = true; - jsonls.enable = true; - nil_ls.enable = true; - pylsp.enable = true; - texlab.enable = true; - tsserver.enable = true; - typst-lsp.enable = true; - }; - keymaps = { - silent = true; - diagnostic = { - "rk" = "goto_prev"; - "rj" = "goto_next"; - }; - lspBuf = { - K = "hover"; - gD = "declaration"; + "tgf" = "git_files"; + "tb" = "buffers"; + "tl" = "live_grep"; + "ts" = "grep_string"; + "tf" = "find_files"; + "tt" = "builtin"; - "ra" = "code_action"; - "rn" = "rename"; - "rs" = "signature_help"; - "f" = "format"; - }; + gd = "lsp_definitions"; + gt = "lsp_type_definitions"; + gr = "lsp_references"; + gi = "lsp_implementations"; + gcd = "diagnostics"; + gsd = "lsp_document_symbols"; + gsw = "lsp_workspace_symbols"; + gci = "lsp_incoming_calls"; + gco = "lsp_outgoing_calls"; + + "tgs" = "git_status"; + "tgb" = "git_branches"; + "tgc" = "git_commits"; }; + }; + }; + extraPlugins = with pkgs.vimPlugins; [ + vim-fetch + vim-fish + vim-flatbuffers + vim-nftables + vim-protobuf + vim-toml + ]; + options = { + hidden = true; + backup = false; + writebackup = false; + cmdheight = 2; + shortmess = "filnxtToOFc"; + signcolumn = "yes"; + number = true; + }; - onAttach = '' - if client.server_capabilities.documentHighlightProvider then - vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) - vim.api.nvim_clear_autocmds { buffer = bufnr, group = "lsp_document_highlight" } - vim.api.nvim_create_autocmd("CursorHold", { - callback = vim.lsp.buf.document_highlight, - buffer = bufnr, - group = "lsp_document_highlight", - desc = "Document Highlight", - }) - vim.api.nvim_create_autocmd("CursorMoved", { - callback = vim.lsp.buf.clear_references, - buffer = bufnr, - group = "lsp_document_highlight", - desc = "Clear All the References", - }) - end - ''; + # LSP + plugins.rust-tools = { + enable = true; + server.standalone = false; + }; + plugins.clangd-extensions.enable = true; + plugins.lsp = { + enable = true; + servers = { + clangd.enable = true; + java-language-server.enable = true; + jsonls.enable = true; + nil_ls.enable = true; + pylsp.enable = true; + texlab.enable = true; + tsserver.enable = true; + typst-lsp.enable = true; }; - # Autocomplete - plugins = { - luasnip.enable = true; - cmp-cmdline.enable = true; - cmp-git.enable = true; - cmp-buffer.enable = true; - nvim-cmp = { - enable = true; - snippet.expand = "luasnip"; - sources = [ - { name = "luasnip"; } - { name = "nvim_lsp"; } - { name = "path"; } - { name = "calc"; } - { name = "emoji"; } - ]; - mappingPresets = [ "insert" "cmdline" ]; - mapping = { - "" = "cmp.mapping.confirm({ select = true })"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.abort()"; - }; + keymaps = { + silent = true; + diagnostic = { + "rk" = "goto_prev"; + "rj" = "goto_next"; + }; + lspBuf = { + K = "hover"; + gD = "declaration"; + + "ra" = "code_action"; + "rn" = "rename"; + "rs" = "signature_help"; + "f" = "format"; }; }; - # For some reason you can't do this directly in nix? - extraConfigLuaPost = '' - do - local cmp = require('cmp') - cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'git' }, - }, { - { name = 'buffer' }, + onAttach = '' + if client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) + vim.api.nvim_clear_autocmds { buffer = bufnr, group = "lsp_document_highlight" } + vim.api.nvim_create_autocmd("CursorHold", { + callback = vim.lsp.buf.document_highlight, + buffer = bufnr, + group = "lsp_document_highlight", + desc = "Document Highlight", }) - }) - - cmp.setup.cmdline({ '/', '?' }, { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = 'buffer' } - } - }) - - cmp.setup.cmdline(':', { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } + vim.api.nvim_create_autocmd("CursorMoved", { + callback = vim.lsp.buf.clear_references, + buffer = bufnr, + group = "lsp_document_highlight", + desc = "Clear All the References", }) - }) end ''; }; + + # Autocomplete + plugins = { + luasnip.enable = true; + cmp-cmdline.enable = true; + cmp-git.enable = true; + cmp-buffer.enable = true; + nvim-cmp = { + enable = true; + snippet.expand = "luasnip"; + sources = [ + { name = "luasnip"; } + { name = "nvim_lsp"; } + { name = "path"; } + { name = "calc"; } + { name = "emoji"; } + ]; + mappingPresets = [ "insert" "cmdline" ]; + mapping = { + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.abort()"; + }; + }; + }; + + # For some reason you can't do this directly in nix? + extraConfigLuaPost = '' + do + local cmp = require('cmp') + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'git' }, + }, { + { name = 'buffer' }, + }) + }) + + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + end + ''; } diff --git a/sets/workstation.nix b/sets/workstation.nix index 953f120..fbd34a2 100644 --- a/sets/workstation.nix +++ b/sets/workstation.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ pkgs, inputs, ... }@args: { imports = [ @@ -6,9 +6,9 @@ ./packages.nix ./pipewire.nix ./base.nix - ./nvim.nix ../home ./nix-index.nix + inputs.nixvim.nixosModules.nixvim ]; i18n.defaultLocale = "de_DE.UTF-8"; @@ -16,10 +16,13 @@ environment = { variables.EDITOR = "nvim"; + variables.VISUAL = "nvim"; variables.TERMINAL = "kitty"; enableDebugInfo = true; }; + programs.nixvim = import ./nvim.nix args // { enable = true; }; + services = { avahi = { enable = true;