From fcb2066392700766cabb06993f15861612fa0a21 Mon Sep 17 00:00:00 2001 From: Zhongheng Liu Date: Sun, 11 Aug 2024 19:50:16 +0800 Subject: [PATCH] feat: create gruvbox-themed nixvim configuration Added nixvim as a flake input in flake.nix Added plugin definitions ini home-manager/stvnliu/nixvim/ Added configuration options for easy toggling for editors --- flake.nix | 10 +- home-manager/stvnliu/editors.nix | 14 ++ home-manager/stvnliu/home.nix | 51 ++----- home-manager/stvnliu/nixvim/auto-pairs.nix | 1 + home-manager/stvnliu/nixvim/autosave.nix | 6 + home-manager/stvnliu/nixvim/bufferline.nix | 1 + home-manager/stvnliu/nixvim/cmp.nix | 152 ++++++++++++++++++++ home-manager/stvnliu/nixvim/default.nix | 146 +++++++++++++++++++ home-manager/stvnliu/nixvim/git.nix | 9 ++ home-manager/stvnliu/nixvim/ionide.nix | 5 + home-manager/stvnliu/nixvim/lsp.nix | 30 ++++ home-manager/stvnliu/nixvim/lualine.nix | 5 + home-manager/stvnliu/nixvim/none-ls.nix | 22 +++ home-manager/stvnliu/nixvim/nvim-tree.nix | 7 + home-manager/stvnliu/nixvim/options.nix | 23 +++ home-manager/stvnliu/nixvim/telescope.nix | 15 ++ home-manager/stvnliu/nixvim/toggleterm.nix | 8 ++ home-manager/stvnliu/nixvim/transparent.nix | 1 + home-manager/stvnliu/nixvim/treesitter.nix | 11 ++ home-manager/stvnliu/nixvim/trouble.nix | 5 + home-manager/stvnliu/nixvim/which_key.nix | 1 + home-manager/stvnliu/nixvim/wilder.nix | 6 + 22 files changed, 490 insertions(+), 39 deletions(-) create mode 100644 home-manager/stvnliu/editors.nix create mode 100644 home-manager/stvnliu/nixvim/auto-pairs.nix create mode 100644 home-manager/stvnliu/nixvim/autosave.nix create mode 100644 home-manager/stvnliu/nixvim/bufferline.nix create mode 100644 home-manager/stvnliu/nixvim/cmp.nix create mode 100644 home-manager/stvnliu/nixvim/default.nix create mode 100644 home-manager/stvnliu/nixvim/git.nix create mode 100644 home-manager/stvnliu/nixvim/ionide.nix create mode 100644 home-manager/stvnliu/nixvim/lsp.nix create mode 100644 home-manager/stvnliu/nixvim/lualine.nix create mode 100644 home-manager/stvnliu/nixvim/none-ls.nix create mode 100644 home-manager/stvnliu/nixvim/nvim-tree.nix create mode 100644 home-manager/stvnliu/nixvim/options.nix create mode 100644 home-manager/stvnliu/nixvim/telescope.nix create mode 100644 home-manager/stvnliu/nixvim/toggleterm.nix create mode 100644 home-manager/stvnliu/nixvim/transparent.nix create mode 100644 home-manager/stvnliu/nixvim/treesitter.nix create mode 100644 home-manager/stvnliu/nixvim/trouble.nix create mode 100644 home-manager/stvnliu/nixvim/which_key.nix create mode 100644 home-manager/stvnliu/nixvim/wilder.nix diff --git a/flake.nix b/flake.nix index 529a83d..a08072b 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,10 @@ inputs = { # Nixpkgs nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - + nixvim = { + url = "github:nix-community/nixvim"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # Home manager home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; @@ -37,7 +40,10 @@ pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance extraSpecialArgs = {inherit inputs outputs;}; # > Our main home-manager configuration file < - modules = [./home-manager/${stevenUserName}/home.nix]; + modules = [ + ./home-manager/${stevenUserName}/home.nix + inputs.nixvim.homeManagerModules.nixvim + ]; }; }; }; diff --git a/home-manager/stvnliu/editors.nix b/home-manager/stvnliu/editors.nix new file mode 100644 index 0000000..6399574 --- /dev/null +++ b/home-manager/stvnliu/editors.nix @@ -0,0 +1,14 @@ +{ + lib, + pkgs, + config, + ... +}: { + imports = [ + #./vscode.nix + #./intellij.nix + ]; + programs.nixvim = import ./nixvim; + # dependencies for nixvim configuration + home.packages = with pkgs; [ripgrep fd]; +} diff --git a/home-manager/stvnliu/home.nix b/home-manager/stvnliu/home.nix index 4da1296..594f74e 100644 --- a/home-manager/stvnliu/home.nix +++ b/home-manager/stvnliu/home.nix @@ -18,6 +18,8 @@ ./shells ./variables.nix ./mako.nix + ./wechat + ./editors.nix ]; nixpkgs = { @@ -50,14 +52,14 @@ "wallpaper.png".source = ./assets/gruvbox-wallpaper.png; }; }; - programs.neovim = { - enable = true; - viAlias = true; - vimAlias = true; - extraConfig = '' - set number - ''; - }; + #programs.neovim = { + # enable = true; + # viAlias = true; + # vimAlias = true; + # extraConfig = '' + # set number + # ''; + #}; home.packages = with pkgs; [ protonvpn-gui devenv @@ -65,34 +67,9 @@ zed-editor rhythmbox clash-verge-rev + qq libreoffice ]; - programs.waybar = { - enable = true; - settings = [ - { - mainBar = { - layer = "top"; - position = "top"; - height = 30; - output = ["eDP-1" "HDMI-A-1"]; - modules-left = ["hyprland/workspaces" "hyprland/mode" "wlr/taskbar"]; - modules-center = ["hyprland/window" "custom/hello-from-waybar"]; - modules-right = ["mpd" "temperature"]; - "hyprland/workspaces" = { - disable-scroll = true; - all-outputs = true; - }; - "custom/hello-from-waybar" = { - format = "hello {}"; - max-length = 40; - interval = "once"; - exec = pkgs.writeShellScript "hello-from-waybar" ''echo "from within waybar"''; - }; - }; - } - ]; - }; programs.git = { enable = true; package = pkgs.gitFull; @@ -124,12 +101,12 @@ } ]; }; - docked = { + docked_office_cn = { outputs = [ { - criteria = "HDMI-A-1"; + criteria = "AOC 2619 M1194JA002428"; position = "0,0"; - mode = "1920x1080@60Hz"; + mode = "1920x1200@59.94Hz"; } { criteria = "eDP-1"; diff --git a/home-manager/stvnliu/nixvim/auto-pairs.nix b/home-manager/stvnliu/nixvim/auto-pairs.nix new file mode 100644 index 0000000..c57a48b --- /dev/null +++ b/home-manager/stvnliu/nixvim/auto-pairs.nix @@ -0,0 +1 @@ +{plugins.nvim-autopairs = {enable = true;};} diff --git a/home-manager/stvnliu/nixvim/autosave.nix b/home-manager/stvnliu/nixvim/autosave.nix new file mode 100644 index 0000000..b2d375a --- /dev/null +++ b/home-manager/stvnliu/nixvim/autosave.nix @@ -0,0 +1,6 @@ +{ + plugins.auto-save = { + enable = true; + enableAutoSave = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/bufferline.nix b/home-manager/stvnliu/nixvim/bufferline.nix new file mode 100644 index 0000000..628aaa6 --- /dev/null +++ b/home-manager/stvnliu/nixvim/bufferline.nix @@ -0,0 +1 @@ +{plugins.bufferline = {enable = true;};} diff --git a/home-manager/stvnliu/nixvim/cmp.nix b/home-manager/stvnliu/nixvim/cmp.nix new file mode 100644 index 0000000..865859a --- /dev/null +++ b/home-manager/stvnliu/nixvim/cmp.nix @@ -0,0 +1,152 @@ +# # Source: https://github.com/hmajid2301/dotfiles/blob/ab7098387426f73c461950c7c0a4f8fb4c843a2c/home-manager/editors/nvim/plugins/coding/cmp.nix +{ + plugins = { + luasnip.enable = true; + copilot-lua = { + enable = true; + suggestion.enabled = false; + panel.enabled = false; + }; + + cmp-buffer = {enable = true;}; + + cmp-emoji = {enable = true;}; + + cmp-nvim-lsp = {enable = true;}; + + cmp-path = {enable = true;}; + + cmp_luasnip = {enable = true;}; + + cmp = { + enable = true; + + settings = { + snippet.expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + sources = [ + {name = "nvim_lsp";} + {name = "luasnip";} + { + name = "buffer"; + option.get_bufnrs.__raw = "vim.api.nvim_list_bufs"; + } + {name = "nvim_lua";} + {name = "path";} + {name = "copilot";} + ]; + + formatting = { + fields = ["abbr" "kind" "menu"]; + format = + # lua + '' + function(_, item) + local icons = { + Namespace = "󰌗", + Text = "󰉿", + Method = "󰆧", + Function = "󰆧", + Constructor = "", + Field = "󰜢", + Variable = "󰀫", + Class = "󰠱", + Interface = "", + Module = "", + Property = "󰜢", + Unit = "󰑭", + Value = "󰎠", + Enum = "", + Keyword = "󰌋", + Snippet = "", + Color = "󰏘", + File = "󰈚", + Reference = "󰈇", + Folder = "󰉋", + EnumMember = "", + Constant = "󰏿", + Struct = "󰙅", + Event = "", + Operator = "󰆕", + TypeParameter = "󰊄", + Table = "", + Object = "󰅩", + Tag = "", + Array = "[]", + Boolean = "", + Number = "", + Null = "󰟢", + String = "󰉿", + Calendar = "", + Watch = "󰥔", + Package = "", + Copilot = "", + Codeium = "", + TabNine = "", + } + + local icon = icons[item.kind] or "" + item.kind = string.format("%s %s", icon, item.kind or "") + return item + end + ''; + }; + + window = { + completion = { + winhighlight = "FloatBorder:CmpBorder,Normal:CmpPmenu,CursorLine:CmpSel,Search:PmenuSel"; + scrollbar = false; + sidePadding = 0; + border = ["╭" "─" "╮" "│" "╯" "─" "╰" "│"]; + }; + + settings.documentation = { + border = ["╭" "─" "╮" "│" "╯" "─" "╰" "│"]; + winhighlight = "FloatBorder:CmpBorder,Normal:CmpPmenu,CursorLine:CmpSel,Search:PmenuSel"; + }; + }; + + mapping = { + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true })"; + "" = + # lua + '' + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") + else + fallback() + end + end + ''; + "" = + # lua + '' + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") + else + fallback() + end + end + ''; + }; + }; + }; + }; +} diff --git a/home-manager/stvnliu/nixvim/default.nix b/home-manager/stvnliu/nixvim/default.nix new file mode 100644 index 0000000..9aadbe4 --- /dev/null +++ b/home-manager/stvnliu/nixvim/default.nix @@ -0,0 +1,146 @@ +{pkgs, ...}: { + imports = [ + ./auto-pairs.nix + ./autosave.nix + ./bufferline.nix + ./cmp.nix + ./git.nix + ./ionide.nix + ./lualine.nix + ./lsp.nix + ./none-ls.nix + ./nvim-tree.nix + ./options.nix + ./telescope.nix + ./toggleterm.nix + ./transparent.nix + ./treesitter.nix + ./trouble.nix + ./which_key.nix + ./wilder.nix + ]; + enable = true; + globals.mapleader = " "; + colorschemes.gruvbox = {enable = true;}; + keymaps = [ + # Global + # Default mode is "" which means normal-visual-op + { + mode = "n"; + key = "bg"; + action = "TransparentToggle"; + options.desc = "Toggle background transparency"; + } + { + key = ""; + action = "NvimTreeToggle"; + options.desc = "Toggle NvimTree"; + } + + # File + { + mode = "n"; + key = "f"; + action = "+find/file"; + } + { + # Format file + key = "fm"; + action = "lua vim.lsp.buf.format()"; + options.desc = "Format the current buffer"; + } + + # Git + { + mode = "n"; + key = "g"; + action = "+git"; + } + { + mode = "n"; + key = "gt"; + action = "+toggles"; + } + { + key = "gtb"; + action = "Gitsigns toggle_current_line_blame"; + options.desc = "Gitsigns current line blame"; + } + { + key = "gtd"; + action = "Gitsigns toggle_deleted"; + options.desc = "Gitsigns deleted"; + } + { + key = "gd"; + action = "Gitsigns diffthis"; + options.desc = "Gitsigns diff this buffer"; + } + + # Tabs + { + mode = "n"; + key = "t"; + action = "+tab"; + } + { + mode = "n"; + key = "tn"; + action = "tabnew"; + options.desc = "Create new tab"; + } + { + mode = "n"; + key = "td"; + action = "tabclose"; + options.desc = "Close tab"; + } + { + mode = "n"; + key = "ts"; + action = "tabnext"; + options.desc = "Go to the sub-sequent tab"; + } + { + mode = "n"; + key = "tp"; + action = "tabprevious"; + options.desc = "Go to the previous tab"; + } + + # Terminal + { + # Escape terminal mode using ESC + mode = "t"; + key = ""; + action = ""; + options.desc = "Escape terminal mode"; + } + + # Trouble + { + mode = "n"; + key = "d"; + action = "+diagnostics/debug"; + } + { + key = "dt"; + action = "TroubleToggle"; + options.desc = "Toggle trouble"; + } + + # Rust + { + mode = "n"; + key = "r"; + action = "+rust"; + } + { + # Start standalone rust-analyzer (fixes issues when opening files from nvim tree) + mode = "n"; + key = "rs"; + action = "RustStartStandaloneServerForBuffer"; + options.desc = "Start standalone rust-analyzer"; + } + ]; +} diff --git a/home-manager/stvnliu/nixvim/git.nix b/home-manager/stvnliu/nixvim/git.nix new file mode 100644 index 0000000..e5cbbb7 --- /dev/null +++ b/home-manager/stvnliu/nixvim/git.nix @@ -0,0 +1,9 @@ +{ + plugins.gitsigns = { + enable = true; + settings = { + current_line_blame = true; + trouble = true; + }; + }; +} diff --git a/home-manager/stvnliu/nixvim/ionide.nix b/home-manager/stvnliu/nixvim/ionide.nix new file mode 100644 index 0000000..db3d3fc --- /dev/null +++ b/home-manager/stvnliu/nixvim/ionide.nix @@ -0,0 +1,5 @@ +{pkgs, ...}: { + extraPlugins = with pkgs.vimPlugins; [ + Ionide-vim + ]; +} diff --git a/home-manager/stvnliu/nixvim/lsp.nix b/home-manager/stvnliu/nixvim/lsp.nix new file mode 100644 index 0000000..a83f01b --- /dev/null +++ b/home-manager/stvnliu/nixvim/lsp.nix @@ -0,0 +1,30 @@ +{ + plugins = { + lsp = { + enable = true; + servers = { + pylsp.enable = true; + bashls.enable = true; + clangd.enable = true; + fsautocomplete.enable = true; + gopls.enable = true; + nil_ls.enable = true; + #nixd.enable = true; + rust-analyzer.enable = true; + tsserver.enable = true; + }; + keymaps.lspBuf = { + "gd" = "definition"; + "gD" = "references"; + "gt" = "type_definition"; + "gi" = "implementation"; + "K" = "hover"; + }; + }; + lsp-lines = { + enable = true; + currentLine = true; + }; + rust-tools.enable = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/lualine.nix b/home-manager/stvnliu/nixvim/lualine.nix new file mode 100644 index 0000000..015eb2a --- /dev/null +++ b/home-manager/stvnliu/nixvim/lualine.nix @@ -0,0 +1,5 @@ +{ + plugins.lualine = { + enable = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/none-ls.nix b/home-manager/stvnliu/nixvim/none-ls.nix new file mode 100644 index 0000000..b32f006 --- /dev/null +++ b/home-manager/stvnliu/nixvim/none-ls.nix @@ -0,0 +1,22 @@ +{ + plugins.none-ls = { + enable = true; + sources = { + diagnostics = { + golangci_lint.enable = true; + ktlint.enable = true; + statix.enable = true; + }; + formatting = { + fantomas.enable = true; + gofmt.enable = true; + goimports.enable = true; + ktlint.enable = true; + nixfmt.enable = true; + markdownlint.enable = true; + shellharden.enable = true; + shfmt.enable = true; + }; + }; + }; +} diff --git a/home-manager/stvnliu/nixvim/nvim-tree.nix b/home-manager/stvnliu/nixvim/nvim-tree.nix new file mode 100644 index 0000000..feeb936 --- /dev/null +++ b/home-manager/stvnliu/nixvim/nvim-tree.nix @@ -0,0 +1,7 @@ +{ + plugins.nvim-tree = { + enable = true; + openOnSetupFile = true; + autoReloadOnWrite = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/options.nix b/home-manager/stvnliu/nixvim/options.nix new file mode 100644 index 0000000..231c131 --- /dev/null +++ b/home-manager/stvnliu/nixvim/options.nix @@ -0,0 +1,23 @@ +{ + config.opts = { + updatetime = 100; # Faster completion + + number = true; + relativenumber = true; + + autoindent = true; + clipboard = "unnamedplus"; + expandtab = true; + shiftwidth = 2; + smartindent = true; + tabstop = 2; + + ignorecase = true; + incsearch = true; + smartcase = true; + wildmode = "list:longest"; + + swapfile = false; + undofile = true; # Build-in persistent undo + }; +} diff --git a/home-manager/stvnliu/nixvim/telescope.nix b/home-manager/stvnliu/nixvim/telescope.nix new file mode 100644 index 0000000..989ff58 --- /dev/null +++ b/home-manager/stvnliu/nixvim/telescope.nix @@ -0,0 +1,15 @@ +{ + plugins.telescope = { + enable = true; + keymaps = { + "" = "live_grep"; + "fg" = { + action = "git_files"; + options = { + desc = "Telescope Git Files"; + }; + }; + }; + extensions.fzf-native = {enable = true;}; + }; +} diff --git a/home-manager/stvnliu/nixvim/toggleterm.nix b/home-manager/stvnliu/nixvim/toggleterm.nix new file mode 100644 index 0000000..125b000 --- /dev/null +++ b/home-manager/stvnliu/nixvim/toggleterm.nix @@ -0,0 +1,8 @@ +{ + plugins.toggleterm = { + enable = true; + settings = { + open_mapping = "[[]]"; + }; + }; +} diff --git a/home-manager/stvnliu/nixvim/transparent.nix b/home-manager/stvnliu/nixvim/transparent.nix new file mode 100644 index 0000000..f81c39b --- /dev/null +++ b/home-manager/stvnliu/nixvim/transparent.nix @@ -0,0 +1 @@ +{plugins.transparent.enable = true;} diff --git a/home-manager/stvnliu/nixvim/treesitter.nix b/home-manager/stvnliu/nixvim/treesitter.nix new file mode 100644 index 0000000..da621c1 --- /dev/null +++ b/home-manager/stvnliu/nixvim/treesitter.nix @@ -0,0 +1,11 @@ +{ + plugins = { + treesitter = { + enable = true; + nixGrammars = true; + indent = true; + }; + treesitter-context.enable = true; + rainbow-delimiters.enable = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/trouble.nix b/home-manager/stvnliu/nixvim/trouble.nix new file mode 100644 index 0000000..76f52a2 --- /dev/null +++ b/home-manager/stvnliu/nixvim/trouble.nix @@ -0,0 +1,5 @@ +{ + plugins = { + trouble.enable = true; + }; +} diff --git a/home-manager/stvnliu/nixvim/which_key.nix b/home-manager/stvnliu/nixvim/which_key.nix new file mode 100644 index 0000000..1b73707 --- /dev/null +++ b/home-manager/stvnliu/nixvim/which_key.nix @@ -0,0 +1 @@ +{plugins.which-key = {enable = true;};} diff --git a/home-manager/stvnliu/nixvim/wilder.nix b/home-manager/stvnliu/nixvim/wilder.nix new file mode 100644 index 0000000..84d2a31 --- /dev/null +++ b/home-manager/stvnliu/nixvim/wilder.nix @@ -0,0 +1,6 @@ +{ + plugins.wilder = { + enable = true; + modes = [":" "/" "?"]; + }; +}