Compare commits

...

4 Commits

Author SHA1 Message Date
LordMZTE 101dbc7181
nvim plugin fixes 2024-04-14 18:33:55 +02:00
LordMZTE acf4abc8ba
mzte-nv: load plugins in chunked event loop callbacks
TODO: move into MZTE-NV with libUV idler
2024-04-14 16:55:23 +02:00
LordMZTE 73b009dd51
manage nvim plugins with nix 2024-04-14 16:09:11 +02:00
LordMZTE bbabdab552
various nix fixes + minecraft dev shell 2024-04-13 21:32:27 +02:00
25 changed files with 272 additions and 172 deletions

View File

@ -24,7 +24,10 @@ cg.onDone(function(errors)
end
end)
local nix = (loadfile "cgnix/nix.lua" or function() return {} end)()
local nix = (loadfile "nix/cgnix/nix.lua" or function()
print "no cgnix file!"
return {}
end)()
cg.opt.nix = nix

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; };
@ -17,8 +18,10 @@
root-mod = {
options.packages = nixpkgs.lib.mkOption { };
options.dev-shells = nixpkgs.lib.mkOption { };
config._module.args = {
inherit inputs;
inherit pkgs system;
inherit (pkgs) lib stdenv;
};
@ -32,44 +35,47 @@
(flakePkg "github:nix-community/zon2nix")
];
};
# devshell for the dotfiles
config.dev-shells.default = nixpkgs.legacyPackages.${system}.mkShell {
buildInputs = with pkgs;
[
# packages required to build scripts
libGL
libgit2
luajit
pkg-config
racket
roswell
wayland
wayland-protocols
haxe
mpv-unwrapped
] ++
# shorthands for setup.rkt
builtins.map
(cmd: pkgs.writeShellScriptBin cmd ''
./setup.rkt ${cmd}
'') [
"install-scripts"
"install-plugins"
"install-lsps-paru"
"setup-nvim-config"
"setup-nix"
"run-confgen"
];
};
};
modopt = nixpkgs.lib.evalModules {
modules = [ root-mod ./cgnix ] ++ common.localconf;
modules = [ root-mod ./nix ] ++ common.localconf;
specialArgs = { inherit common; };
};
in
{
config = modopt;
mzteinit = pkgs.callPackage ./scripts/mzteinit/package.nix { };
packages = modopt.config.packages;
devShells.default = nixpkgs.legacyPackages.${system}.mkShell {
buildInputs = with pkgs;
[
# packages required to build scripts
libGL
libgit2
luajit
pkg-config
racket
roswell
wayland
wayland-protocols
haxe
mpv-unwrapped
] ++
# shorthands for setup.rkt
builtins.map
(cmd: pkgs.writeShellScriptBin cmd ''
./setup.rkt ${cmd}
'') [
"install-scripts"
"install-plugins"
"install-lsps-paru"
"setup-nvim-config"
"setup-nix"
"run-confgen"
];
};
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

@ -7,16 +7,5 @@
:ignore false}
:renderer {:indent_markers {:enable true} :group_empty true}})
;; open on startup
(fn on-enter [data]
(local is-no-name (and (= data.file "") (= (. vim :bo data.buf :buftype) "")))
(local is-dir (= (vim.fn.isdirectory data.file) 1))
(when is-dir
(vim.cmd.cd data.file))
(when (or is-no-name is-dir)
((. (require :nvim-tree.api) :tree :open))))
(vim.api.nvim_create_autocmd [:VimEnter] {:callback on-enter})
(vim.keymap.set :n :TT #((. (require :nvim-tree.api) :tree :toggle))
(. (require :mzte_nv) :utils :map_opt))

View File

@ -34,7 +34,7 @@
(tset opt k v))
`(do
(nmap ,(.. :g suffix) ,action ,opt)
(nmap ,(.. :gt suffix) ,action
(nmap ,(.. :gn suffix) ,action
,(doto (collect [k v (pairs opt)] k v)
(tset :jump_type :tab)))
(nmap ,(.. :gs suffix) ,action

View File

@ -1,98 +1,62 @@
(vim.cmd "packadd packer.nvim")
(local mztenv (require :mzte_nv))
(local packer (require :packer))
(tset mztenv.reg :plugin_load_callbacks [])
(macro pconf [plugin]
`#(require ,(.. :pluginconf.p- plugin)))
(let [path mztenv.reg.nvim_plugins]
(when path
(vim.opt.runtimepath:prepend (.. path "/*"))
(vim.opt.runtimepath:append (.. path "/*/after"))))
(fn use/mztegit [plugin opts]
(let [url (.. "https://git.mzte.de/nvim-plugins/" plugin)
opt (or opts {})]
(tset opt 1 url)
(packer.use opt)))
;; Plugins to load before nvim finishes startup
(local startup-plugins [])
(macro use/pconf [plugin conf]
`(use/mztegit ,plugin {:config (pconf ,conf)}))
;; Plugins to load in the background
(local deferred-plugins [:lspconf
:cmp
:luasnip
:nullls
:catppuccin
:line
:treesitter
:nvimtree
:devicons
:neogit
:telescope
:autopairs
:tterm
:ts-context
:ufo
:aerial
:dap
:harpoon
:recorder
:noice
:tsn-actions
:lightbulb
:dressing])
(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))
(local errors {})
(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 load-plugin [plugin]
(let [(success ret) (pcall require (.. :pluginconf/p- plugin))]
(when (not success)
(tset errors p ret))))
(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))
(each [_ p (ipairs startup-plugins)]
(load-plugin p))
(packer.startup init)
(fn load-one-deferred [idx]
(let [plugin (. deferred-plugins idx)]
(if plugin
(do
(load-plugin plugin)
(vim.schedule #(load-one-deferred (+ idx 1))))
(do
(when (next errors)
(vim.notify (accumulate [text "Errors loading plugin configs:\n" plugin err (pairs errors)]
(.. text " - " plugin ": " err))
vim.log.levels.error))
(each [_ cb (ipairs mztenv.reg.plugin_load_callbacks)]
(pcall cb))))))
;; 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})
(vim.schedule #(load-one-deferred 1))

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
"20-lspconfig" = plugin "nvim-lspconfig";
"20-nullls" = plugin "null-ls.nvim";
"20-jdtls" = plugin "nvim-jdtls";
# CMP
"45-cmp" = plugin "nvim-cmp";
"50-cmp-nvim-lsp" = plugin "cmp-nvim-lsp";
"50-cmp-buffer" = plugin "cmp-buffer";
"50-cmp-path" = plugin "cmp-path";
"50-cmp-cmdline" = plugin "cmp-cmdline";
"50-cmp-luasnip" = plugin "cmp_luasnip";
"50-friendly-snippets" = plugin "friendly-snippets";
"50-luasnip" = plugin "LuaSnip";
"50-cmp-treesitter" = plugin "cmp-treesitter";
# Treesitter
"30-treesitter" = plugin "nvim-treesitter";
"30-autopairs" = plugin "nvim-autopairs";
"30-ts-autotag" = plugin "nvim-ts-autotag";
"30-ts-context" = plugin "nvim-treesitter-context";
"30-tsn-actions" = plugin "ts-node-action";
"30-ts-playground" = plugin "playground";
# Language Support
"30-fish" = plugin "vim-fish";
"30-wgsl" = plugin "wgsl.vim";
"30-nu" = plugin "nvim-nu";
"30-crafttweaker" = plugin "crafttweaker-vim-highlighting";
"30-vaxe" = plugin "vaxe";
# Misc
"50-catppuccin" = plugin "catppuccin";
"50-gitsigns" = plugin "gitsigns.nvim";
"50-lualine" = plugin "lualine.nvim";
"50-tree" = plugin "nvim-tree.lua";
"50-neogit" = fetchGit { url = "https://git.mzte.de/nvim-plugins/neogit.git?rev=nightly"; };
"50-telescope" = plugin "telescope.nvim";
"50-toggleterm" = plugin "toggleterm.nvim";
"50-notify" = plugin "nvim-notify";
"50-dressing" = plugin "dressing.nvim"; # TODO: remove once noice gets support for ui.select
"50-ufo" = plugin "nvim-ufo";
"50-aerial" = plugin "aerial.nvim";
"50-dap" = plugin "nvim-dap";
"50-dapui" = plugin "nvim-dap-ui";
"50-harpoon" = plugin "harpoon";
"50-recorder" = plugin "nvim-recorder";
"50-noice" = plugin "noice.nvim";
"50-lightbulb" = plugin "nvim-lightbulb";
# Libraries
"10-plenary" = plugin "plenary.nvim";
"10-devicons" = plugin "nvim-web-devicons";
"10-promise-async" = plugin "promise-async";
"10-nio" = plugin "nvim-nio";
"10-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
);
}

7
nix/default.nix Normal file
View File

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

37
nix/mcdev.nix Normal file
View File

@ -0,0 +1,37 @@
# A dev shell for Minecraft development, including necessary dependencies for the game to run.
{ pkgs, ... }:
let
libs = with pkgs; [
libpulseaudio
libGL
glfw
openal
stdenv.cc.cc.lib
udev # OSHI
];
xorg-libs = with pkgs.xorg; [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
];
in
{
dev-shells = builtins.mapAttrs
(_: extra-pkgs:
let
shpgks = libs ++ xorg-libs ++ extra-pkgs;
in
pkgs.mkShell {
shellHook = ''
export LD_LIBRARY_PATH="${pkgs.addOpenGLRunpath.driverLink}/lib:${pkgs.lib.makeLibraryPath shpgks}:$LD_LIBRARY_PATH"
'';
buildInputs = shpgks;
})
{
mcdev = [ pkgs.jdk8 ];
mcdev-new = [ pkgs.jdk17 ];
};
}

View File

@ -19,22 +19,24 @@ pub fn main() !u8 {
var env = try std.process.getEnvMap(alloc);
defer env.deinit();
const jvm_basepath = opts.jvm orelse "/usr/lib/jvm";
if (env.getPtr("PATH")) |path_p| {
const newpath = try std.fmt.allocPrint(
alloc,
(opts.jvm orelse "/usr/lib/jvm") ++ "/{s}/bin:{s}",
jvm_basepath ++ "/{s}/bin:{s}",
.{ std.os.argv[1], path_p.* },
);
alloc.free(path_p.*);
path_p.* = newpath;
} else {
const newpath = try std.fmt.allocPrint(alloc, "/usr/lib/jvm/{s}/bin", .{std.os.argv[1]});
const newpath = try std.fmt.allocPrint(alloc, jvm_basepath ++ "/{s}/bin", .{std.os.argv[1]});
errdefer alloc.free(newpath);
try env.putMove(try alloc.dupe(u8, "PATH"), newpath);
}
{
const java_home = try std.fmt.allocPrint(alloc, "/usr/lib/jvm/{s}", .{std.os.argv[1]});
const java_home = try std.fmt.allocPrint(alloc, jvm_basepath ++ "/{s}", .{std.os.argv[1]});
errdefer alloc.free(java_home);
try env.putMove(try alloc.dupe(u8, "JAVA_HOME"), java_home);
}

View File

@ -5,4 +5,4 @@
(define (run)
(define out (build-path (find-system-path 'home-dir) ".local" "mzte-nix"))
(cmd "nix" "build" ".#mzte-nix" "--impure" "--out-link" out)
(cmd "nix" "build" ".#cgnix" "--impure" "--out-link" "cgnix/nix.lua"))
(cmd "nix" "build" ".#cgnix" "--impure" "--out-link" "nix/cgnix/nix.lua"))