Skip to content

Commit

Permalink
added support for home manager module syntax for plugins (#27)
Browse files Browse the repository at this point in the history
ran nix flake update
  • Loading branch information
BirdeeHub committed Jun 19, 2024
1 parent fc0aa77 commit cd8e419
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 61 deletions.
25 changes: 4 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
url = "github:m-demare/hlargs.nvim";
flake = false;
};
"plugins-nvim-nio" = {
url = "github:nvim-neotest/nvim-nio";
flake = false;
};

# neovim-nightly-overlay = {
# url = "github:nix-community/neovim-nightly-overlay";
Expand Down Expand Up @@ -118,7 +114,7 @@
# This is for plugins that will load at startup without using packadd:
startupPlugins = {
debug = with pkgs.vimPlugins; [
pkgs.neovimPlugins.nvim-nio
nvim-nio
nvim-dap
nvim-dap-ui
nvim-dap-virtual-text
Expand Down
4 changes: 2 additions & 2 deletions nix/builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let
# the source says:
/* the function you would have passed to python.withPackages */
# So you put in a set of categories of lists of them.
extraPythonPackages = {};
# extraPythonPackages = {};
extraPython3Packages = {};
extraPython3wrapperArgs = {};
# same thing except for lua.withPackages
Expand Down Expand Up @@ -275,7 +275,7 @@ in
};
};
/* the function you would have passed to python.withPackages */
extraPythonPackages = combineCatsOfFuncs extraPythonPackages;
# extraPythonPackages = combineCatsOfFuncs extraPythonPackages;
/* the function you would have passed to python.withPackages */
withPython3 = settings.withPython3;
extraPython3Packages = combineCatsOfFuncs extraPython3Packages;
Expand Down
68 changes: 36 additions & 32 deletions nix/builder/wrapNeovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rec {
legacyWrapper = pkgs: neovim: {
extraMakeWrapperArgs ? ""
/* the function you would have passed to python.withPackages */
, extraPythonPackages ? (_: [])
# , extraPythonPackages ? (_: [])
/* the function you would have passed to python.withPackages */
, withPython3 ? true, extraPython3Packages ? (_: [])
/* the function you would have passed to lua.withPackages */
Expand All @@ -26,10 +26,40 @@ rec {
, extraPython3wrapperArgs ? []
}:
let
# although I removed an error that doesnt make sense for my flake.
plugins = pkgs.lib.flatten (pkgs.lib.mapAttrsToList genPlugin (configure.packages or {}));
# and made it be able to include configs to be ran BEFORE customRC is loaded.
genPlugin = packageName: {start ? [], opt ? []}:
plugins = pkgs.lib.flatten (pkgs.lib.mapAttrsToList genPluginList (configure.packages or {}));

# can parse programs.neovim plugin syntax for both nixos and home module, in addition to just a derivation.
# or even another one with config.lua or config.vim
parsepluginspec = opt: p: let
optional = if p ? optional && builtins.isBool p.optional then p.optional else opt;

attrsyn = p ? plugin && p ? config && builtins.isAttrs p.config;
hmsyn = p ? plugin && p ? config && ! builtins.isAttrs p.config && p ? type;
nixossyn = p ? plugin && p ? config && ! builtins.isAttrs p.config && ! p ? type;

type = if ! p ? config then null else if nixossyn then "viml" else if hmsyn then p.type
else if attrsyn then
if p.config ? lua then "lua"
else if p.config ? vim then "viml"
else null
else null;
in
(if nixossyn || hmsyn || attrsyn
then (p // { config = let
lua = if type == "lua" then ''
lua << EOF
${if attrsyn then p.config.lua else p.config}
EOF
'' else "";
vim = if type == "viml" then
if attrsyn then p.config.vim else p.config
else "";
in
(vim + "\n" + lua); inherit optional; })
else if p ? plugin then p // { inherit optional; }
else { plugin = p; inherit optional; });

genPluginList = packageName: {start ? [], opt ? []}:
[ {
plugin = pkgs.stdenv.mkDerivation {
name = "empty-derivation";
Expand All @@ -40,32 +70,7 @@ rec {
};
config = runB4Config;
optional = false;
} ] ++
(map (p:
if builtins.isAttrs p && (p ? config.lua || p ? config.vim) && p ? plugin
then (p // { config = let
lua = if p ? config.lua then ''
lua << EOF
${p.config.lua}
EOF
'' else "";
vim = if p ? config.vim then p.config.vim else "";
in
(vim + "\n" + lua); })
else p) start)
++
(map (p:
if builtins.isAttrs p && (p ? config.lua || p ? config.vim) && p ? plugin
then (p // { config = let
lua = if p ? config.lua then ''
lua << EOF
${p.config.lua}
EOF
'' else "";
vim = if p ? config.vim then p.config.vim else "";
in
(vim + "\n" + lua); optional = true; })
else (if p ? plugin then p else { plugin = p; optional = true; })) opt);
} ] ++ (map (parsepluginspec false) start) ++ (map (parsepluginspec true) opt);

res = pkgs.neovimUtils.makeNeovimConfig {
customRC = configure.customRC or "";
Expand All @@ -76,7 +81,6 @@ rec {
inherit extraName;
};
in
# it uses the new wrapper!!!
(pkgs.callPackage ./wrapper.nix {}) neovim (res // {
wrapperArgs = pkgs.lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs;
# I handle this with customRC
Expand Down
11 changes: 10 additions & 1 deletion nix/nixCatsHelp/nixCatsFlake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,16 @@ This applies in many situations. Take this one for example.
instead be defined within an attribute set that also contains config
to be ran before sourcing init.lua (nixCats, however is still accessible)
to do this, you may use the following syntax in opt or start sections: >nix
{ plugin = derivation; config.vim = ""; config.lua = ""; }
[
# you may add a plugin to a category list in any of these ways
{ plugin = derivation; config.vim = ""; config.lua = ""; }
{ plugin = derivation; config = ""; type = "<viml or lua>"; }
{ plugin = derivation; config = ""; } # defaults to viml
{ plugin = derivation; }
# all the above options can accept an optional = bool;
# to override its presence in either startupPlugins or optionalPlugins
derivation
]
<
---------------------------------------------------------------------------------------
Package Generation: *nixCats.flake.outputs.packageDefinitions*
Expand Down

0 comments on commit cd8e419

Please sign in to comment.