diff --git a/.gitignore b/.gitignore index 8a9deba..4f5e3e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result log +.luarc.json diff --git a/flake.nix b/flake.nix index 146d0ce..c4cf7c2 100644 --- a/flake.nix +++ b/flake.nix @@ -109,9 +109,31 @@ packages = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + vim = import ./nvim (inputs + // { + inherit pkgs; + lib = nixpkgs.lib; + }); in rec { default = nvim; - nvim = import ./nvim (inputs // { inherit pkgs; lib = nixpkgs.lib; }); + nvim = vim.nvim; + }); + + devShells = eachSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + vim = import ./nvim (inputs + // { + inherit pkgs; + lib = nixpkgs.lib; + }); + in rec { + default = nvim-lua; + nvim-lua = pkgs.mkShell { + name = "nvim-lua"; + shellHook = '' + ln -fs ${vim.luarc} .luarc.json + ''; + }; }); }; } diff --git a/nvim/bytecompile.nix b/nvim/nix/bytecompile.nix similarity index 100% rename from nvim/bytecompile.nix rename to nvim/nix/bytecompile.nix diff --git a/nvim/nix/luarc.nix b/nvim/nix/luarc.nix new file mode 100644 index 0000000..88c0d2d --- /dev/null +++ b/nvim/nix/luarc.nix @@ -0,0 +1,69 @@ +{ + pkgs, + lib, + ... +}: { + nvim, + plugins ? { + start = []; + opt = []; + }, + meta ? {luvit = true;}, + lua-version ? "5.1", + disabled-diagnostics ? [], +}: let + # stolen from https://github.com/mrcjkb/nix-gen-luarc-json + pluginPackages = + map ( + x: + if x ? plugin + then x.plugin + else x + ) + (plugins.start ++ plugins.opt); + partitions = builtins.partition (plugin: + plugin.vimPlugin + or false + || plugin.pname or "" == "nvim-treesitter") + pluginPackages; + nvim-plugins = partitions.right; + rocks = partitions.wrong; + plugin-luadirs = builtins.map (plugin: "${plugin}/lua") nvim-plugins; + pkg-libdirs = builtins.map (pkg: "${pkg}/lib/lua/${lua-version}") rocks; + pkg-sharedirs = builtins.map (pkg: "${pkg}/share/lua/${lua-version}") rocks; + + luarc = { + "$schema" = "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json"; + runtime = { + version = "LuaJIT"; + }; + workspace = { + checkThirdParty = false; + library = + [ + "${nvim}/share/nvim/runtime/lua" + "$VIMRUNTIME/lua" + "\${3rd}/busted/library" + "\${3rd}/luassert/library" + ] + ++ plugin-luadirs + ++ pkg-libdirs + ++ pkg-sharedirs + ++ (lib.optional (meta.luvit or false) "${pkgs.vimPlugins.luvit-meta}/library"); + ignoreDir = [ + ".git" + ".github" + ".direnv" + "result" + "nix" + "doc" + ]; + }; + diagnostics = { + libraryFiles = "Disable"; + globals = ["vim"]; + disable = disabled-diagnostics; + }; + }; +in + (pkgs.formats.json {}).generate ".luarc.json" luarc diff --git a/nvim/mknvim.nix b/nvim/nix/mknvim.nix similarity index 87% rename from nvim/mknvim.nix rename to nvim/nix/mknvim.nix index 745e435..55517ae 100644 --- a/nvim/mknvim.nix +++ b/nvim/nix/mknvim.nix @@ -4,11 +4,12 @@ stdenv, ... }: { + name ? "nvim", package ? pkgs.neovim, config, plugins ? { start = []; - opts = []; + opt = []; }, extraPackages ? [], extraLuaPackages ? p: [], @@ -17,21 +18,19 @@ withPerl ? false, withRuby ? false, withNodeJs ? false, - withSqlite ? false, }: let builder = (import ./bytecompile.nix) {inherit pkgs lib;}; pack = (import ./pack.nix) {inherit pkgs lib;}; + mkLuarc = (import ./luarc.nix) {inherit pkgs lib;}; nvim = builder.byteCompileVim package; # TODO: only the (unused) init.lua seems to be byte compiled, idk why - conf = builder.byteCompileLuaDrv ( - (pkgs.runCommandLocal "nvim-config" {} '' - mkdir $out - cp -r ${config}/* $out - ls $out - '') - ); + conf = builder.byteCompileLuaDrv (pkgs.runCommandLocal "nvim-config" {} '' + mkdir $out + cp -r ${config}/* $out + ls $out + ''); pluginPack = let normalize = optional: p: let @@ -62,7 +61,7 @@ withDeps = p: [p] ++ builtins.concatMap withDeps (map (normalize false) (p.plugin.dependencies or [])); - plugs = (map (normalize false) plugins.start) ++ (map (normalize true) plugins.opts); + plugs = (map (normalize false) plugins.start) ++ (map (normalize true) plugins.opt); allPlugs = lib.unique (builtins.concatMap withDeps plugs); partitioned = builtins.partition (p: p.optional) (preparePlugins allPlugs); opt = map (p: p.plugin) partitioned.right; @@ -90,8 +89,8 @@ ${builtins.readFile (config + "/init.lua")} ''; -in - pkgs.wrapNeovimUnstable nvim { +in { + ${name} = pkgs.wrapNeovimUnstable nvim { wrapRc = false; wrapperArgs = builtins.concatStringsSep " " [ (lib.optionals (extraPackages != []) ''--prefix PATH : "${lib.makeBinPath extraPackages}"'') @@ -99,4 +98,7 @@ in ]; inherit withPython3 withNodeJs withPerl withRuby extraPython3Packages extraLuaPackages; - } + }; + + luarc = mkLuarc { nvim = package; inherit plugins; }; +} diff --git a/nvim/pack.nix b/nvim/nix/pack.nix similarity index 99% rename from nvim/pack.nix rename to nvim/nix/pack.nix index be88a32..eb48a00 100644 --- a/nvim/pack.nix +++ b/nvim/nix/pack.nix @@ -16,6 +16,7 @@ "/keymap" "/lang" "/lua" + "/lsp" "/pack" "/parser" "/plugin"