From 65f6600f324601607dd1fb096cce8f512e1e85ac Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Thu, 30 May 2024 19:45:38 +0200 Subject: [PATCH] Initial nixvim config (replaces helix) --- flake.lock | 276 ++++++++++++++++++ flake.nix | 18 +- home/christoph/default.nix | 11 +- home/modules/default.nix | 1 + home/modules/neovim/default.nix | 484 ++++++++++++++++++++++++++++---- 5 files changed, 719 insertions(+), 71 deletions(-) diff --git a/flake.lock b/flake.lock index 7ee23890..22adced1 100644 --- a/flake.lock +++ b/flake.lock @@ -19,6 +19,28 @@ "type": "github" } }, + "devshell_2": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713532798, + "narHash": "sha256-wtBhsdMJA3Wa32Wtm1eeo84GejtI43pMrFrmwLXrsEc=", + "owner": "numtide", + "repo": "devshell", + "rev": "12e914740a25ea1891ec619bb53cf5e6ca922e40", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, "emacs-overlay": { "inputs": { "flake-utils": "flake-utils_2", @@ -55,6 +77,72 @@ "type": "github" } }, + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715865404, + "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-root": { + "locked": { + "lastModified": 1713493429, + "narHash": "sha256-ztz8JQkI08tjKnsTpfLqzWoKFQF4JGu2LRz8bkdnYUk=", + "owner": "srid", + "repo": "flake-root", + "rev": "bc748b93b86ee76e2032eecda33440ceb2532fcd", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -91,6 +179,73 @@ "type": "github" } }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716213921, + "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixvim", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "hardware": { "locked": { "lastModified": 1716987116, @@ -126,6 +281,48 @@ "type": "github" } }, + "home-manager_2": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716457508, + "narHash": "sha256-ZxzffLuWRyuMrkVVq7wastNUqeO0HJL9xqfY1QsYaqo=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "850cb322046ef1a268449cf1ceda5fd24d930b05", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716511055, + "narHash": "sha256-5Fe/DGgvMhPEMl9VdVxv3zvwRcwNDmW5eRJ0gk72w7U=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "0bea8222f6e83247dd13b055d83e64bce02ee532", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, "nix-flatpak": { "locked": { "lastModified": 1711997201, @@ -206,6 +403,48 @@ "type": "github" } }, + "nixpkgs_4": { + "locked": { + "lastModified": 1716509168, + "narHash": "sha256-4zSIhSRRIoEBwjbPm3YiGtbd8HDWzFxJjw5DYSDy1n8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfb7a882678e518398ce9a31a881538679f6f092", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixvim": { + "inputs": { + "devshell": "devshell_2", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "flake-root": "flake-root", + "git-hooks": "git-hooks", + "home-manager": "home-manager_2", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs_4", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1717012327, + "narHash": "sha256-hmm9DA0+7RSbxudrscrjKJ3EGSwxvrkpjpCEAa+GtT8=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "2031a09b36c19526aa82d27167942edf62915b66", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixvim", + "type": "github" + } + }, "nur": { "locked": { "lastModified": 1717054761, @@ -230,6 +469,7 @@ "home-manager": "home-manager", "nix-flatpak": "nix-flatpak", "nixpkgs": "nixpkgs_3", + "nixvim": "nixvim", "nur": "nur" } }, @@ -262,6 +502,42 @@ "repo": "default", "type": "github" } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715940852, + "narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "2fba33a182602b9d49f0b2440513e5ee091d838b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 3102dc04..f0367065 100644 --- a/flake.nix +++ b/flake.nix @@ -18,13 +18,13 @@ # Other Flakes emacs-overlay.url = "github:nix-community/emacs-overlay"; nur.url = "github:nix-community/NUR"; - # musnix.url = "github:musnix/musnix"; devshell.url = "github:numtide/devshell"; - # hyprland.url = "github:hyprwm/Hyprland"; # NOTE: only for Home-Manager, NixOS includes hyprland - # hyprpaper.url = "github:hyprwm/hyprpaper"; # NOTE: replaced with hyprpaper package - # hyprpicker.url = "github:hyprwm/hyprpicker"; # NOTE: replaced with hyprpicker package - # nixvim.url = "github:pta2002/nixvim"; + nixvim.url = "github:nix-community/nixvim"; + nix-flatpak.url = "github:gmodena/nix-flatpak/?ref=v0.4.1"; + # musnix.url = "github:musnix/musnix"; # nixified-ai.url = "github:nixified-ai/flake"; + # nixos-conf-editor.url = "github:vlinkz/nixos-conf-editor"; + # nix-matlab.url = "gitlab:doronbehar/nix-matlab"; # plasma-manager.url = "github:pjones/plasma-manager"; # plasma-manager.inputs.nixpkgs.follows = "nixpkgs"; @@ -33,14 +33,12 @@ firefox-gnome-theme.url = "github:rafaelmardojai/firefox-gnome-theme"; firefox-gnome-theme.flake = false; - nix-flatpak.url = "github:gmodena/nix-flatpak/?ref=v0.4.1"; - # adwaita-for-steam.url = "github:tkashkin/Adwaita-for-Steam"; # adwaita-for-steam.flake = false; - # nixos-conf-editor.url = "github:vlinkz/nixos-conf-editor"; - - # nix-matlab.url = "gitlab:doronbehar/nix-matlab"; + # hyprland.url = "github:hyprwm/Hyprland"; # NOTE: only for Home-Manager, NixOS includes hyprland + # hyprpaper.url = "github:hyprwm/hyprpaper"; # NOTE: replaced with hyprpaper package + # hyprpicker.url = "github:hyprwm/hyprpicker"; # NOTE: replaced with hyprpicker package }; # Outputs is a function that takes the inputs as arguments. diff --git a/home/christoph/default.nix b/home/christoph/default.nix index fa990999..6dc61f9c 100644 --- a/home/christoph/default.nix +++ b/home/christoph/default.nix @@ -84,7 +84,7 @@ rec { # jabref.enable = false; # }; - helix.enable = true; + helix.enable = false; hyprland = { enable = true; @@ -176,7 +176,7 @@ rec { }; neovim = { - enable = false; + enable = true; alias = true; }; @@ -263,8 +263,10 @@ rec { sessionVariables = { LANG = "en_US.UTF-8"; - EDITOR = "hx"; - VISUAL = "hx"; + # TODO: Configure in neovim/helix modules and choose a winner + # EDITOR = "hx"; + # VISUAL = "hx"; + # TERMINAL = "alacritty -o font.size=12"; TERMINAL = "kitty"; BROWSER = "firefox"; @@ -367,6 +369,7 @@ rec { # suricata cifs-utils # Mount samba shares nfs-utils + sshfs appimage-run # decker # TODO: Build failure diff --git a/home/modules/default.nix b/home/modules/default.nix index f967ffb1..47fe9ddc 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -29,5 +29,6 @@ ./waybar inputs.nix-flatpak.homeManagerModules.nix-flatpak + inputs.nixvim.homeManagerModules.nixvim ]; } diff --git a/home/modules/neovim/default.nix b/home/modules/neovim/default.nix index 20af5ed8..3a072479 100644 --- a/home/modules/neovim/default.nix +++ b/home/modules/neovim/default.nix @@ -19,71 +19,441 @@ in { # VISUAL = "nvim"; # }; - programs.neovim = { + home.packages = with pkgs; [ + # Linters + vale + + # Formatters + alejandra # nix + jq # json + html-tidy # html + ]; + + programs.nixvim = { enable = true; + defaultEditor = true; + enableMan = true; + colorschemes.catppuccin.enable = true; - extraConfig = '' - set incsearch - set hlsearch - set ignorecase - set autoindent - set expandtab - set smartindent - set smarttab - set shiftwidth=4 - set softtabstop=4 - set backspace=indent,eol,start - set ruler - set number - set laststatus=2 - set noshowmode - set undofile - set undodir=~/.vim/undo - set hidden - set printfont=JetBrainsMono\ Nerd\ Font\ Mono:h10 - set guifont=JetBrainsMono\ Nerd\ Font\ Mono:h12 - let printencoding='utf-8' - set encoding=utf-8 - ''; + opts = { + ruler = true; # Show cursor position in status line + number = true; + relativenumber = false; + showmode = false; # Status line already shows this + backspace = ["indent" "eol" "start"]; + undofile = true; + undodir = "~/.vim/undo"; + encoding = "utf-8"; - plugins = with pkgs.vimPlugins; [ - # vim-nix - # YouCompleteMe - surround-nvim + # TODO: Move neovide config to this module + # printfont = "JetBrainsMono Nerd Font Mono:h10"; + # guifont = "JetBrainsMono Nerd Font Mono:h12"; - { - plugin = lualine-nvim; - config = '' - lua << EOF - require('lualine').setup {} - EOF - ''; - } + # Search + incsearch = true; # Already highlight results while typing + hlsearch = true; + ignorecase = true; + laststatus = 2; + hidden = true; # Don't unload buffers immediately - { - plugin = nvim-autopairs; - config = '' - lua << EOF - require('nvim-autopairs').setup {} - EOF - ''; - } + # Indentation + autoindent = true; + expandtab = true; + smartindent = true; + smarttab = true; + shiftwidth = 4; + softtabstop = 4; - { - plugin = nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars); - config = '' - lua << EOF - require('nvim-treesitter.configs').setup { - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - } - EOF - ''; - } + termguicolors = true; # For bufferline + }; + + extraLuaPackages = with pkgs.lua51Packages; [ + # lua-curl # For rest + # xml2lua # For rest + # mimetypes # For rest ]; + extraPlugins = with pkgs.vimPlugins; [ + vim-airline-themes + nvim-web-devicons + # nvim-nio # For rest + ]; + + plugins = { + # TODO: Fix the terribly ugly right side with the line numbers etc. + # Status line, alternative to lualine + airline = { + enable = false; + + settings = { + powerline_fonts = true; + theme = "catppuccin"; + }; + }; + + # Auto-close parenthesis, alternative to nvim-autopairs + autoclose = { + enable = true; + }; + + # TODO: Remove once I have telescope + # Alternative to bufferline + barbar = { + enable = true; + }; + + # Escape insert mode by pressing jk + better-escape = { + enable = true; + # keys = "keys.__raw = '' function() return vim.api.nvim_win_get_cursor(0)[2] > 1 and ‘l’ or ‘’ end '';"; + mapping = ["jk"]; + timeout = 200; # In ms + }; + + # Alternative to barbar + # bufferline = { + # enable = true; + + # middleMouseCommand = "bdelete! %d"; + # # rightMouseCommand = "BufferLineTogglePin"; + # separatorStyle = "thin"; + # }; + + # Directory tree + chadtree = { + enable = true; + }; + + # TODO: Requires LSP + clangd-extensions = { + enable = false; + }; + + # Completion engine + cmp = { + enable = true; + + settings = { + sources = [ + { name = "async_path"; } + { name = "emoji"; } + { name = "nvim_lsp"; } + { name = "nvim_lsp_signature_help"; } + ]; + }; + }; + + # TODO: Add snippet engine completion + cmp-async-path.enable = true; + cmp-emoji.enable = true; + cmp-nvim-lsp.enable = true; + cmp-nvim-lsp-signature-help.enable = true; + + # Comment/Uncomment line/selection etc. + comment = { + enable = true; + }; + + # TODO: Setup formatters + # File formatter in addition to LSP (uses LSP as fallback) + conform-nvim = { + enable = true; + + formattersByFt = { + nix = [ "alejandra" ]; + }; + + # TODO: formatOnSave = " [???] "; + }; + + # TODO: Doesn't work, need LSP/treesitter? + # Highlight words under cursor, alternative to illuminate + cursorline = { + enable = false; + }; + + # TODO: Figure out how debugging from nvim works... + # Debug-Adapter-Protocol + dap = { + enable = false; + }; + + # TODO: Figure out how diff-mode works... + diffview = { + enable = false; + }; + + # TODO: Compare after telescope etc. are enabled + # Changes nvim UI components, alternative to Noice + dressing = { + enable = false; + }; + + # Notifications + LSP progress, alternative to Noice + fidget = { + enable = false; + }; + + # TODO: Doesn't work + # Search labels + flash = { + enable = true; + }; + + # Git client + fugitive = { + enable = true; + }; + + # Alternative to gitsigns + # gitgutter = { + # enable = true; + # grep.package = (pkgs.ripgrep.override {withPCRE2 = true;}); + # grep.command = "rg"; + # }; + + # Display message of commit that modified the current line + gitmessenger = { + enable = true; + }; + + # Alternative to gitgutter + gitsigns = { + enable = true; + + settings = { + current_line_blame = false; + }; + }; + + # Vim habit trainer, blocks keys + hardtime = { + enable = false; + }; + + # TODO: Maybe, don't know yet (also, telescope) + # Mark files and jump to them + harpoon = { + enable = false; + }; + + # Markdown etc. heading highlights + headlines = { + enable = true; + }; + + # TODO: + # Alternative to cursorline + illuminate = { + enable = true; + }; + + # Live-preview of LSP renamings + inc-rename = { + enable = true; + }; + + # TODO: Shortcut compatible with cmp + # Indent to current level on empty line + intellitab = { + enable = true; + }; + + lazygit = { + enable = true; + }; + + # TODO: More linters + # Linting as addition to LSP + lint = { + enable = true; + + lintersByFt = { + text = ["vale"]; + markdown = ["vale"]; + }; + }; + + # TODO: More LSP servers + # Language-Server-Protocol + lsp = { + enable = true; + + servers = { + nil_ls.enable = true; + }; + }; + + # TODO: Maybe too much? + # Render diagnostics as virtual line overlay + lsp-lines = { + enable = true; + }; + + # Statusline, alternative to airline + lualine = { + enable = true; + + globalstatus = true; + sectionSeparators = { left = ""; right = ""; }; + componentSeparators = { left = ""; right = ""; }; + }; + + # TODO: When I start actually using marks + # Show marks in the gutter + marks = { + enable = false; + }; + + # Structural overview + navbuddy = { + enable = true; + + lsp.autoAttach = true; + }; + + # Generate doc comments + neogen = { + enable = true; + }; + + # TODO: When I need this + # Interact with test frameworks + neotest = { + enable = false; + }; + + # NeoVim UI refresh, alternative to fidget and dressing + noice = { + enable = true; + }; + + notify = { + enable = true; + }; + + # Alternative to autoclose + nvim-autopairs = { + enable = false; + }; + + # Colorize color hex codes etc. + nvim-colorizer = { + enable = true; + }; + + # TODO: Folds the entire code at startup??? + # Code folding + nvim-ufo = { + enable = false; + }; + + # File system explorer that is editable like a normal buffer + oil = { + enable = true; + }; + + # Colorize paranthesis + rainbow-delimiters = { + enable = true; + }; + + # TODO: Lua deps not found + # REST/HTTP client + rest = { + enable = false; + }; + + # TODO: + rustaceanvim = { + enable = false; + }; + + # Work with pairs of delimiters + sandwich = { + enable = true; + }; + + # Automatically infer tab width + sleuth = { + enable = true; + }; + + # TODO: Doesn't show up + # Left-hand side status column with folding markers + statuscol = { + enable = false; + }; + + # Select something + telescope = { + enable = true; + + extensions = { + fzf-native.enable = true; + ui-select.enable = true; + undo.enable = true; + }; + }; + + # TODO: Folds at startup + treesitter = { + enable = true; + + ensureInstalled = "all"; + folding = false; + indent = true; + + incrementalSelection = { + enable = true; + }; + }; + + # Trim whitespace + trim = { + enable = true; + }; + + # Window listing detected linting/lsp problems + trouble = { + enable = true; + }; + + # Don't mess up splits when closing buffers + vim-bbye = { + enable = true; + }; + + # TODO: Setup + # LaTeX + vimtex = { + enable = true; + + texlivePackage = null; # Don't auto-install + }; + + # Display keybindings help + which-key = { + enable = true; + }; + + # TODO: Bindings + # Clipboard enhancements (e.g. history) + yanky = { + enable = true; + }; + }; + + # TODO: Use conform-nvim.formatOnSave, also make this toggleable and add a "Format" command + extraConfigLua = '' + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*", + callback = function(args) + require("conform").format({ bufnr = args.buf }) + end, + }) + ''; + viAlias = cfg.alias; vimAlias = cfg.alias; };