refac: use nixpkgs lib instead
This commit is contained in:
parent
6bbb562216
commit
53b281848b
6 changed files with 29 additions and 76 deletions
|
@ -208,7 +208,7 @@
|
||||||
buildPlugin = name: vimUtils.buildVimPlugin {
|
buildPlugin = name: vimUtils.buildVimPlugin {
|
||||||
name = name;
|
name = name;
|
||||||
src = getAttr name inputs;
|
src = getAttr name inputs;
|
||||||
patches = lib.optional
|
patches = lib.optionals
|
||||||
(pathExists ./patches/${name})
|
(pathExists ./patches/${name})
|
||||||
(map
|
(map
|
||||||
(patchName: ./patches/${name}/${patchName})
|
(patchName: ./patches/${name}/${patchName})
|
||||||
|
|
60
lib.nix
60
lib.nix
|
@ -1,65 +1,7 @@
|
||||||
{ lib, substituteAll, ... }:
|
{ lib, substituteAll, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) length elemAt isList isString hasAttr getAttr;
|
|
||||||
|
|
||||||
###########################################################################
|
|
||||||
# Helpers
|
|
||||||
|
|
||||||
# Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix
|
|
||||||
foldr = op: nul: list:
|
|
||||||
let
|
|
||||||
len = length list;
|
|
||||||
fold' = n:
|
|
||||||
if n == len
|
|
||||||
then nul
|
|
||||||
else op (elemAt list n) (fold' (n + 1));
|
|
||||||
in
|
|
||||||
fold' 0;
|
|
||||||
|
|
||||||
concatMap = op: list:
|
|
||||||
let
|
|
||||||
concat = (a: b: op a + b);
|
|
||||||
in
|
|
||||||
foldr concat "" list;
|
|
||||||
|
|
||||||
############################################################################
|
|
||||||
# Configs
|
|
||||||
|
|
||||||
optional = cond: val:
|
|
||||||
let
|
|
||||||
def =
|
|
||||||
if isList val then [ ]
|
|
||||||
else if isString val then ""
|
|
||||||
else null;
|
|
||||||
in
|
|
||||||
if cond then val else def;
|
|
||||||
|
|
||||||
getAttrOpt = a: s:
|
|
||||||
if hasAttr a s then getAttr a s else null;
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
# Lua
|
|
||||||
|
|
||||||
mkLuaHeredoc = content: ''
|
|
||||||
lua << EOF
|
|
||||||
${content}
|
|
||||||
EOF
|
|
||||||
'';
|
|
||||||
|
|
||||||
mkLuaRc = contents: concatMap mkLuaHeredoc contents;
|
|
||||||
|
|
||||||
############################################################################
|
|
||||||
# Configs
|
|
||||||
|
|
||||||
readSubFile = src: params: builtins.readFile
|
readSubFile = src: params: builtins.readFile
|
||||||
(substituteAll (params // { inherit src; }));
|
(substituteAll (params // { inherit src; }));
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
lib // { inherit readSubFile substituteAll; }
|
||||||
inherit (lib) importJSON attrByPath;
|
|
||||||
inherit foldr concatMap;
|
|
||||||
inherit optional getAttrOpt;
|
|
||||||
inherit mkLuaHeredoc mkLuaRc;
|
|
||||||
inherit readSubFile substituteAll;
|
|
||||||
}
|
|
||||||
|
|
16
neovim.nix
16
neovim.nix
|
@ -35,7 +35,7 @@ let
|
||||||
plugins = mergeAttrs plugins';
|
plugins = mergeAttrs plugins';
|
||||||
inherit (builtins) catAttrs readFile;
|
inherit (builtins) catAttrs readFile;
|
||||||
|
|
||||||
myLib = import ./lib.nix { inherit lib substituteAll; } // {
|
extLib = import ./lib.nix { inherit lib substituteAll; } // {
|
||||||
inherit (nix2lua.lib) toLua LuaNil;
|
inherit (nix2lua.lib) toLua LuaNil;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ let
|
||||||
pluginParams = neovimPlugins // {
|
pluginParams = neovimPlugins // {
|
||||||
inherit tree-sitter plugins enableDevIcons enableTabby enableOrgMode;
|
inherit tree-sitter plugins enableDevIcons enableTabby enableOrgMode;
|
||||||
themeCfg = theme;
|
themeCfg = theme;
|
||||||
lib = myLib;
|
lib = extLib;
|
||||||
};
|
};
|
||||||
|
|
||||||
callPlugin = plugin: callPackage plugin pluginParams;
|
callPlugin = plugin: callPackage plugin pluginParams;
|
||||||
|
@ -67,6 +67,14 @@ let
|
||||||
basicConfigs = map readFile [ ./config/basic.lua ];
|
basicConfigs = map readFile [ ./config/basic.lua ];
|
||||||
pluginConfigs = catAttrs "luaConfig" pluginsSettings;
|
pluginConfigs = catAttrs "luaConfig" pluginsSettings;
|
||||||
allConfigs = basicConfigs ++ pluginConfigs ++ [ extraLuaConfig ];
|
allConfigs = basicConfigs ++ pluginConfigs ++ [ extraLuaConfig ];
|
||||||
|
|
||||||
|
mkLuaHeredoc = content: ''
|
||||||
|
lua << EOF
|
||||||
|
${content}
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
|
||||||
|
mkLuaRc = lib.concatMapStrings mkLuaHeredoc;
|
||||||
in
|
in
|
||||||
(wrapNeovim neovim-unwrapped {
|
(wrapNeovim neovim-unwrapped {
|
||||||
inherit viAlias;
|
inherit viAlias;
|
||||||
|
@ -77,13 +85,13 @@ in
|
||||||
withRuby = false;
|
withRuby = false;
|
||||||
|
|
||||||
configure = {
|
configure = {
|
||||||
customRC = extraConfig + myLib.mkLuaRc allConfigs;
|
customRC = extraConfig + mkLuaRc allConfigs;
|
||||||
|
|
||||||
packages.myVimPackages = { start = allPlugins; };
|
packages.myVimPackages = { start = allPlugins; };
|
||||||
};
|
};
|
||||||
}).overrideAttrs (oldAttrs: {
|
}).overrideAttrs (oldAttrs: {
|
||||||
passthru = oldAttrs.passthru // {
|
passthru = oldAttrs.passthru // {
|
||||||
nix2lua = nix2lua.lib;
|
nix2lua = nix2lua.lib;
|
||||||
inherit plugins;
|
inherit plugins allConfigs;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -18,14 +18,17 @@ let
|
||||||
max_lines = 100;
|
max_lines = 100;
|
||||||
};
|
};
|
||||||
tabbymlSettings = lib.toLua (lib.attrByPath [ "tabbyml" "settings" ] tabbymlDefaultSettings plugins);
|
tabbymlSettings = lib.toLua (lib.attrByPath [ "tabbyml" "settings" ] tabbymlDefaultSettings plugins);
|
||||||
tabbymlLuaConfig = lib.optional tabbymlEnable
|
tabbymlLuaConfig = lib.optionalString tabbymlEnable
|
||||||
(lib.readSubFile ./cmp-tabby.lua { inherit tabbymlSettings; });
|
(lib.readSubFile ./cmp-tabby.lua { inherit tabbymlSettings; });
|
||||||
|
|
||||||
cmpSources = lib.toLua ([
|
cmpSources = lib.toLua (
|
||||||
{ name = "nvim_lsp"; }
|
[
|
||||||
{ name = "luasnip"; }
|
{ name = "nvim_lsp"; }
|
||||||
{ name = "orgmode"; }
|
{ name = "luasnip"; }
|
||||||
] ++ lib.optional tabbymlEnable [{ name = "cmp_tabby"; }]);
|
{ name = "orgmode"; }
|
||||||
|
]
|
||||||
|
++ lib.optional tabbymlEnable { name = "cmp_tabby"; }
|
||||||
|
);
|
||||||
cmpLuaConfig = lib.readSubFile ./nvim-cmp.lua { inherit cmpSources; };
|
cmpLuaConfig = lib.readSubFile ./nvim-cmp.lua { inherit cmpSources; };
|
||||||
|
|
||||||
lspconfigLuaConfig = lib.readSubFile ./lspconfig.lua
|
lspconfigLuaConfig = lib.readSubFile ./lspconfig.lua
|
||||||
|
@ -37,7 +40,7 @@ let
|
||||||
nvim-cmp # Autocompletion
|
nvim-cmp # Autocompletion
|
||||||
cmp-nvim-lsp # LSP source for nvim-cmp
|
cmp-nvim-lsp # LSP source for nvim-cmp
|
||||||
cmp-luasnip # Snippets source for nvim-cmp
|
cmp-luasnip # Snippets source for nvim-cmp
|
||||||
] ++ lib.optional tabbymlEnable [ cmp-tabby ];
|
] ++ lib.optional tabbymlEnable cmp-tabby;
|
||||||
|
|
||||||
lspConfigServers = lib.toLua (lib.attrByPath [ "lspConfig" "servers" ] [ ] plugins);
|
lspConfigServers = lib.toLua (lib.attrByPath [ "lspConfig" "servers" ] [ ] plugins);
|
||||||
lspSagaSettings = lib.toLua (lib.attrByPath [ "lspSaga" "settings" ] { } plugins);
|
lspSagaSettings = lib.toLua (lib.attrByPath [ "lspSaga" "settings" ] { } plugins);
|
||||||
|
|
|
@ -27,10 +27,10 @@ in
|
||||||
{
|
{
|
||||||
luaConfig = themeConfig
|
luaConfig = themeConfig
|
||||||
+ (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; }))
|
+ (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; }))
|
||||||
+ (lib.optional enableTabby (readFile ./tabby-nvim.lua));
|
+ (lib.optionalString enableTabby (readFile ./tabby-nvim.lua));
|
||||||
|
|
||||||
plugins = [ theme ]
|
plugins = [ theme ]
|
||||||
++ lualinePlugins
|
++ lualinePlugins
|
||||||
++ (lib.optional enableDevIcons [ nvim-web-devicons ])
|
++ (lib.optional enableDevIcons nvim-web-devicons)
|
||||||
++ (lib.optional enableTabby [ tabby-nvim ]);
|
++ (lib.optional enableTabby tabby-nvim);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ let
|
||||||
|
|
||||||
orgmodeEnable = lib.attrByPath [ "orgmode" "enable" ] enableOrgMode plugins;
|
orgmodeEnable = lib.attrByPath [ "orgmode" "enable" ] enableOrgMode plugins;
|
||||||
orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins);
|
orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins);
|
||||||
orgmodeLuaConfig = lib.optional orgmodeEnable
|
orgmodeLuaConfig = lib.optionalString orgmodeEnable
|
||||||
(lib.readSubFile ./nvim-orgmode.lua { inherit orgmodeSettings; });
|
(lib.readSubFile ./nvim-orgmode.lua { inherit orgmodeSettings; });
|
||||||
|
|
||||||
colorizerFiletypes = lib.toLua (lib.attrByPath [ "colorizer" "filetypes" ] lib.LuaNil plugins);
|
colorizerFiletypes = lib.toLua (lib.attrByPath [ "colorizer" "filetypes" ] lib.LuaNil plugins);
|
||||||
|
@ -28,5 +28,5 @@ in
|
||||||
luaConfig = hopLuaConfig + orgmodeLuaConfig + colorizerLuaConfig;
|
luaConfig = hopLuaConfig + orgmodeLuaConfig + colorizerLuaConfig;
|
||||||
|
|
||||||
plugins = [ hop-nvim nvim-colorizer ]
|
plugins = [ hop-nvim nvim-colorizer ]
|
||||||
++ lib.optional orgmodeEnable [ nvim-orgmode org-bullets-nvim ];
|
++ lib.optionals orgmodeEnable [ nvim-orgmode org-bullets-nvim ];
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue