1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-08 17:56:54 +00:00

neovim: remove with lib

This commit is contained in:
Austin Horstman 2025-01-30 13:46:03 -06:00
parent 86b0f3049c
commit 234613d77c

View file

@ -1,8 +1,8 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
inherit (lib)
literalExpression mkEnableOption mkIf mkOption mkRemovedOptionModule types;
cfg = config.programs.neovim; cfg = config.programs.neovim;
@ -55,7 +55,7 @@ let
}; };
}; };
allPlugins = cfg.plugins ++ optional cfg.coc.enable { allPlugins = cfg.plugins ++ lib.optional cfg.coc.enable {
type = "viml"; type = "viml";
plugin = cfg.coc.package; plugin = cfg.coc.package;
config = cfg.coc.pluginConfig; config = cfg.coc.pluginConfig;
@ -155,15 +155,14 @@ in {
# In case we get a plain list, we need to turn it into a function, # In case we get a plain list, we need to turn it into a function,
# as expected by the function in nixpkgs. # as expected by the function in nixpkgs.
# The only way to do so is to call `const`, which will ignore its input. # The only way to do so is to call `const`, which will ignore its input.
type = with types; type = let fromType = types.listOf types.package;
let fromType = listOf package; in types.coercedTo fromType (lib.flip lib.warn lib.const ''
in coercedTo fromType (flip warn const '' Assigning a plain list to extraPython3Packages is deprecated.
Assigning a plain list to extraPython3Packages is deprecated. Please assign a function taking a package set as argument, so
Please assign a function taking a package set as argument, so extraPython3Packages = [ pkgs.python3Packages.xxx ];
extraPython3Packages = [ pkgs.python3Packages.xxx ]; should become
should become extraPython3Packages = ps: [ ps.xxx ];
extraPython3Packages = ps: [ ps.xxx ]; '') (types.functionTo fromType);
'') (functionTo fromType);
default = _: [ ]; default = _: [ ];
defaultText = literalExpression "ps: [ ]"; defaultText = literalExpression "ps: [ ]";
example = example =
@ -180,15 +179,14 @@ in {
# Lua packageset to evaluate the function that this option was set to. # Lua packageset to evaluate the function that this option was set to.
# This ensures that we always use the same Lua version as the Neovim package. # This ensures that we always use the same Lua version as the Neovim package.
extraLuaPackages = mkOption { extraLuaPackages = mkOption {
type = with types; type = let fromType = types.listOf types.package;
let fromType = listOf package; in types.coercedTo fromType (lib.flip lib.warn lib.const ''
in coercedTo fromType (flip warn const '' Assigning a plain list to extraLuaPackages is deprecated.
Assigning a plain list to extraLuaPackages is deprecated. Please assign a function taking a package set as argument, so
Please assign a function taking a package set as argument, so extraLuaPackages = [ pkgs.lua51Packages.xxx ];
extraLuaPackages = [ pkgs.lua51Packages.xxx ]; should become
should become extraLuaPackages = ps: [ ps.xxx ];
extraLuaPackages = ps: [ ps.xxx ]; '') (types.functionTo fromType);
'') (functionTo fromType);
default = _: [ ]; default = _: [ ];
defaultText = literalExpression "ps: [ ]"; defaultText = literalExpression "ps: [ ]";
example = literalExpression "luaPkgs: with luaPkgs; [ luautf8 ]"; example = literalExpression "luaPkgs: with luaPkgs; [ luautf8 ]";
@ -416,7 +414,7 @@ in {
concatConfigs = lib.concatMapStrings (p: p.config); concatConfigs = lib.concatMapStrings (p: p.config);
configsOnly = lib.foldl configsOnly = lib.foldl
(acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ]; (acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ];
in mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals)) in lib.mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals))
grouped; grouped;
home.packages = [ cfg.finalPackage ]; home.packages = [ cfg.finalPackage ];
@ -425,25 +423,24 @@ in {
home.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; }; home.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
xdg.configFile = xdg.configFile = let
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs; hasLuaConfig = lib.hasAttr "lua" config.programs.neovim.generatedConfigs;
in mkMerge ( in lib.mkMerge (
# writes runtime # writes runtime
(map (x: x.runtime) pluginsNormalized) ++ [{ (map (x: x.runtime) pluginsNormalized) ++ [{
"nvim/init.lua" = let "nvim/init.lua" = let
luaRcContent = lib.optionalString (wrappedNeovim'.initRc != "") luaRcContent = lib.optionalString (wrappedNeovim'.initRc != "")
"vim.cmd [[source ${ "vim.cmd [[source ${
pkgs.writeText "nvim-init-home-manager.vim" pkgs.writeText "nvim-init-home-manager.vim" wrappedNeovim'.initRc
wrappedNeovim'.initRc }]]" + config.programs.neovim.extraLuaConfig
}]]" + config.programs.neovim.extraLuaConfig + lib.optionalString hasLuaConfig
+ lib.optionalString hasLuaConfig config.programs.neovim.generatedConfigs.lua;
config.programs.neovim.generatedConfigs.lua; in mkIf (luaRcContent != "") { text = luaRcContent; };
in mkIf (luaRcContent != "") { text = luaRcContent; };
"nvim/coc-settings.json" = mkIf cfg.coc.enable { "nvim/coc-settings.json" = mkIf cfg.coc.enable {
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings; source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
}; };
}]); }]);
programs.neovim.finalPackage = wrappedNeovim'; programs.neovim.finalPackage = wrappedNeovim';
}; };