forked from mirrors_public/oddlama_nix-config
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,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
inherit
|
||||
(lib)
|
||||
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}"];
|
||||
};
|
||||
|
||||
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 = lib.mkEnableOption "Neovim";
|
||||
package = lib.mkPackageOption pkgs "neovim" {};
|
||||
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 = lib.mkIf config.programs.neovim-custom.enable {
|
||||
config = mkIf cfg.enable {
|
||||
home = {
|
||||
# TODO packages = [config.programs.neovim-custom.package];
|
||||
# XXX: TODO packages = [finalPackage];
|
||||
shellAliases.E = "${finalPackage}/bin/nvim";
|
||||
sessionVariables.EDITOR = "nvim";
|
||||
shellAliases.vimdiff = "nvim -d";
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue