diff --git a/.config/fish/conf.d/50-exa-ls.fish b/.config/fish/conf.d/50-exa-ls.fish deleted file mode 100644 index e975c66..0000000 --- a/.config/fish/conf.d/50-exa-ls.fish +++ /dev/null @@ -1,5 +0,0 @@ -# Alias ls to use exa -alias ls="exa --icons --group-directories-first --classify --octal-permissions" -alias ll="ls -l" -alias la="ll -a" -alias lt="ll --tree" diff --git a/.config/fish/conf.d/50-eza-ls.fish.cgt b/.config/fish/conf.d/50-eza-ls.fish.cgt new file mode 100644 index 0000000..b15d601 --- /dev/null +++ b/.config/fish/conf.d/50-eza-ls.fish.cgt @@ -0,0 +1,7 @@ +# Alias ls to use exa + +alias ls "<% base_cmd %>" +alias ll "<% base_cmd %> --long" +alias la "<% base_cmd %> --long --all" +alias lt "<% base_cmd %> --long --tree" +alias lta "<% base_cmd %> --long --all --tree" diff --git a/cgnix/.gitignore b/cgnix/.gitignore new file mode 100644 index 0000000..90d74f9 --- /dev/null +++ b/cgnix/.gitignore @@ -0,0 +1 @@ +nix.lua diff --git a/cgnix/README.md b/cgnix/README.md new file mode 100644 index 0000000..941b4e2 --- /dev/null +++ b/cgnix/README.md @@ -0,0 +1,2 @@ +# cgnix +This nix module acts as a shim between my confgen environment and nix. It's ultimately one single derivation which is a Lua file that declares paths into the nix store. These can then be used by confgen and thus by my scripts. diff --git a/cgnix/default.nix b/cgnix/default.nix new file mode 100644 index 0000000..7867963 --- /dev/null +++ b/cgnix/default.nix @@ -0,0 +1,23 @@ +{ config +, lib +, pkgs +, ... +}: +{ + imports = [ ./nvim-tools.nix ./tree-sitter-parsers.nix ]; + + options.cgnix.entries = lib.mkOption { + default = { }; + }; + + config.cgnix.entries."fennel.lua" = "${pkgs.luajitPackages.fennel}/share/lua/5.1/fennel.lua"; + + config.packages.cgnix = pkgs.writeTextFile { + name = "nix.lua"; + text = '' + return { + ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: ''["${k}"] = "${v}",'') config.cgnix.entries)} + } + ''; + }; +} diff --git a/cgnix/nvim-tools.nix b/cgnix/nvim-tools.nix new file mode 100644 index 0000000..26df46c --- /dev/null +++ b/cgnix/nvim-tools.nix @@ -0,0 +1,36 @@ +{ lib, pkgs, system, config, ... }: +let + flakePkg = ref: (builtins.getFlake ref).packages.${system}.default; + default-packages = with pkgs; [ + # MISSING: glsl_analyzer, haxe_language_server, prosemd_lsp, racket_langserver, yamlls, zls + # Language Servers + (flakePkg "github:oxalica/nil") + (pkgs.linkFarm "clangd" [{ name = "bin/clangd"; path = "${clang-tools}/bin/clangd"; }]) # only clangd + elixir-ls + jdt-language-server + lua-language-server + ocamlPackages.ocaml-lsp + openscad-lsp + taplo + vscode-langservers-extracted # cssls, eslint, html, jsonls + + # Formatters + (pkgs.linkFarm "prettier" [{ name = "bin/prettier"; path = "${nodePackages.prettier}/bin/prettier"; }]) # needed due to symlink shenanigans + fnlfmt + nixpkgs-fmt + + # Misc + html-tidy + shellcheck + ]; +in +{ + options.cgnix.nvim-tools = lib.mkOption { + default = default-packages; + }; + + config.cgnix.entries.nvim_tools = pkgs.symlinkJoin { + name = "nvim-tools"; + paths = config.cgnix.nvim-tools; + }; +} diff --git a/cgnix/tree-sitter-parsers.nix b/cgnix/tree-sitter-parsers.nix new file mode 100644 index 0000000..5b3b25b --- /dev/null +++ b/cgnix/tree-sitter-parsers.nix @@ -0,0 +1,19 @@ +# This uses Nix to manage tree-sitter parsers for neovim, instead of nvim-treesitter's weird installer. +{ lib, pkgs, ... }: +let + mapParsers = pkg: + let + parsername = lib.removeSuffix "-grammar" pkg.pname; + in + { + # Parser + name = "parser/${parsername}.so"; + path = "${pkg}/parser"; + }; +in +{ + cgnix.entries.tree_sitter_parsers = pkgs.linkFarm + "tree-sitter-parsers" + (map mapParsers pkgs.vimPlugins.nvim-treesitter.allGrammars); +} + diff --git a/confgen.lua b/confgen.lua index 6ddf826..317d38b 100644 --- a/confgen.lua +++ b/confgen.lua @@ -24,7 +24,11 @@ cg.onDone(function(errors) end end) -local fennel = loadfile "/usr/share/lua/5.4/fennel.lua" () +local nix = (loadfile "cgnix/nix.lua" or function() return {} end)() + +cg.opt.nix = nix + +local fennel = (loadfile(nix["fennel.lua"] or"/usr/share/lua/5.4/fennel.lua") ()) -- Recursively merge 2 tables local function merge(a, b) diff --git a/flake.nix b/flake.nix index cffb570..a63df6e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,51 +8,68 @@ { self , nixpkgs , utils - }: utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - flakePkg = ref: (builtins.getFlake ref).packages.${system}.default; - in - { - mzteinit = pkgs.callPackage ./scripts/mzteinit/package.nix { }; - # Local user nix env - packages.mzte-nix = pkgs.symlinkJoin { - name = "mzte-nix"; - paths = [ - pkgs.nixpkgs-fmt - pkgs.nix-output-monitor - pkgs.nix-du - (flakePkg "github:oxalica/nil") - (flakePkg "github:nix-community/zon2nix") - ]; - }; + }: utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { inherit system; }; + common = pkgs.callPackage ./lib/common-nix { }; + flakePkg = ref: (builtins.getFlake ref).packages.${system}.default; - 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" - ]; - }; - }); + root-mod = { + options.packages = nixpkgs.lib.mkOption { }; + + config._module.args = { + inherit pkgs system; + inherit (pkgs) lib stdenv; + }; + + # Local user nix env + config.packages.mzte-nix = pkgs.symlinkJoin { + name = "mzte-nix"; + paths = [ + pkgs.nix-output-monitor + pkgs.nix-du + (flakePkg "github:nix-community/zon2nix") + ]; + }; + }; + + modopt = nixpkgs.lib.evalModules { + modules = [ root-mod ./cgnix ] ++ common.localconf; + specialArgs = { inherit common; }; + }; + in + { + 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" + ]; + }; + }); } diff --git a/lib/common-nix/default.nix b/lib/common-nix/default.nix new file mode 100644 index 0000000..53d4b87 --- /dev/null +++ b/lib/common-nix/default.nix @@ -0,0 +1,8 @@ +{ lib }: +{ + localconf = + let + path = "${builtins.getEnv "HOME"}/.config/mzte_localconf/opts.nix"; + in + lib.optional (builtins.pathExists path) (import path); +} diff --git a/mzte-nv/build.zig b/mzte-nv/build.zig index 3caef26..f3c2b48 100644 --- a/mzte-nv/build.zig +++ b/mzte-nv/build.zig @@ -21,10 +21,19 @@ 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 { + tree_sitter_parsers: ?[:0]u8 = null, + nvim_tools: ?[:0]u8 = null, + @"fennel.lua": ?[:0]u8 = null, + }, }, b.allocator); const opts = b.addOptions(); opts.addOption([]const u8, "font", cg_opt.term_font); + 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, "fennel.lua", cg_opt.nix.@"fennel.lua"); + lib.root_module.addImport("opts", opts.createModule()); lib.root_module.addImport("nvim", znvim_dep.module("nvim_c")); @@ -48,6 +57,7 @@ pub fn build(b: *std.Build) !void { compiler.linkLibC(); compiler.linkSystemLibrary("luajit"); + compiler.root_module.addImport("opts", opts.createModule()); compiler.root_module.addImport("common", b.dependency("common", .{}).module("common")); compiler.root_module.unwind_tables = true; diff --git a/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl b/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl index fce268b..4d255a2 100644 --- a/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl @@ -1,8 +1,14 @@ -(local (configs parsers ts-utils) - (values (require :nvim-treesitter.configs) +(local (mztenv configs parsers ts-utils) + (values (require :mzte_nv) + (require :nvim-treesitter.configs) (require :nvim-treesitter.parsers) (require :nvim-treesitter.ts_utils))) +;; Nix based parsers +(let [path mztenv.reg.tree_sitter_parsers] + (when path + (vim.opt.runtimepath:append path))) + (var parser-config (parsers.get_parser_configs)) (tset parser-config :haxe {:install_info {:url "https://github.com/vantreeseba/tree-sitter-haxe" diff --git a/mzte-nv/conf/lua/settings.fnl b/mzte-nv/conf/lua/settings.fnl index 6d22b76..99a15c0 100644 --- a/mzte-nv/conf/lua/settings.fnl +++ b/mzte-nv/conf/lua/settings.fnl @@ -1,6 +1,11 @@ (local mztenv (require :mzte_nv)) (local cmd vim.cmd) +;; Update $PATH with nvim tools path +(let [lsppath mztenv.reg.nvim_tools] + (when lsppath + (set vim.env.PATH (.. lsppath "/bin:" vim.env.PATH)))) + ;; CPBuf command (vim.api.nvim_create_user_command :CPBuf mztenv.cpbuf.copyBuf {:nargs 0}) diff --git a/mzte-nv/src/compiler.zig b/mzte-nv/src/compiler.zig index cd2c676..57e4832 100644 --- a/mzte-nv/src/compiler.zig +++ b/mzte-nv/src/compiler.zig @@ -1,4 +1,6 @@ const std = @import("std"); +const opts = @import("opts"); + const ffi = @import("ffi.zig"); const c = ffi.c; const ser = @import("ser.zig"); @@ -42,7 +44,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void { // fennel is made to run on lua 5.4, but ends up working with LJ too c.lua_getfield(l, c.LUA_GLOBALSINDEX, "package"); c.lua_getfield(l, -1, "path"); - ffi.luaPushString(l, ";" ++ "/usr/share/lua/5.4/fennel.lua"); + ffi.luaPushString(l, ";" ++ (opts.@"fennel.lua" orelse "/usr/share/lua/5.4/fennel.lua")); c.lua_concat(l, 2); c.lua_setfield(l, -2, "path"); c.lua_pop(l, 1); diff --git a/mzte-nv/src/main.zig b/mzte-nv/src/main.zig index 0cc7a75..52f6628 100644 --- a/mzte-nv/src/main.zig +++ b/mzte-nv/src/main.zig @@ -1,6 +1,8 @@ const std = @import("std"); const nvim = @import("nvim"); const znvim = @import("znvim"); +const opts = @import("opts"); + const ffi = @import("ffi.zig"); const ser = @import("ser.zig"); const c = ffi.c; @@ -99,9 +101,17 @@ export fn luaopen_mzte_nv(l_: ?*c.lua_State) c_int { } fn lOnInit(l: *c.lua_State) !c_int { - _ = l; try @import("options.zig").initOptions(); + c.lua_getfield(l, c.LUA_REGISTRYINDEX, reg_key); + defer c.lua_pop(l, 1); + inline for (.{ "tree_sitter_parsers", "nvim_tools" }) |fname| { + if (@field(opts, fname)) |x| { + ffi.luaPushString(l, x); + c.lua_setfield(l, -2, fname); + } + } + std.log.info( "MZTE-NV v{s} Initialized on {s}", .{ version, nvim.longVersion }, diff --git a/mzte-nv/src/modules/fennel.zig b/mzte-nv/src/modules/fennel.zig index edaf1d9..073da76 100644 --- a/mzte-nv/src/modules/fennel.zig +++ b/mzte-nv/src/modules/fennel.zig @@ -1,4 +1,6 @@ const std = @import("std"); +const opts = @import("opts"); + const ffi = @import("../ffi.zig"); const ser = @import("../ser.zig"); const c = ffi.c; @@ -21,7 +23,7 @@ fn loadFennel(l: *c.lua_State) !void { std.log.debug("loading fennel", .{}); - if (c.luaL_loadfile(l, "/usr/share/lua/5.4/fennel.lua") != 0) { + if (c.luaL_loadfile(l, opts.@"fennel.lua" orelse "/usr/share/lua/5.4/fennel.lua") != 0) { return error.FennelLoad; } diff --git a/setup.rkt b/setup.rkt index 3faf641..6d23082 100755 --- a/setup.rkt +++ b/setup.rkt @@ -12,7 +12,7 @@ (define verb (command-line #:program "setup.rkt" #:usage-help "Sets up my dotfiles. Available verbs:" - "install-scripts, install-plugins, install-lsps-paru, setup-nvim-config, run-confgen" + "install-scripts, install-plugins, setup-nix, setup-nvim-config, run-confgen" #:once-each [("-o" "--bin-output") o "Output directory for executables" (output-bin-path o)] #:args (verb) @@ -41,9 +41,6 @@ ['install-plugins (local-require "setup/commands/install-plugins.rkt") (run)] - ['install-lsps-paru - (local-require "setup/commands/install-lsps-paru.rkt") - (run)] ['setup-nvim-config (local-require "setup/commands/setup-nvim-config.rkt") (run)] diff --git a/setup/commands/install-lsps-paru.rkt b/setup/commands/install-lsps-paru.rkt deleted file mode 100644 index ff01a1e..0000000 --- a/setup/commands/install-lsps-paru.rkt +++ /dev/null @@ -1,31 +0,0 @@ -#lang racket -(require "../common.rkt") -(provide run) - -(define lsp-packages - (list "elixir-ls-git" - "eslint" - "jdtls" - "lua-language-server" - "shellcheck" - "shfmt" - "taplo-cli" - "tidy" - "vscode-langservers-extracted" - "yaml-language-server" - "zls-git")) - -(define (run) - (apply cmd "paru" "-S" "--needed" "--noconfirm" lsp-packages) - - ;; install OCaml LSP - (when (find-executable-path "opam") - (cmd "opam" "install" "--yes" "ocaml-lsp-server" "ocamlformat")) - - ;; Install CommonLisp LSP - ;; Also useful for CommonLisp: - ;; - `ros install koji-kojiro/cl-repl` - ;; - `ros install fukamachi/mondo` - (when (find-executable-path "ros") - (cmd "ros" "install" "lem-project/lem" "cxxxr/cl-lsp")) - null) diff --git a/setup/commands/setup-nix.rkt b/setup/commands/setup-nix.rkt index 5922386..821b926 100644 --- a/setup/commands/setup-nix.rkt +++ b/setup/commands/setup-nix.rkt @@ -4,4 +4,5 @@ (define (run) (define out (build-path (find-system-path 'home-dir) ".local" "mzte-nix")) - (cmd "nix" "build" ".#mzte-nix" "--impure" "--no-write-lock-file" "--out-link" out)) + (cmd "nix" "build" ".#mzte-nix" "--impure" "--out-link" out) + (cmd "nix" "build" ".#cgnix" "--impure" "--out-link" "cgnix/nix.lua"))