From c4f7a64329b56958d3e6844da1b62638b371cbf8 Mon Sep 17 00:00:00 2001 From: gwg313 Date: Tue, 3 Sep 2024 23:07:50 -0400 Subject: [PATCH] neovim/fw --- common/networking/default.nix | 12 +- common/networking/firewall.nix | 18 ++ home-manager/modules/hyprland.nix | 9 +- home-manager/modules/linux-gui.nix | 1 + .../neovim/plugins/clangd-extensions.nix | 30 +++ home-manager/modules/neovim/plugins/cmp.nix | 181 ++++++++++++++++++ .../modules/neovim/plugins/default.nix | 5 + home-manager/modules/neovim/plugins/lean.nix | 9 + home-manager/modules/neovim/plugins/lsp.nix | 4 + .../modules/neovim/plugins/refactoring.nix | 100 ++++++++++ .../modules/neovim/plugins/todo-comments.nix | 7 + .../modules/neovim/plugins/treesitter.nix | 2 + .../modules/neovim/plugins/undotree.nix | 39 ++++ hosts/candlekeep/configuration.nix | 10 +- hosts/grymforge/configuration.nix | 10 +- hosts/grymforge/hardware-configuration.nix | 14 +- 16 files changed, 427 insertions(+), 24 deletions(-) create mode 100644 common/networking/firewall.nix create mode 100644 home-manager/modules/neovim/plugins/clangd-extensions.nix create mode 100644 home-manager/modules/neovim/plugins/cmp.nix create mode 100644 home-manager/modules/neovim/plugins/lean.nix create mode 100644 home-manager/modules/neovim/plugins/refactoring.nix create mode 100644 home-manager/modules/neovim/plugins/undotree.nix diff --git a/common/networking/default.nix b/common/networking/default.nix index 0398525..5552711 100644 --- a/common/networking/default.nix +++ b/common/networking/default.nix @@ -1,9 +1,9 @@ -{ - config, - lib, - ... -}: { - imports = [./zerotier.nix]; +{lib, ...}: { + imports = [ + ./zerotier.nix + ./firewall.nix + ]; zerotier.enable = lib.mkDefault true; + firewall.enable = lib.mkDefault true; } diff --git a/common/networking/firewall.nix b/common/networking/firewall.nix new file mode 100644 index 0000000..b14141f --- /dev/null +++ b/common/networking/firewall.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + pkgs, + inputs, + outputs, + ... +}: { + options = { + firewall.enable = lib.mkEnableOption "Enable the Firewall"; + }; + config = lib.mkIf config.firewall.enable { + networking.nftables.enable = true; + networking.firewall = { + enable = true; + }; + }; +} diff --git a/home-manager/modules/hyprland.nix b/home-manager/modules/hyprland.nix index 4d37524..e514418 100644 --- a/home-manager/modules/hyprland.nix +++ b/home-manager/modules/hyprland.nix @@ -3,9 +3,7 @@ pkgs, ... }: { - imports = [ - ./waybar.nix - ]; + imports = [./waybar.nix]; services.mako = { enable = true; @@ -163,9 +161,8 @@ ]; monitor = [",preferred,auto,1"]; - exec = [ - "${pkgs.swaybg}/bin/swaybg -i ${config.stylix.image} -m fill" - ]; + # monitor = [ "HDMI-A-1,1920x1080@144,auto,1" ]; + exec = ["${pkgs.swaybg}/bin/swaybg -i ${config.stylix.image} -m fill"]; exec-once = [ # Enables clipboard sync "${pkgs.wl-clipboard}/bin/wl-paste -p | ${pkgs.wl-clipboard}/bin/wl-copy" diff --git a/home-manager/modules/linux-gui.nix b/home-manager/modules/linux-gui.nix index 379b531..a4ce10e 100644 --- a/home-manager/modules/linux-gui.nix +++ b/home-manager/modules/linux-gui.nix @@ -23,5 +23,6 @@ nicotine-plus anki obsidian + vlc ]; } diff --git a/home-manager/modules/neovim/plugins/clangd-extensions.nix b/home-manager/modules/neovim/plugins/clangd-extensions.nix new file mode 100644 index 0000000..9545524 --- /dev/null +++ b/home-manager/modules/neovim/plugins/clangd-extensions.nix @@ -0,0 +1,30 @@ +{...}: { + programs.nixvim = { + plugins = { + clangd-extensions = { + enable = true; + enableOffsetEncodingWorkaround = true; + + ast = { + roleIcons = { + type = ""; + declaration = ""; + expression = ""; + specifier = ""; + statement = ""; + templateArgument = ""; + }; + kindIcons = { + compound = ""; + recovery = ""; + translationUnit = ""; + packExpansion = ""; + templateTypeParm = ""; + templateTemplateParm = ""; + templateParamObject = ""; + }; + }; + }; + }; + }; +} diff --git a/home-manager/modules/neovim/plugins/cmp.nix b/home-manager/modules/neovim/plugins/cmp.nix new file mode 100644 index 0000000..dd36150 --- /dev/null +++ b/home-manager/modules/neovim/plugins/cmp.nix @@ -0,0 +1,181 @@ +{pkgs, ...}: { + programs.nixvim = { + extraConfigLuaPre = '' + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + ''; + plugins = { + luasnip = { + enable = true; + fromVscode = [{}]; + + settings = { + enable_autosnippets = true; + store_selection_keys = ""; + }; + }; + friendly-snippets = { + enable = true; + }; + + lspkind = { + enable = true; + mode = "symbol_text"; + cmp = { + enable = true; + # Custom Theme + after = '' + function(entry, vim_item, kind) + local strings = vim.split(kind.kind, "%s", { trimempty = true }) + kind.kind = " " .. (strings[1] or "") .. " " + kind.menu = " (" .. (strings[2] or "") .. ")" + return kind + end + ''; + }; + }; + cmp-nvim-lsp.enable = true; + cmp-nvim-lua.enable = true; + cmp_luasnip.enable = true; + cmp-path.enable = true; + cmp-latex-symbols.enable = true; + cmp-buffer.enable = true; + cmp = { + enable = true; + autoEnableSources = true; + + settings = { + experimental = { + ghost_text = true; + }; + sources = [ + { + name = "nvim_lsp"; + # priority = 1000; + # option = { }; + } + + {name = "luasnip";} + + {name = "buffer";} + + {name = "path";} + ]; + + mapping = { + "" = "cmp.mapping.confirm({ select = true })"; + "" = '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_locally_jumpable() then + require("luasnip").expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }) + ''; + "" = '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }) + ''; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + }; + window = { + documentation.max_height = "math.floor(40 * (40 / vim.o.lines))"; + completion = { + winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None"; + col_offset = -3; + side_padding = 0; + border = "rounded"; + }; + documentation = { + border = "rounded"; + }; + }; + + snippet.expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + + formatting = { + fields = [ + "kind" + "abbr" + "menu" + ]; + }; + + menu = { + buffer = ""; + calc = ""; + cmdline = ""; + codeium = "󱜙"; + emoji = "󰞅"; + git = ""; + luasnip = "󰩫"; + neorg = ""; + nvim_lsp = ""; + nvim_lua = ""; + path = ""; + spell = ""; + treesitter = "󰔱"; + }; + }; + }; + }; + + extraPlugins = with pkgs.vimPlugins; [vim-snippets]; + extraConfigLua = '' + luasnip = require("luasnip") + kind_icons = { + 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 = "", + } + ''; + }; +} diff --git a/home-manager/modules/neovim/plugins/default.nix b/home-manager/modules/neovim/plugins/default.nix index 8892b32..b2651cb 100644 --- a/home-manager/modules/neovim/plugins/default.nix +++ b/home-manager/modules/neovim/plugins/default.nix @@ -6,6 +6,8 @@ _: { ./catppuccin.nix ./comment.nix ./conform.nix + ./clangd-extensions.nix + ./cmp.nix ./diffview.nix ./flash.nix ./git-conflict.nix @@ -14,6 +16,7 @@ _: { ./illuminate.nix ./lightbulb.nix ./lualine.nix + ./lean.nix ./lsp.nix ./mini-bufremove.nix ./navic.nix @@ -22,12 +25,14 @@ _: { ./notify.nix ./precognition.nix ./spectre.nix + ./refactoring.nix ./telescope.nix ./todo-comments.nix ./toggleterm.nix ./treesitter.nix ./trouble.nix ./which-key.nix + ./undotree.nix ./yazi.nix ]; } diff --git a/home-manager/modules/neovim/plugins/lean.nix b/home-manager/modules/neovim/plugins/lean.nix new file mode 100644 index 0000000..6ccf0f4 --- /dev/null +++ b/home-manager/modules/neovim/plugins/lean.nix @@ -0,0 +1,9 @@ +{...}: { + programs.nixvim = { + plugins.lean = { + enable = true; + lsp.enable = false; + abbreviations.enable = false; + }; + }; +} diff --git a/home-manager/modules/neovim/plugins/lsp.nix b/home-manager/modules/neovim/plugins/lsp.nix index 22fc319..d406ee7 100644 --- a/home-manager/modules/neovim/plugins/lsp.nix +++ b/home-manager/modules/neovim/plugins/lsp.nix @@ -70,6 +70,10 @@ }; }; }; + + pyright.enable = true; + hls.enable = true; + leanls.enable = true; }; }; which-key.settings.spec = [ diff --git a/home-manager/modules/neovim/plugins/refactoring.nix b/home-manager/modules/neovim/plugins/refactoring.nix new file mode 100644 index 0000000..178a119 --- /dev/null +++ b/home-manager/modules/neovim/plugins/refactoring.nix @@ -0,0 +1,100 @@ +{...}: { + programs.nixvim = { + plugins = { + refactoring = { + enable = true; + }; + + telescope.enabledExtensions = ["refactoring"]; + + which-key.settings.spec = [ + { + __unkeyed = "r"; + mode = "x"; + group = " Refactor"; + } + ]; + }; + + keymaps = [ + { + mode = "x"; + key = "re"; + action = ":Refactor extract "; + options = { + desc = "Extract"; + silent = true; + }; + } + { + mode = "x"; + key = "rE"; + action = ":Refactor extract_to_file "; + options = { + desc = "Extract to file"; + silent = true; + }; + } + { + mode = "x"; + key = "rv"; + action = ":Refactor extract_var "; + options = { + desc = "Extract var"; + silent = true; + }; + } + { + mode = "n"; + key = "ri"; + action = ":Refactor inline_var"; + options = { + desc = "Inline var"; + silent = true; + }; + } + { + mode = "n"; + key = "rI"; + action = ":Refactor inline_func"; + options = { + desc = "Inline Func"; + silent = true; + }; + } + { + mode = "n"; + key = "rb"; + action = ":Refactor extract_block"; + options = { + desc = "Extract block"; + silent = true; + }; + } + { + mode = "n"; + key = "rB"; + action = ":Refactor extract_block_to_file"; + options = { + desc = "Extract block to file"; + silent = true; + }; + } + { + mode = "n"; + key = "fR"; + action.__raw = + # lua + '' + function() + require('telescope').extensions.refactoring.refactors() + end + ''; + options = { + desc = "Refactoring"; + silent = true; + }; + } + ]; + }; +} diff --git a/home-manager/modules/neovim/plugins/todo-comments.nix b/home-manager/modules/neovim/plugins/todo-comments.nix index 29a03cf..c51897b 100644 --- a/home-manager/modules/neovim/plugins/todo-comments.nix +++ b/home-manager/modules/neovim/plugins/todo-comments.nix @@ -2,6 +2,13 @@ programs.nixvim = { plugins.todo-comments = { enable = true; + + keymaps = { + todoTelescope = { + key = "ft"; + keywords = "TODO,FIX,HACK"; + }; + }; }; }; } diff --git a/home-manager/modules/neovim/plugins/treesitter.nix b/home-manager/modules/neovim/plugins/treesitter.nix index dedaec4..6b23487 100644 --- a/home-manager/modules/neovim/plugins/treesitter.nix +++ b/home-manager/modules/neovim/plugins/treesitter.nix @@ -7,6 +7,8 @@ settings = { indent.enable = true; + highlight.enable = true; + incremental_selection.enable = true; }; }; diff --git a/home-manager/modules/neovim/plugins/undotree.nix b/home-manager/modules/neovim/plugins/undotree.nix new file mode 100644 index 0000000..a63d00b --- /dev/null +++ b/home-manager/modules/neovim/plugins/undotree.nix @@ -0,0 +1,39 @@ +{...}: { + programs.nixvim = { + plugins.undotree = { + enable = true; + + settings = { + CursorLine = true; + DiffAutoOpen = true; + DiffCommand = "diff"; + DiffpanelHeight = 10; + HelpLine = true; + HighlightChangedText = true; + HighlightChangedWithSign = true; + HighlightSyntaxAdd = "DiffAdd"; + HighlightSyntaxChange = "DiffChange"; + HighlightSyntaxDel = "DiffDelete"; + RelativeTimestamp = true; + SetFocusWhenToggle = true; + ShortIndicators = false; + TreeNodeShape = "*"; + TreeReturnShape = "\\"; + TreeSplitShape = "/"; + TreeVertShape = "|"; + }; + }; + + keymaps = [ + { + mode = "n"; + key = "uu"; + action = ":UndotreeToggle"; + options = { + desc = "Undotree toggle"; + silent = true; + }; + } + ]; + }; +} diff --git a/hosts/candlekeep/configuration.nix b/hosts/candlekeep/configuration.nix index d19483b..aeea012 100644 --- a/hosts/candlekeep/configuration.nix +++ b/hosts/candlekeep/configuration.nix @@ -19,6 +19,7 @@ ../../common/nixos/bluetooth.nix ../../common/nixos/restic.nix ../../common/nixos/ssh/ssh.nix + ../../common/gui/steam.nix ../../common/nixos/ssh/ssh_client.nix ../../common/nixos/ssh/ssh_guard.nix ../../common/gui/hyprland.nix @@ -27,6 +28,8 @@ ../../common/virtualization/default.nix ../../common/nixos/sysctl/default.nix + ../../common/networking + ./auditd.nix ./kernel.nix ./sysctl.nix @@ -89,14 +92,15 @@ # This will add each flake input as a registry # To make nix3 commands consistent with your flake - nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ((lib.filterAttrs (_: lib.isType "flake")) inputs); + nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ( + (lib.filterAttrs (_: lib.isType "flake")) inputs + ); # This will additionally add your inputs to the system's legacy channels # Making legacy nix commands consistent as well, awesome! nix.nixPath = ["/etc/nix/path"]; environment.etc = - lib.mapAttrs' - (name: value: { + lib.mapAttrs' (name: value: { name = "nix/path/${name}"; value.source = value.flake; }) diff --git a/hosts/grymforge/configuration.nix b/hosts/grymforge/configuration.nix index 3b94363..d1e466b 100644 --- a/hosts/grymforge/configuration.nix +++ b/hosts/grymforge/configuration.nix @@ -14,7 +14,6 @@ # If you want to use modules your own flake exports (from modules/nixos): # outputs.nixosModules.example ../../common/nixos/common.nix - ../../common/networking/zerotier.nix ../../common/nixos/bluetooth.nix ../../common/nixos/restic.nix ../../common/nixos/ssh/default.nix @@ -27,6 +26,8 @@ ../../common/virtualization/libvirt.nix ../../common/nixos/sysctl/default.nix + ../../common/networking + ./syncthing.nix ./auditd.nix ./kernel.nix @@ -92,14 +93,15 @@ # This will add each flake input as a registry # To make nix3 commands consistent with your flake - nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ((lib.filterAttrs (_: lib.isType "flake")) inputs); + nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ( + (lib.filterAttrs (_: lib.isType "flake")) inputs + ); # This will additionally add your inputs to the system's legacy channels # Making legacy nix commands consistent as well, awesome! nix.nixPath = ["/etc/nix/path"]; environment.etc = - lib.mapAttrs' - (name: value: { + lib.mapAttrs' (name: value: { name = "nix/path/${name}"; value.source = value.flake; }) diff --git a/hosts/grymforge/hardware-configuration.nix b/hosts/grymforge/hardware-configuration.nix index 61e7307..0e127bf 100644 --- a/hosts/grymforge/hardware-configuration.nix +++ b/hosts/grymforge/hardware-configuration.nix @@ -10,10 +10,16 @@ }: { imports = [ (modulesPath + "/installer/scan/not-detected.nix") - # ../../common/nixos/nfs.nix + ../../common/nixos/nfs.nix ]; - boot.initrd.availableKernelModules = ["nvme" "xhci_pci" "usbhid" "usb_storage" "sd_mod"]; + boot.initrd.availableKernelModules = [ + "nvme" + "xhci_pci" + "usbhid" + "usb_storage" + "sd_mod" + ]; boot.initrd.kernelModules = []; boot.kernelModules = ["kvm-amd"]; boot.extraModulePackages = []; @@ -30,9 +36,7 @@ fsType = "vfat"; }; - swapDevices = [ - {device = "/dev/disk/by-uuid/04f457e4-1bd2-417f-bcb7-f8b770e71c21";} - ]; + swapDevices = [{device = "/dev/disk/by-uuid/04f457e4-1bd2-417f-bcb7-f8b770e71c21";}]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's