From 0dbe093453f6d0237c47400f1982096e233fde94 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Thu, 22 Feb 2024 22:48:54 +0100 Subject: [PATCH] feat: add flake.nix --- README.md | 13 ++++++++++ flake.nix | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 flake.nix diff --git a/README.md b/README.md index fdb3a94..c1988d2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ # nix-gen-luarc-json + Generate a .luarc.json for Lua/Neovim devShells +## Usage + +Apply this flake's overlay. +It provides a `mk-luarc-json` function, +which takes an attrset with the following arguments: + +- `nvim`: The neovim package. Defaults to `neovim-unwrapped`. +- `neodev-types`: neodev.nvim types to add to the `workspace.library`. + Defaults to `"stable"`. +- Plugins: List of Neovim plugins and/or luarocks packages. + Defaults to an empty list. + ## License This flake is [licensed according to GPL version 2](./LICENSE), diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8e4f72d --- /dev/null +++ b/flake.nix @@ -0,0 +1,77 @@ +{ + description = "Generate a .luarc.json for Lua/Neovim devShells"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs @ { + self, + nixpkgs, + flake-parts, + }: + flake-parts.lib.mkFlake {inherit inputs;} { + flake = { + overlays.default = final: prev: { + mk-luarc-json = { + # list of plugins that have a /lua directory + nvim ? final.neovim-unwrapped, + neodev-types ? "stable", + plugins ? [], + }: let + lib = final.lib; + plugin-lib-dirs = lib.lists.map (plugin: + if + builtins.hasAttr "vimPlugin" plugin + && plugin.vimPlugin + || plugin.pname == "nvim-treesitter" + then "${plugin}/lua" + else "${plugin}/lib/lua/5.1") + plugins; + luarc = { + runtime.version = "LuaJIT"; + Lua = { + globals = [ + "vim" + ]; + workspace = { + library = + [ + "${nvim}/share/nvim/runtime/lua" + "${final.vimPlugins.neodev-nvim}/types/${neodev-types}" + "\${3rd}/busted/library" + "\${3rd}/luassert/library" + ] + ++ plugin-lib-dirs; + ignoreDir = [ + ".git" + ".github" + ".direnv" + "result" + "nix" + "doc" + ]; + }; + diagnostics = { + libraryFiles = "Disable"; + disable = []; + }; + }; + }; + in + final.runCommand ".luarc.json" { + buildInputs = [ + final.jq + ]; + passAsFile = ["rawJSON"]; + rawJSON = builtins.toJSON luarc; + } '' + { + jq . <"$rawJSONPath" + } >$out + ''; + }; + }; + }; +}