From dc39b8570196f74f48c43348220d770ff8916945 Mon Sep 17 00:00:00 2001 From: joygnu Date: Mon, 8 Jul 2024 13:44:01 +0200 Subject: [PATCH] neovim --- flake.lock | 250 ++++++++++++++++++++++++++- flake.nix | 14 +- home/default.nix | 17 +- home/hyprland/default.nix | 2 - hosts/desktop/default.nix | 1 + modules/default.nix | 1 + modules/neovim/default.nix | 46 +++++ modules/neovim/plugins/alpha.nix | 78 +++++++++ modules/neovim/plugins/cmp.nix | 81 +++++++++ modules/neovim/plugins/default.nix | 10 ++ modules/neovim/plugins/lsp.nix | 12 ++ modules/neovim/plugins/luasnip.nix | 16 ++ modules/neovim/plugins/telescope.nix | 48 +++++ modules/neovim/set.nix | 28 +++ 14 files changed, 588 insertions(+), 16 deletions(-) create mode 100644 modules/neovim/default.nix create mode 100644 modules/neovim/plugins/alpha.nix create mode 100644 modules/neovim/plugins/cmp.nix create mode 100644 modules/neovim/plugins/default.nix create mode 100644 modules/neovim/plugins/lsp.nix create mode 100644 modules/neovim/plugins/luasnip.nix create mode 100644 modules/neovim/plugins/telescope.nix create mode 100644 modules/neovim/set.nix diff --git a/flake.lock b/flake.lock index 97c9588..ea724cc 100644 --- a/flake.lock +++ b/flake.lock @@ -132,7 +132,59 @@ "type": "github" } }, + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717408969, + "narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=", + "owner": "numtide", + "repo": "devshell", + "rev": "1ebbe68d57457c8cae98145410b164b5477761f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "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-compat_3": { "flake": false, "locked": { "lastModified": 1673956053, @@ -148,6 +200,45 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719877454, + "narHash": "sha256-g5N1yyOSsPNiOlFfkuI/wcUjmtah+nxdImJqrSATjOU=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "4e3583423212f9303aa1a6337f8dffb415920e4f", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "fromYaml": { "flake": false, "locked": { @@ -164,6 +255,55 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719259945, + "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", + "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" + } + }, "gnome-shell": { "flake": false, "locked": { @@ -202,6 +342,27 @@ } }, "home-manager_2": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719827439, + "narHash": "sha256-tneHOIv1lEavZ0vQ+rgz67LPNCgOZVByYki3OkSshFU=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "59ce796b2563e19821361abbe2067c3bb4143a7d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "home-manager_3": { "inputs": { "nixpkgs": [ "stylix", @@ -222,6 +383,27 @@ "type": "github" } }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719845423, + "narHash": "sha256-ZLHDmWAsHQQKnmfyhYSHJDlt8Wfjv6SQhl2qek42O7A=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "ec12b88104d6c117871fad55e931addac4626756", + "type": "github" + }, + "original": { + "owner": "lnl7", + "repo": "nix-darwin", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1718714799, @@ -270,11 +452,39 @@ "type": "github" } }, + "nixvim": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "git-hooks": "git-hooks", + "home-manager": "home-manager_2", + "nix-darwin": "nix-darwin", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1720367057, + "narHash": "sha256-ZdSDmunn2oDPWm19RlFTwlK9BoAi9uw9QliWE4FnQc4=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "a6cc4c6c331c86e6b1ff7316fdc076f4ca7b163b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixvim", + "type": "github" + } + }, "root": { "inputs": { "ags": "ags", "home-manager": "home-manager", "nixpkgs": "nixpkgs_2", + "nixvim": "nixvim", "stylix": "stylix" } }, @@ -287,9 +497,9 @@ "base16-kitty": "base16-kitty", "base16-tmux": "base16-tmux", "base16-vim": "base16-vim", - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_3", "gnome-shell": "gnome-shell", - "home-manager": "home-manager_2", + "home-manager": "home-manager_3", "nixpkgs": "nixpkgs_3" }, "locked": { @@ -305,6 +515,42 @@ "repo": "stylix", "type": "github" } + }, + "systems": { + "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": 1719887753, + "narHash": "sha256-p0B2r98UtZzRDM5miGRafL4h7TwGRC4DII+XXHDHqek=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "bdb6355009562d8f9313d9460c0d3860f525bc6c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index a16a639..6a987d4 100644 --- a/flake.nix +++ b/flake.nix @@ -6,10 +6,15 @@ ags.url = "github:Aylur/ags"; stylix.url = "github:danth/stylix"; - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + nixvim = { + url = "github:nix-community/nixvim"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; @@ -25,6 +30,7 @@ specialArgs = {inherit inputs;}; modules = [ ./hosts/laptop + inputs.stylix.nixosModules.stylix ]; }; }; diff --git a/home/default.nix b/home/default.nix index e14edde..d962289 100644 --- a/home/default.nix +++ b/home/default.nix @@ -2,14 +2,15 @@ { imports = [ - ./rofi - ./alacritty - ./hyprland - ./zsh - ./gtk - ./git - ./ags - inputs.ags.homeManagerModules.default + ./rofi + ./alacritty + ./hyprland + ./zsh + ./gtk + ./git + ./ags + inputs.ags.homeManagerModules.default + inputs.nixvim.homeManagerModules.nixvim ]; home.username = "joy"; diff --git a/home/hyprland/default.nix b/home/hyprland/default.nix index 6b7d01b..4697073 100644 --- a/home/hyprland/default.nix +++ b/home/hyprland/default.nix @@ -34,8 +34,6 @@ exec-once = [ "lxqt-policykit-agent &" - "swww init &" - "swww img ~/nix/home/hyprland/wallpaper.png &" "ags -c ~/nix/home/ags/config.js &" "wl-paste --type text --watch cliphist store" "wl-paste --type image --watch cliphist store" diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index 26ff53a..09b9e45 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -10,5 +10,6 @@ ../../modules ./hardware.nix inputs.home-manager.nixosModules.default +# nixvim.nixosModules.nixvim ]; } diff --git a/modules/default.nix b/modules/default.nix index abb7293..cb7957a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,5 +7,6 @@ ./misc ./gdm ./stylix + ./neovim ]; } diff --git a/modules/neovim/default.nix b/modules/neovim/default.nix new file mode 100644 index 0000000..a9f5ab7 --- /dev/null +++ b/modules/neovim/default.nix @@ -0,0 +1,46 @@ +{ ... }: +{ + home-manager.users.joy = { + imports = [ + ./plugins + ./set.nix + ]; + programs.nixvim = { + enable = true; + defaultEditor = true; + vimAlias = true; + clipboard.register = "unnamedplus"; + colorschemes.catppuccin.enable = true; + + plugins = { + presence-nvim = { + enable = true; + mainImage = "file"; + }; + bufferline = { + enable = true; + separatorStyle = "slope"; + }; + treesitter = { + enable = true; + indent = true; + nixvimInjections = true; + }; + treesitter-context.enable = true; + nvim-tree = { + enable = true; + renderer.groupEmpty = true; + }; + lualine.enable = true; + }; + + keymaps = [ + { + mode = "n"; + key = ""; + action = "NvimTreeToggle"; + } + ]; + }; + }; +} diff --git a/modules/neovim/plugins/alpha.nix b/modules/neovim/plugins/alpha.nix new file mode 100644 index 0000000..3975997 --- /dev/null +++ b/modules/neovim/plugins/alpha.nix @@ -0,0 +1,78 @@ +{ ... }: +{ + programs.nixvim.plugins.alpha = { + enable = true; + layout = [ + { + type = "padding"; + val = 4; + } + { + opts = { + hl = "AlphaHeader"; + position = "center"; + }; + type = "text"; + val = [ + " ▄▄▄█████▓ ▒█████ ███▄ ▄███▓ " + " ▓ ██▒ ▓▒▒██▒ ██▒▓██▒▀█▀ ██▒ " + " ▒ ▓██░ ▒░▒██░ ██▒▓██ ▓██░ " + " ░ ▓██▓ ░ ▒██ ██░▒██ ▒██ " + " ▒██▒ ░ ░ ████▓▒░▒██▒ ░██▒ " + " ▒ ░░ ░ ▒░▒░▒░ ░ ▒░ ░ ░ " + " ░ ░ ▒ ▒░ ░ ░ ░ " + " ░ ░ ░ ░ ▒ ░ ░ " + " ░ ░ ░ " + " " + " git@github.com:TomJuri " + ]; + } + { + type = "padding"; + val = 2; + } + { + type = "group"; + val = let + mkButton = shortcut: cmd: val: hl: { + type = "button"; + inherit val; + opts = { + inherit hl shortcut; + keymap = [ + "n" + shortcut + cmd + {} + ]; + position = "center"; + cursor = 0; + width = 40; + align_shortcut = "right"; + hl_shortcut = "Keyword"; + }; + }; + in [ + ( + mkButton + "f" + "lua require('telescope.builtin').find_files({hidden = true})" + "🔍 Find File" + "Operator" + ) + ( + mkButton + "q" + "qa" + "💣 Quit" + "String" + ) + ]; + } + { + type = "padding"; + val = 2; + } + ]; + }; +} diff --git a/modules/neovim/plugins/cmp.nix b/modules/neovim/plugins/cmp.nix new file mode 100644 index 0000000..309fbcc --- /dev/null +++ b/modules/neovim/plugins/cmp.nix @@ -0,0 +1,81 @@ +{ ... }: +{ + programs.nixvim = { + plugins = { + cmp-nvim-lsp.enable = true; + cmp_luasnip.enable = true; + cmp = { + enable = true; + settings = { + autoEnableSources = true; + experimental = { ghost_text = true; }; + performance = { + debounce = 57; + fetchingTimeout = 197; + maxViewEntries = 27; + }; + + snippet.expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + + formatting.fields = ["kind" "abbr" "menu"]; + + sources = [ + { + name = "nvim_lsp"; + } + { + name = "luasnip"; + } + ]; + + mapping = { + "" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + }; + + window = { + completion.border = "solid"; + documentation.border = "solid"; + }; + }; + }; + }; + 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/modules/neovim/plugins/default.nix b/modules/neovim/plugins/default.nix new file mode 100644 index 0000000..80a20e4 --- /dev/null +++ b/modules/neovim/plugins/default.nix @@ -0,0 +1,10 @@ +{ ... }: +{ + imports = [ + ./alpha.nix + ./cmp.nix + ./lsp.nix + ./luasnip.nix + ./telescope.nix + ]; +} diff --git a/modules/neovim/plugins/lsp.nix b/modules/neovim/plugins/lsp.nix new file mode 100644 index 0000000..c133f97 --- /dev/null +++ b/modules/neovim/plugins/lsp.nix @@ -0,0 +1,12 @@ +{ ... }: +{ + programs.nixvim.plugins.lsp = { + enable = true; + servers = { + nil-ls = { enable = true; }; + kotlin-language-server = { enable = true; }; + rust-analyzer = { enable = true; installCargo = true; installRustc = true; }; + pyright = { enable = true; }; + }; + }; +} diff --git a/modules/neovim/plugins/luasnip.nix b/modules/neovim/plugins/luasnip.nix new file mode 100644 index 0000000..888df13 --- /dev/null +++ b/modules/neovim/plugins/luasnip.nix @@ -0,0 +1,16 @@ +{ pkgs, ... }: +{ + programs.nixvim.plugins.luasnip = { + enable = true; + extraConfig = { + enable_autosnippets = true; + store_selection_keys = ""; + }; + fromVscode = [ + { + lazyLoad = true; + paths = "${pkgs.vimPlugins.friendly-snippets}"; + } + ]; + }; +} diff --git a/modules/neovim/plugins/telescope.nix b/modules/neovim/plugins/telescope.nix new file mode 100644 index 0000000..7996520 --- /dev/null +++ b/modules/neovim/plugins/telescope.nix @@ -0,0 +1,48 @@ +{ pkgs, ... }: +{ + home.packages = [ + pkgs.ripgrep + ]; + + programs.nixvim.plugins.telescope = { + enable = true; + extensions = { + file-browser = { + enable = true; + }; + fzf-native = { + enable = true; + }; + }; + settings = { + defaults = { + layout_config = { + horizontal = { + prompt_position = "top"; + }; + }; + sorting_strategy = "ascending"; + }; + }; + keymaps = { + "" = { + action = "find_files, {}"; + options = { + desc = "Find project files"; + }; + }; + "/" = { + action = "live_grep"; + options = { + desc = "Grep (root dir)"; + }; + }; + "" = { + action = "git_files, {}"; + options = { + desc = "Search git files"; + }; + }; + }; + }; +} diff --git a/modules/neovim/set.nix b/modules/neovim/set.nix new file mode 100644 index 0000000..da15fa0 --- /dev/null +++ b/modules/neovim/set.nix @@ -0,0 +1,28 @@ +{ ... }: +{ + programs.nixvim = { + globals.mapleader = " "; + + opts = { + number = true; + relativenumber = true; + + tabstop = 2; + softtabstop = 2; + showtabline = 2; + expandtab = true; + + shiftwidth = 2; + smartindent = true; + + breakindent = true; + cursorline = true; + scrolloff = 8; + cmdheight = 0; + wrap = true; + termguicolors = true; + colorcolumn = "150"; + showmode = false; + }; + }; +}