mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-11 07:10:39 +02:00
feat(neovim): abstract custom config boilerplate away
This commit is contained in:
parent
7b7458ccd5
commit
603b59cbe9
3 changed files with 89 additions and 24 deletions
|
@ -3,15 +3,72 @@
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: {
|
}: let
|
||||||
options.programs.neovim-custom = {
|
inherit
|
||||||
enable = lib.mkEnableOption "Neovim";
|
(lib)
|
||||||
package = lib.mkPackageOption pkgs "neovim" {};
|
concatMapStrings
|
||||||
|
flip
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
mkPackageOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
cfg = config.programs.neovim-custom;
|
||||||
|
|
||||||
|
initLuaContent = ''
|
||||||
|
${cfg.initEarly}
|
||||||
|
|
||||||
|
-- Begin plugin configuration
|
||||||
|
${concatMapStrings (x: "${x.config}\n") (cfg.config.plugins or [])}
|
||||||
|
-- End plugin configuration
|
||||||
|
|
||||||
|
${cfg.init}
|
||||||
|
'';
|
||||||
|
|
||||||
|
nvimConfig =
|
||||||
|
pkgs.neovimUtils.makeNeovimConfig cfg.config
|
||||||
|
// {
|
||||||
|
wrapRc = false;
|
||||||
|
wrapperArgs = ["--add-flags" "-u ${pkgs.writeText "init.lua" initLuaContent}"];
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf config.programs.neovim-custom.enable {
|
finalPackage =
|
||||||
|
flip pkgs.wrapNeovimUnstable nvimConfig
|
||||||
|
(cfg.package.overrideAttrs (_final: prev: {
|
||||||
|
nativeBuildInputs = (prev.nativeBuildInputs or []) ++ [pkgs.makeWrapper];
|
||||||
|
postInstall =
|
||||||
|
(prev.postInstall or "")
|
||||||
|
+ ''
|
||||||
|
wrapProgram $out/bin/nvim --add-flags "--clean"
|
||||||
|
'';
|
||||||
|
}));
|
||||||
|
in {
|
||||||
|
options.programs.neovim-custom = {
|
||||||
|
enable = mkEnableOption "Neovim";
|
||||||
|
package = mkPackageOption pkgs "neovim-unwrapped" {};
|
||||||
|
config = mkOption {
|
||||||
|
description = "The neovim configuration to use (passed to makeNeovimConfig and then to wrapNeovimUnstable)";
|
||||||
|
default = {};
|
||||||
|
type = types.anything;
|
||||||
|
};
|
||||||
|
initEarly = mkOption {
|
||||||
|
description = "The early init.lua content that will be added before plugin configs.";
|
||||||
|
default = "";
|
||||||
|
type = types.lines;
|
||||||
|
};
|
||||||
|
init = mkOption {
|
||||||
|
description = "The init.lua content, added after plugin configs.";
|
||||||
|
default = "";
|
||||||
|
type = types.lines;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
home = {
|
home = {
|
||||||
# TODO packages = [config.programs.neovim-custom.package];
|
# XXX: TODO packages = [finalPackage];
|
||||||
|
shellAliases.E = "${finalPackage}/bin/nvim";
|
||||||
sessionVariables.EDITOR = "nvim";
|
sessionVariables.EDITOR = "nvim";
|
||||||
shellAliases.vimdiff = "nvim -d";
|
shellAliases.vimdiff = "nvim -d";
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,12 @@ opt.title = false -- Sets the window title
|
||||||
--opt.titlestring = "%t%( %M%)%( (%{expand(\"%:~:.:h\")})%) - nvim" -- The format for the window title
|
--opt.titlestring = "%t%( %M%)%( (%{expand(\"%:~:.:h\")})%) - nvim" -- The format for the window title
|
||||||
|
|
||||||
-- Hide line numbers in terminal windows
|
-- Hide line numbers in terminal windows
|
||||||
vim.api.nvim_exec([[au BufEnter term://* setlocal nonumber]], false)
|
vim.api.nvim_create_autocmd("BufEnter", {
|
||||||
|
pattern = "term://*",
|
||||||
|
callback = function()
|
||||||
|
vim.bo.number = false
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------
|
||||||
-- Editing behavior
|
-- Editing behavior
|
||||||
|
|
|
@ -3,23 +3,27 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
programs.neovim-custom.package = let
|
programs.neovim-custom = {
|
||||||
nvimConfig =
|
config = {
|
||||||
pkgs.neovimUtils.makeNeovimConfig {
|
withPython3 = false;
|
||||||
wrapRc = false;
|
withRuby = false;
|
||||||
withPython3 = true;
|
withNodeJs = false;
|
||||||
withRuby = true;
|
|
||||||
withNodeJs = true;
|
|
||||||
#extraPython3Packages = p: [];
|
#extraPython3Packages = p: [];
|
||||||
#plugins = [
|
plugins = with pkgs.vimPlugins; [
|
||||||
# { plugin = pkgs.; config = ''''; optional = false; }
|
{
|
||||||
#];
|
plugin = neo-tree-nvim;
|
||||||
|
config =
|
||||||
|
/*
|
||||||
|
lua
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
require("neo-tree").setup {}
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
// {
|
];
|
||||||
wrapperArgs = ["--add-flags" "--clean -u ${./aaa/init.lua}"];
|
};
|
||||||
|
init = builtins.readFile ./aaa/init.lua;
|
||||||
};
|
};
|
||||||
in
|
|
||||||
pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped nvimConfig;
|
|
||||||
|
|
||||||
home.packages = let
|
home.packages = let
|
||||||
nvimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
nvimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||||
|
@ -36,5 +40,4 @@
|
||||||
"nvim/init.lua".source = ./init.lua;
|
"nvim/init.lua".source = ./init.lua;
|
||||||
"nvim/lua".source = ./lua;
|
"nvim/lua".source = ./lua;
|
||||||
};
|
};
|
||||||
home.sessionVariables.E = "${config.programs.neovim-custom.package}/bin/nvim";
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue