From 65a72ab802c59fa2b7e3af98d3b419711ba394d0 Mon Sep 17 00:00:00 2001 From: ulic-youthlic Date: Sat, 18 Oct 2025 23:10:53 +0800 Subject: [PATCH] feat: Add nvchad module and enable nvchad instead of nixvim --- flake.lock | 78 +++++++++++++- flake.nix | 13 +++ .../configurations/Tytonidae/default.nix | 1 + home/david/modules/programs/nvchad.nix | 26 +++++ home/modules/default.nix | 1 + nixos/configurations/Tytonidae/default.nix | 2 +- nvchad/init.lua | 37 +++++++ nvchad/lua/autocmds.lua | 1 + nvchad/lua/chadrc.lua | 31 ++++++ nvchad/lua/configs/conform.lua | 18 ++++ nvchad/lua/configs/idris2.lua | 8 ++ nvchad/lua/configs/lazy.lua | 45 ++++++++ nvchad/lua/configs/lspconfig.lua | 16 +++ nvchad/lua/mappings.lua | 29 +++++ nvchad/lua/options.lua | 102 ++++++++++++++++++ nvchad/lua/plugins/init.lua | 56 ++++++++++ 16 files changed, 460 insertions(+), 4 deletions(-) create mode 100644 home/david/modules/programs/nvchad.nix create mode 100644 nvchad/init.lua create mode 100644 nvchad/lua/autocmds.lua create mode 100644 nvchad/lua/chadrc.lua create mode 100644 nvchad/lua/configs/conform.lua create mode 100644 nvchad/lua/configs/idris2.lua create mode 100644 nvchad/lua/configs/lazy.lua create mode 100644 nvchad/lua/configs/lspconfig.lua create mode 100644 nvchad/lua/mappings.lua create mode 100644 nvchad/lua/options.lua create mode 100644 nvchad/lua/plugins/init.lua diff --git a/flake.lock b/flake.lock index 447a825..11bc930 100644 --- a/flake.lock +++ b/flake.lock @@ -524,6 +524,24 @@ "type": "github" } }, + "flake-utils_3": { + "inputs": { + "systems": "systems_5" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flakey-profile": { "locked": { "lastModified": 1712898590, @@ -1018,6 +1036,30 @@ "type": "github" } }, + "nix4nvchad": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ], + "nvchad-starter": [ + "nvchad-starter" + ] + }, + "locked": { + "lastModified": 1759653262, + "narHash": "sha256-uTiQXY/ZlplEq1j2jH0k6oDzldid0xHgnLsLQyRRbvk=", + "owner": "nix-community", + "repo": "nix4nvchad", + "rev": "9d91858966b5d4e87ee52e16993988dfea9b0f94", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix4nvchad", + "type": "github" + } + }, "nixos-hardware": { "locked": { "lastModified": 1760106635, @@ -1261,7 +1303,7 @@ "flake-parts": "flake-parts_6", "nixpkgs": "nixpkgs_7", "nuschtosSearch": "nuschtosSearch", - "systems": "systems_5" + "systems": "systems_6" }, "locked": { "lastModified": 1760906375, @@ -1323,7 +1365,7 @@ }, "nuschtosSearch": { "inputs": { - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils_3", "ixx": "ixx", "nixpkgs": [ "nixvim", @@ -1344,6 +1386,19 @@ "type": "github" } }, + "nvchad-starter": { + "flake": false, + "locked": { + "lastModified": 1, + "narHash": "sha256-F3ysDLjeyNGHcZYOQHbw8kjBqf3L+ESrZs9XMRefOJQ=", + "path": "./nvchad", + "type": "path" + }, + "original": { + "path": "./nvchad", + "type": "path" + } + }, "pre-commit-hooks-nix": { "inputs": { "flake-compat": [ @@ -1389,10 +1444,12 @@ "niri-flake": "niri-flake", "nix-doom": "nix-doom", "nix-gaming": "nix-gaming", + "nix4nvchad": "nix4nvchad", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs_6", "nixvim": "nixvim", "nur": "nur", + "nvchad-starter": "nvchad-starter", "sops-nix": "sops-nix", "spacemacs": "spacemacs", "stylix": "stylix", @@ -1513,7 +1570,7 @@ "nixpkgs" ], "nur": "nur_2", - "systems": "systems_6", + "systems": "systems_7", "tinted-foot": "tinted-foot", "tinted-kitty": "tinted-kitty", "tinted-schemes": "tinted-schemes", @@ -1624,6 +1681,21 @@ "type": "github" } }, + "systems_7": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "tinted-foot": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index e451eec..c33a7b1 100644 --- a/flake.nix +++ b/flake.nix @@ -194,6 +194,19 @@ owner = "nix-community"; repo = "neovim-nightly-overlay"; }; + nvchad-starter = { + url = "path:./nvchad"; + flake = false; + }; + nix4nvchad = { + type = "github"; + owner = "nix-community"; + repo = "nix4nvchad"; + inputs = { + nixpkgs.follows = "nixpkgs"; + nvchad-starter.follows = "nvchad-starter"; + }; + }; lanzaboote = { type = "github"; diff --git a/home/david/configurations/Tytonidae/default.nix b/home/david/configurations/Tytonidae/default.nix index 2e0dd36..e7de391 100644 --- a/home/david/configurations/Tytonidae/default.nix +++ b/home/david/configurations/Tytonidae/default.nix @@ -57,6 +57,7 @@ firefox.enable = true; openssh.enable = true; helix.enable = true; + nvchad.enable = true; # spacemacs.enable = true; }; }; diff --git a/home/david/modules/programs/nvchad.nix b/home/david/modules/programs/nvchad.nix new file mode 100644 index 0000000..3328c65 --- /dev/null +++ b/home/david/modules/programs/nvchad.nix @@ -0,0 +1,26 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.david.programs.nvchad; +in +{ + options = { + david.programs.nvchad = { + enable = lib.mkEnableOption "nvchad"; + }; + }; + config = lib.mkIf cfg.enable { + programs.nvchad = { + enable = true; + extraPackages = with pkgs; [ + editor-runtime + ]; + neovim = pkgs.neovim-nightly; + backup = true; + }; + }; +} diff --git a/home/modules/default.nix b/home/modules/default.nix index cf2a7ed..4585136 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -8,6 +8,7 @@ (with inputs; [ sops-nix.homeManagerModules.sops betterfox-nix.homeModules.betterfox + nix4nvchad.homeManagerModule ]) ++ lib.youthlic.loadImports ./.; diff --git a/nixos/configurations/Tytonidae/default.nix b/nixos/configurations/Tytonidae/default.nix index f91368a..c81056c 100644 --- a/nixos/configurations/Tytonidae/default.nix +++ b/nixos/configurations/Tytonidae/default.nix @@ -91,7 +91,7 @@ waypipe wineWow64Packages.waylandFull iperf3 - nixvim + neovim-nightly doom-emacs neovide osu-lazer-bin # typochecker: disable-line diff --git a/nvchad/init.lua b/nvchad/init.lua new file mode 100644 index 0000000..e861b68 --- /dev/null +++ b/nvchad/init.lua @@ -0,0 +1,37 @@ +vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/" +vim.g.mapleader = " " + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" + +if not vim.uv.fs_stat(lazypath) then + local repo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } +end + +vim.opt.rtp:prepend(lazypath) + +local lazy_config = require "configs.lazy" + +-- load plugins +require("lazy").setup({ + { + "NvChad/NvChad", + lazy = false, + branch = "v2.5", + import = "nvchad.plugins", + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "options" +require "autocmds" + +vim.schedule(function() + require "mappings" +end) diff --git a/nvchad/lua/autocmds.lua b/nvchad/lua/autocmds.lua new file mode 100644 index 0000000..d2db0bb --- /dev/null +++ b/nvchad/lua/autocmds.lua @@ -0,0 +1 @@ +require "nvchad.autocmds" diff --git a/nvchad/lua/chadrc.lua b/nvchad/lua/chadrc.lua new file mode 100644 index 0000000..bd014be --- /dev/null +++ b/nvchad/lua/chadrc.lua @@ -0,0 +1,31 @@ +-- This file needs to have same structure as nvconfig.lua +-- https://github.com/NvChad/ui/blob/v3.0/lua/nvconfig.lua +-- Please read that file to know all available options :( @type ChadrcConfig +local M = {} + +M.base46 = { + theme = "solarized_light", + + -- hl_override = { + -- Comment = { italic = true }, + -- ["@comment"] = { italic = true }, + -- }, +} + +M.nvdash = { load_on_startup = true } +M.ui = { + cmp = { + style = "atom_colored", + }, + tabufline = { + -- lazyload = true, + enabled = false, + }, + statusline = { + enabled = true, + separator_style = "arrow", + theme = "default", + }, +} + +return M diff --git a/nvchad/lua/configs/conform.lua b/nvchad/lua/configs/conform.lua new file mode 100644 index 0000000..dd5af91 --- /dev/null +++ b/nvchad/lua/configs/conform.lua @@ -0,0 +1,18 @@ +local options = { + formatters_by_ft = { + lua = { "stylua" }, + -- css = { "prettier" }, + -- html = { "prettier" }, + nix = { + "nixfmt", + lsp_format = "fallback", + }, + }, + format_on_save = { + -- These options will be passed to conform.format() + timeout_ms = 500, + lsp_fallback = true, + }, +} + +return options diff --git a/nvchad/lua/configs/idris2.lua b/nvchad/lua/configs/idris2.lua new file mode 100644 index 0000000..8504e40 --- /dev/null +++ b/nvchad/lua/configs/idris2.lua @@ -0,0 +1,8 @@ +local options = {} + +options = { + default_regexp_syntax = true, + use_default_semantic_hl_groups = true +} + +return options diff --git a/nvchad/lua/configs/lazy.lua b/nvchad/lua/configs/lazy.lua new file mode 100644 index 0000000..e3b15c2 --- /dev/null +++ b/nvchad/lua/configs/lazy.lua @@ -0,0 +1,45 @@ +return { + defaults = { lazy = true }, + install = { colorscheme = { "nvchad" } }, + ui = { + icons = { + ft = "", + lazy = "󰂠 ", + loaded = "", + not_loaded = "", + }, + }, + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/nvchad/lua/configs/lspconfig.lua b/nvchad/lua/configs/lspconfig.lua new file mode 100644 index 0000000..5d5b69d --- /dev/null +++ b/nvchad/lua/configs/lspconfig.lua @@ -0,0 +1,16 @@ +require("nvchad.configs.lspconfig").defaults() + +local servers = { + "rust_analyzer", + "nixd", + "nil_ls", + "lua_ls", + "jsonls", + "taplo" +} +vim.lsp.enable(servers, true) + +local lua_ls_libraries = vim.deepcopy(vim.lsp.config.lua_ls.settings.Lua.workspace.library) +table.insert(lua_ls_libraries, + #lua_ls_libraries, vim.fn.stdpath "data" .. "/lazy/NvChad/lua/nvchad") +vim.lsp.config.lua_ls.settings.Lua.workspace.library = lua_ls_libraries diff --git a/nvchad/lua/mappings.lua b/nvchad/lua/mappings.lua new file mode 100644 index 0000000..689ea47 --- /dev/null +++ b/nvchad/lua/mappings.lua @@ -0,0 +1,29 @@ +require "nvchad.mappings" + +local map = vim.keymap.set + +map("n", "", ":", { desc = "CMD enter command mode" }) +map("n", "ti", function() + local is_enabled = vim.lsp.inlay_hint.is_enabled() + if is_enabled then + vim.lsp.inlay_hint.enable(false) + else + vim.lsp.inlay_hint.enable(true) + end +end, { desc = "Toggle lsp inlay hint" }) + +map({ "n", "v" }, "j", "gj") +map({ "n", "v" }, "k", "gk") +map({ "n", "v" }, "gj", "j") +map({ "n", "v" }, "gk", "k") +map({ "n", "v" }, "", "Telescope help_tags", { desc = "telescope help page" }) +map("i", "", "", { desc = "backspace" }) +map({ "n", "v" }, "tm", function() + local image_api = require("image") + local is_enabled = image_api.is_enabled() + if is_enabled then + image_api.disable() + else + image_api.enable() + end +end, { desc = "Toggle image.nvim" }) diff --git a/nvchad/lua/options.lua b/nvchad/lua/options.lua new file mode 100644 index 0000000..e99d7d3 --- /dev/null +++ b/nvchad/lua/options.lua @@ -0,0 +1,102 @@ +require "nvchad.options" + +local o = vim.o +local opt = vim.opt + +o.autoindent = true +o.autoread = true +opt.backspace = { + "indent", + "eol", + "start", +} +o.backup = false + +opt.breakindent = true +opt.breakindentopt = { "sbr" } +o.showbreak = "↪" + +o.cdhome = true +o.cmdheight = 1 +opt.completeopt = { + "fuzzy", + "menuone", + "noselect", + "popup", +} +opt.concealcursor = { ["v"] = true } +o.confirm = true +o.cursorline = true +opt.cursorlineopt = { "number", "screenline" } +opt.diffopt = { + "algorithm:minimal", + "closeoff", + "context:20", + "followwrap", + "internal", + "linematch:40", +} +o.errorbells = true +o.expandtab = true +o.exrc = true +o.foldcolumn = "auto" +o.fsync = true +o.gdefault = false +opt.helplang = { + "zh", + "en", +} +o.history = 10000 +o.hlsearch = true + +o.ignorecase = true +o.smartcase = true + +o.inccommand = "split" +o.list = true +opt.listchars = { + tab = "--→", + trail = "·", + multispace = " ", + nbsp = "⍽", + space = "·", +} +o.magic = true +o.more = true +o.mouse = "a" + +o.number = true +o.numberwidth = 4 +o.relativenumber = true + +o.scrollback = 100000 +o.scrolloff = 5 +o.shiftround = true +o.shiftwidth = 2 +o.showmode = false +o.signcolumn = "yes" +o.smoothscroll = true +o.splitbelow = true +o.splitright = true +o.startofline = true +o.swapfile = false +opt.tabclose = { + "uselast", +} +o.tabstop = 2 +o.termguicolors = true +o.undofile = true +o.undolevels = 100000 +opt.virtualedit = { + "block", + "onemore", +} +opt.whichwrap = { b = true, s = true, ["<"] = true, [">"] = true } +o.wildmenu = true +opt.wildmode = { "full" } +opt.wildoptions = { + "fuzzy", + "pum", +} +o.winborder = "solid" +o.wrap = true diff --git a/nvchad/lua/plugins/init.lua b/nvchad/lua/plugins/init.lua new file mode 100644 index 0000000..60c51b2 --- /dev/null +++ b/nvchad/lua/plugins/init.lua @@ -0,0 +1,56 @@ +return { + { + "stevearc/conform.nvim", + event = "BufWritePre", -- uncomment for format on save + opts = require "configs.conform", + }, + { + "neovim/nvim-lspconfig", + config = function() + require "configs.lspconfig" + end, + }, + { import = "nvchad.blink.lazyspec" }, + { + "nvim-treesitter/nvim-treesitter", + opts = { + ensure_installed = { + "markdown", + "typst", + "lua", + "toml", + "yaml", + "json", + "rust" + }, + }, + }, + { + "idris-community/idris2-nvim", + dependencies = { + "neovim/nvim-lspconfig", + "MunifTanjim/nui.nvim" + }, + main = "idris2", + opts = require("configs.idris2"), + ft = { "idris2", "ipkg", "lidris2" } + }, + { + "3rd/image.nvim", + opts = { + processor = "magick_cli", + integrations = { + markdown = { + only_render_image_at_cursor = true, + only_render_image_at_cursor_mode = "popup", + }, + } + }, + ft = { "markdown", "typst" } + }, + { + "mrcjkb/rustaceanvim", + version = "^6", + lazy = false, + }, +}