manage nvim plugins with nix

This commit is contained in:
LordMZTE 2024-04-14 16:09:11 +02:00
parent bbabdab552
commit 73b009dd51
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
14 changed files with 171 additions and 133 deletions

View File

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1711703276,
"narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=",
"lastModified": 1712791164,
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "d8fe5e6c92d0d190646fb9f1056741a229980089",
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5",
"type": "github"
},
"original": {

View File

@ -8,7 +8,8 @@
{ self
, nixpkgs
, utils
}: utils.lib.eachDefaultSystem
, ...
}@inputs: utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
@ -20,6 +21,7 @@
options.dev-shells = nixpkgs.lib.mkOption { };
config._module.args = {
inherit inputs;
inherit pkgs system;
inherit (pkgs) lib stdenv;
};
@ -71,6 +73,7 @@
};
in
{
config = modopt;
mzteinit = pkgs.callPackage ./scripts/mzteinit/package.nix { };
packages = modopt.config.packages;
devShells = modopt.config.dev-shells;

View File

@ -22,6 +22,7 @@ pub fn build(b: *std.Build) !void {
const cg_opt = try common.confgenGet(struct {
term_font: []u8, // TODO: this being non-const is a workaround for an std bug
nix: struct {
nvim_plugins: ?[:0]u8 = null,
tree_sitter_parsers: ?[:0]u8 = null,
nvim_tools: ?[:0]u8 = null,
jvm: ?[:0]u8 = null,
@ -31,6 +32,7 @@ pub fn build(b: *std.Build) !void {
const opts = b.addOptions();
opts.addOption([]const u8, "font", cg_opt.term_font);
opts.addOption(?[:0]const u8, "nvim_plugins", cg_opt.nix.nvim_plugins);
opts.addOption(?[:0]const u8, "tree_sitter_parsers", cg_opt.nix.tree_sitter_parsers);
opts.addOption(?[:0]const u8, "nvim_tools", cg_opt.nix.nvim_tools);
opts.addOption(?[:0]const u8, "jvm", cg_opt.nix.jvm);

View File

@ -30,10 +30,7 @@
(nmap :<C-k> vim.lsp.buf.signature_help)
(nmap :<space>e vim.diagnostic.open_float)
(nmap :K (fn []
(if ((. (require :conjure.client) :get))
((. (require :conjure.eval) :doc-word))
(vim.lsp.buf.hover))))
(nmap :K vim.lsp.buf.hover)
;; command to stop LSPs
(vim.api.nvim_create_user_command :StopLsps

View File

@ -2,7 +2,6 @@
(values (require :cmp) (require :luasnip) (require :mzte_nv)))
(local sources {:buffer " "
:conjure " "
:crates " "
:luasnip " "
:nvim_lsp " "

View File

@ -1,23 +0,0 @@
;; Blame conjure for this BS config
;; NOTE: this is ran before conjure initialization
;; Disable auto-attach
(tset vim :g "conjure#client_on_load" false)
(tset vim :g "conjure#mapping#prefix" :<F1>)
;; Only enable used clients
(tset vim :g "conjure#filetypes" [:clojure
:commonlisp
:fennel
:scheme
:lua
:lisp
:python])
(tset vim :g "conjure#filetype#rust" false)
(tset vim :g "conjure#filetype#racket" false)
(tset vim :g "conjure#filetype#commonlisp" "conjure.client.common-lisp.swank")
;; This has custom handling for compat with LSP
(tset vim :g "conjure#mapping#doc_word" false)

View File

@ -0,0 +1,4 @@
(local dressing (require :dressing))
(dressing.setup {;; Provided by noice
:input {:enabled false}})

View File

@ -10,8 +10,8 @@ local t = ls.text_node
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep
require("luasnip.loaders.from_vscode").load()
require("luasnip.loaders.from_snipmate").load()
require("luasnip.loaders.from_vscode").lazy_load()
require("luasnip.loaders.from_snipmate").lazy_load()
ls.add_snippets("markdown", {
s("shrug", {

View File

@ -1,98 +1,38 @@
(vim.cmd "packadd packer.nvim")
(local mztenv (require :mzte_nv))
(local packer (require :packer))
(let [path mztenv.reg.nvim_plugins]
(when path
(vim.opt.runtimepath:append (.. path "/*"))))
(macro pconf [plugin]
`#(require ,(.. :pluginconf.p- plugin)))
(fn use/mztegit [plugin opts]
(let [url (.. "https://git.mzte.de/nvim-plugins/" plugin)
opt (or opts {})]
(tset opt 1 url)
(packer.use opt)))
(macro use/pconf [plugin conf]
`(use/mztegit ,plugin {:config (pconf ,conf)}))
(macro use/pconf [plugin conf extra]
(var c {:config `(pconf ,conf)})
(each [k v (pairs (or extra {}))]
(tset c k v))
`(use/mztegit ,plugin ,c))
(fn cmp-plugins []
(use/pconf :nvim-lspconfig :lspconf)
(use/pconf :nvim-cmp :cmp)
(use/mztegit :cmp-nvim-lsp)
(use/mztegit :cmp-buffer)
(use/mztegit :cmp-path)
(use/mztegit :cmp-cmdline)
(use/mztegit :cmp_luasnip)
(use/mztegit :friendly-snippets)
(use/pconf :LuaSnip :luasnip)
(use/mztegit :crates.nvim {:config #((. (require :crates) :setup) {})})
(use/mztegit :cmp-treesitter)
(use/pconf :null-ls.nvim :nullls)
(use/mztegit :nvim-nu
{:config #((. (require :nu) :setup) {:complete_cmd_names true})})
(use/mztegit :cmp-conjure))
(fn init []
(use/mztegit :packer.nvim)
(use/mztegit :plenary.nvim)
(use/pconf :catppuccin :catppuccin)
(use/mztegit :gitsigns.nvim {:config #((. (require :gitsigns) :setup) {})})
(use/mztegit :vim-fish)
(use/pconf :lualine.nvim :line {:after :catppuccin})
(use/pconf :nvim-treesitter :treesitter)
(use/pconf :nvim-web-devicons :devicons)
(use/pconf :nvim-tree.lua :nvimtree)
(use/pconf :neogit :neogit)
(use/pconf :telescope.nvim :telescope)
(use/pconf :nvim-autopairs :autopairs)
(use/mztegit :nvim-ts-autotag)
(use/mztegit :rainbow-delimiters.nvim)
(use/pconf :toggleterm.nvim :tterm)
(use/mztegit :wgsl.vim)
(use/mztegit :nvim-notify)
;; TODO: remove once noice gets support for ui.select
(use/mztegit :dressing.nvim
{:config #((. (require :dressing) :setup) {:input ;; Provided by noice
{:enabled false}})})
(use/pconf :nvim-treesitter-context :ts-context)
(use/mztegit :crafttweaker-vim-highlighting)
(use/mztegit :nvim-jdtls)
(use/mztegit :promise-async)
(use/pconf :nvim-ufo :ufo {:after :nvim-lspconfig})
(use/pconf :aerial.nvim :aerial)
(use/mztegit :nvim-nio) ;; dep of dap-ui
(use/mztegit :nvim-dap-ui)
(use/pconf :nvim-dap :dap)
(use/pconf :harpoon :harpoon)
(use/pconf :nvim-recorder :recorder)
(use/mztegit :nui.nvim)
(use/pconf :noice.nvim :noice)
(use/mztegit :vaxe)
(use/pconf :ts-node-action :tsn-actions)
(use/mztegit :playground)
(use/mztegit :conjure {:setup (pconf :conjure)})
(use/pconf :nvim-lightbulb :lightbulb)
(cmp-plugins))
(packer.startup init)
;; PackerCompile automagically
(when (= 0 (length (vim.api.nvim_get_runtime_file :plugin/packer_compiled.lua
false)))
(packer.compile))
;; actually compile packer-generated config after packer's "compile" step
(fn compile-packer-generated []
(let [mztenv (require :mzte_nv)
packer (require :packer)]
(mztenv.compile.compilePath packer.config.compile_path)))
(vim.api.nvim_create_autocmd :User
{:pattern :PackerCompileDone
:once true
:callback compile-packer-generated})
(let [plugins [:lspconf
:cmp
:luasnip
:nullls
:catppuccin
:line
:treesitter
:devicons
:nvimtree
:neogit
:telescope
:autopairs
:tterm
:ts-context
:ufo
:aerial
:dap
:harpoon
:recorder
:noice
:tsn-actions
:lightbulb
:dressing]
errors {}]
(each [_ p (ipairs plugins)]
(let [(success ret) (pcall require (.. :pluginconf/p- p))]
(when (not success)
(tset errors p ret))))
(when (next errors)
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err))
vim.log.levels.error)))

View File

@ -105,7 +105,7 @@ fn lOnInit(l: *c.lua_State) !c_int {
c.lua_getfield(l, c.LUA_REGISTRYINDEX, reg_key);
defer c.lua_pop(l, 1);
inline for (.{ "tree_sitter_parsers", "nvim_tools" }) |fname| {
inline for (.{ "nvim_plugins", "tree_sitter_parsers", "nvim_tools" }) |fname| {
if (@field(opts, fname)) |x| {
ffi.luaPushString(l, x);
c.lua_setfield(l, -2, fname);

View File

@ -48,7 +48,11 @@ fn lPathTransformerClosure(l: *c.lua_State) !c_int {
fn transformJdtlsURI(uri_str: []const u8, writer: anytype) !void {
// We do a full-on URI parse here because JDTLS often appends parameters and other garbage data.
const uri = try std.Uri.parse(uri_str);
var fname_iter = std.fs.path.ComponentIterator(.posix, u8).init(uri.path) catch
var fname_iter = std.fs.path.ComponentIterator(.posix, u8).init(
switch (uri.path) {
inline else => |s| s,
},
) catch
unreachable; // this can only error on windows lol
_ = fname_iter.next() orelse return error.InvalidPath; // name of the JAR

View File

@ -6,6 +6,7 @@
{
imports = [
./jvm.nix
./nvim-plugins.nix
./nvim-tools.nix
./tree-sitter-parsers.nix
];

108
nix/cgnix/nvim-plugins.nix Normal file
View File

@ -0,0 +1,108 @@
{ config, pkgs, lib, stdenv, ... }:
let
plugin = name: fetchGit { url = "https://git.mzte.de/nvim-plugins/${name}.git"; };
plugins = {
# LSP
lspconfig = plugin "nvim-lspconfig";
nullls = plugin "null-ls.nvim";
jdtls = plugin "nvim-jdtls";
# CMP
cmp = plugin "nvim-cmp";
cmp-nvim-lsp = plugin "cmp-nvim-lsp";
cmp-buffer = plugin "cmp-buffer";
cmp-path = plugin "cmp-path";
cmp-cmdline = plugin "cmp-cmdline";
cmp-luasnip = plugin "cmp_luasnip";
friendly-snippets = plugin "friendly-snippets";
luasnip = plugin "LuaSnip";
cmp-treesitter = plugin "cmp-treesitter";
# Treesitter
treesitter = plugin "nvim-treesitter";
autopairs = plugin "nvim-autopairs";
ts-autotag = plugin "nvim-ts-autotag";
ts-context = plugin "nvim-treesitter-context";
tsn-actions = plugin "ts-node-action";
ts-playground = plugin "playground";
# Language Support
fish = plugin "vim-fish";
wgsl = plugin "wgsl.vim";
nu = plugin "nvim-nu";
crafttweaker = plugin "crafttweaker-vim-highlighting";
vaxe = plugin "vaxe";
# Misc
catppuccin = plugin "catppuccin";
gitsigns = plugin "gitsigns.nvim";
lualine = plugin "lualine.nvim";
tree = plugin "nvim-tree.lua";
neogit = fetchGit { url = "https://git.mzte.de/nvim-plugins/neogit.git?rev=nightly"; };
telescope = plugin "telescope.nvim";
toggleterm = plugin "toggleterm.nvim";
notify = plugin "nvim-notify";
dressing = plugin "dressing.nvim"; # TODO: remove once noice gets support for ui.select
ufo = plugin "nvim-ufo";
aerial = plugin "aerial.nvim";
dap = plugin "nvim-dap";
dapui = plugin "nvim-dap-ui";
harpoon = plugin "harpoon";
recorder = plugin "nvim-recorder";
noice = plugin "noice.nvim";
lightbulb = plugin "nvim-lightbulb";
# Libraries
plenary = plugin "plenary.nvim";
devicons = plugin "nvim-web-devicons";
promise-async = plugin "promise-async";
nio = plugin "nvim-nio";
nui = plugin "nui.nvim";
};
mzte-nv-compiler =
let
path = "${builtins.getEnv "HOME"}/.local/bin/mzte-nv-compile";
in
if (builtins.pathExists path) then
# This derivation exists to patch a potentially mismatched dynamic linker.
stdenv.mkDerivation
{
name = "mzte-nv-compiler-patched";
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
buildInputs = with pkgs; [ luajit ];
dontUnpack = true;
buildPhase = ''
cp ${/. + path} $out
'';
} else "";
in
{
options.cgnix.nvim-plugins = lib.mkOption { };
config.cgnix.nvim-plugins = plugins;
config.cgnix.entries.nvim_plugins = pkgs.linkFarm "nvim-plugins"
(lib.mapAttrsToList
(name: src: {
name = name;
path = stdenv.mkDerivation {
name = "${name}-compiled";
inherit src;
nativeBuildInputs = with pkgs; [ luajit luajitPackages.fennel ];
buildPhase = ''
# Compile source with mzte-nv-compile
${if mzte-nv-compiler != "" then "${mzte-nv-compiler} ." else ""}
'';
installPhase = ''
mkdir -p "$out"
mv * .* "$out"
'';
};
})
config.cgnix.nvim-plugins
);
}

View File

@ -1,4 +1,7 @@
{ ... }:
{
imports = [ ./cgnix ./mcdev.nix ];
imports = [
./cgnix
./mcdev.nix
];
}