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 {
|
||||
name = name;
|
||||
src = getAttr name inputs;
|
||||
patches = lib.optional
|
||||
patches = lib.optionals
|
||||
(pathExists ./patches/${name})
|
||||
(map
|
||||
(patchName: ./patches/${name}/${patchName})
|
||||
|
|
60
lib.nix
60
lib.nix
|
@ -1,65 +1,7 @@
|
|||
{ lib, substituteAll, ... }:
|
||||
|
||||
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
|
||||
(substituteAll (params // { inherit src; }));
|
||||
|
||||
in
|
||||
{
|
||||
inherit (lib) importJSON attrByPath;
|
||||
inherit foldr concatMap;
|
||||
inherit optional getAttrOpt;
|
||||
inherit mkLuaHeredoc mkLuaRc;
|
||||
inherit readSubFile substituteAll;
|
||||
}
|
||||
lib // { inherit readSubFile substituteAll; }
|
||||
|
|
16
neovim.nix
16
neovim.nix
|
@ -35,7 +35,7 @@ let
|
|||
plugins = mergeAttrs plugins';
|
||||
inherit (builtins) catAttrs readFile;
|
||||
|
||||
myLib = import ./lib.nix { inherit lib substituteAll; } // {
|
||||
extLib = import ./lib.nix { inherit lib substituteAll; } // {
|
||||
inherit (nix2lua.lib) toLua LuaNil;
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ let
|
|||
pluginParams = neovimPlugins // {
|
||||
inherit tree-sitter plugins enableDevIcons enableTabby enableOrgMode;
|
||||
themeCfg = theme;
|
||||
lib = myLib;
|
||||
lib = extLib;
|
||||
};
|
||||
|
||||
callPlugin = plugin: callPackage plugin pluginParams;
|
||||
|
@ -67,6 +67,14 @@ let
|
|||
basicConfigs = map readFile [ ./config/basic.lua ];
|
||||
pluginConfigs = catAttrs "luaConfig" pluginsSettings;
|
||||
allConfigs = basicConfigs ++ pluginConfigs ++ [ extraLuaConfig ];
|
||||
|
||||
mkLuaHeredoc = content: ''
|
||||
lua << EOF
|
||||
${content}
|
||||
EOF
|
||||
'';
|
||||
|
||||
mkLuaRc = lib.concatMapStrings mkLuaHeredoc;
|
||||
in
|
||||
(wrapNeovim neovim-unwrapped {
|
||||
inherit viAlias;
|
||||
|
@ -77,13 +85,13 @@ in
|
|||
withRuby = false;
|
||||
|
||||
configure = {
|
||||
customRC = extraConfig + myLib.mkLuaRc allConfigs;
|
||||
customRC = extraConfig + mkLuaRc allConfigs;
|
||||
|
||||
packages.myVimPackages = { start = allPlugins; };
|
||||
};
|
||||
}).overrideAttrs (oldAttrs: {
|
||||
passthru = oldAttrs.passthru // {
|
||||
nix2lua = nix2lua.lib;
|
||||
inherit plugins;
|
||||
inherit plugins allConfigs;
|
||||
};
|
||||
})
|
||||
|
|
|
@ -18,14 +18,17 @@ let
|
|||
max_lines = 100;
|
||||
};
|
||||
tabbymlSettings = lib.toLua (lib.attrByPath [ "tabbyml" "settings" ] tabbymlDefaultSettings plugins);
|
||||
tabbymlLuaConfig = lib.optional tabbymlEnable
|
||||
tabbymlLuaConfig = lib.optionalString tabbymlEnable
|
||||
(lib.readSubFile ./cmp-tabby.lua { inherit tabbymlSettings; });
|
||||
|
||||
cmpSources = lib.toLua ([
|
||||
cmpSources = lib.toLua (
|
||||
[
|
||||
{ name = "nvim_lsp"; }
|
||||
{ name = "luasnip"; }
|
||||
{ name = "orgmode"; }
|
||||
] ++ lib.optional tabbymlEnable [{ name = "cmp_tabby"; }]);
|
||||
]
|
||||
++ lib.optional tabbymlEnable { name = "cmp_tabby"; }
|
||||
);
|
||||
cmpLuaConfig = lib.readSubFile ./nvim-cmp.lua { inherit cmpSources; };
|
||||
|
||||
lspconfigLuaConfig = lib.readSubFile ./lspconfig.lua
|
||||
|
@ -37,7 +40,7 @@ let
|
|||
nvim-cmp # Autocompletion
|
||||
cmp-nvim-lsp # LSP 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);
|
||||
lspSagaSettings = lib.toLua (lib.attrByPath [ "lspSaga" "settings" ] { } plugins);
|
||||
|
|
|
@ -27,10 +27,10 @@ in
|
|||
{
|
||||
luaConfig = themeConfig
|
||||
+ (readFile (lib.substituteAll { src = ./lualine.lua; inherit lualineSettings; }))
|
||||
+ (lib.optional enableTabby (readFile ./tabby-nvim.lua));
|
||||
+ (lib.optionalString enableTabby (readFile ./tabby-nvim.lua));
|
||||
|
||||
plugins = [ theme ]
|
||||
++ lualinePlugins
|
||||
++ (lib.optional enableDevIcons [ nvim-web-devicons ])
|
||||
++ (lib.optional enableTabby [ tabby-nvim ]);
|
||||
++ (lib.optional enableDevIcons nvim-web-devicons)
|
||||
++ (lib.optional enableTabby tabby-nvim);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ let
|
|||
|
||||
orgmodeEnable = lib.attrByPath [ "orgmode" "enable" ] enableOrgMode plugins;
|
||||
orgmodeSettings = lib.toLua (lib.attrByPath [ "orgmode" "settings" ] { } plugins);
|
||||
orgmodeLuaConfig = lib.optional orgmodeEnable
|
||||
orgmodeLuaConfig = lib.optionalString orgmodeEnable
|
||||
(lib.readSubFile ./nvim-orgmode.lua { inherit orgmodeSettings; });
|
||||
|
||||
colorizerFiletypes = lib.toLua (lib.attrByPath [ "colorizer" "filetypes" ] lib.LuaNil plugins);
|
||||
|
@ -28,5 +28,5 @@ in
|
|||
luaConfig = hopLuaConfig + orgmodeLuaConfig + colorizerLuaConfig;
|
||||
|
||||
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