mirror of
https://github.com/nix-community/home-manager
synced 2024-12-25 03:09:47 +01:00
neovim: fix extraLuaPackages type. (#3533)
Assigning to `programs.neovim.extraLuaPackages` a function taking a lua package set as input and returning a list of packages, as described in the documentation, threw an error because the rest of the code assumed that the value was always a plain list. Using `lib.types.coercedTo`, we can accept such functions, as per the documentation, as well as plain lists, which we then convert to a function ignoring its input argument. We print a warning when a plain list is assigned, since the function form is preferred, as it ensures that the right lua package set is used. For the lua packages, we also get the lua package set from the finalPackage, to make sure that we are always using the same package set as the actual unwrapped neovim package being built. For `programs.neovim.extraPythonPackages` I did the same. I updated the test case so that we test both ways of setting these options.
This commit is contained in:
parent
fa1bc088ea
commit
a993eac106
2 changed files with 81 additions and 61 deletions
|
@ -13,25 +13,6 @@ let
|
||||||
|
|
||||||
jsonFormat = pkgs.formats.json { };
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
extraPython3PackageType = mkOptionType {
|
|
||||||
name = "extra-python3-packages";
|
|
||||||
description = "python3 packages in python.withPackages format";
|
|
||||||
check = with types;
|
|
||||||
(x: if isFunction x then isList (x pkgs.python3Packages) else false);
|
|
||||||
merge = mergeOneOption;
|
|
||||||
};
|
|
||||||
|
|
||||||
# Currently, upstream Neovim is pinned on Lua 5.1 for LuaJIT support.
|
|
||||||
# This will need to be updated if Neovim ever migrates to a newer
|
|
||||||
# version of Lua.
|
|
||||||
extraLua51PackageType = mkOptionType {
|
|
||||||
name = "extra-lua51-packages";
|
|
||||||
description = "lua5.1 packages in lua5_1.withPackages format";
|
|
||||||
check = with types;
|
|
||||||
(x: if isFunction x then isList (x pkgs.lua51Packages) else false);
|
|
||||||
merge = mergeOneOption;
|
|
||||||
};
|
|
||||||
|
|
||||||
pluginWithConfigType = types.submodule {
|
pluginWithConfigType = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
|
@ -80,19 +61,23 @@ let
|
||||||
optional = false;
|
optional = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
luaPackages = cfg.finalPackage.unwrapped.lua.pkgs;
|
||||||
|
resolvedExtraLuaPackages = cfg.extraLuaPackages luaPackages;
|
||||||
|
|
||||||
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
||||||
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
||||||
extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
extraMakeWrapperLuaCArgs =
|
||||||
|
lib.optionalString (resolvedExtraLuaPackages != [ ]) ''
|
||||||
--suffix LUA_CPATH ";" "${
|
--suffix LUA_CPATH ";" "${
|
||||||
lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaCPath
|
lib.concatMapStringsSep ";" luaPackages.getLuaCPath
|
||||||
cfg.extraLuaPackages
|
resolvedExtraLuaPackages
|
||||||
}"'';
|
}"'';
|
||||||
extraMakeWrapperLuaArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
extraMakeWrapperLuaArgs = lib.optionalString (resolvedExtraLuaPackages != [ ])
|
||||||
|
''
|
||||||
--suffix LUA_PATH ";" "${
|
--suffix LUA_PATH ";" "${
|
||||||
lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaPath
|
lib.concatMapStringsSep ";" luaPackages.getLuaPath
|
||||||
cfg.extraLuaPackages
|
resolvedExtraLuaPackages
|
||||||
}"'';
|
}"'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
imports = [
|
imports = [
|
||||||
(mkRemovedOptionModule [ "programs" "neovim" "withPython" ]
|
(mkRemovedOptionModule [ "programs" "neovim" "withPython" ]
|
||||||
|
@ -164,24 +149,51 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
extraPython3Packages = mkOption {
|
extraPython3Packages = mkOption {
|
||||||
type = with types; either extraPython3PackageType (listOf package);
|
# In case we get a plain list, we need to turn it into a function,
|
||||||
default = (_: [ ]);
|
# as expected by the function in nixpkgs.
|
||||||
|
# The only way to do so is to call `const`, which will ignore its input.
|
||||||
|
type = with types;
|
||||||
|
let fromType = listOf package;
|
||||||
|
in coercedTo fromType (flip warn const ''
|
||||||
|
Assigning a plain list to extraPython3Packages is deprecated.
|
||||||
|
Please assign a function taking a package set as argument, so
|
||||||
|
extraPython3Packages = [ pkgs.python3Packages.xxx ];
|
||||||
|
should become
|
||||||
|
extraPython3Packages = ps: [ ps.xxx ];
|
||||||
|
'') (functionTo fromType);
|
||||||
|
default = _: [ ];
|
||||||
defaultText = literalExpression "ps: [ ]";
|
defaultText = literalExpression "ps: [ ]";
|
||||||
example = literalExpression "(ps: with ps; [ python-language-server ])";
|
example =
|
||||||
|
literalExpression "pyPkgs: with pyPkgs; [ python-language-server ]";
|
||||||
description = ''
|
description = ''
|
||||||
A function in python.withPackages format, which returns a
|
The extra Python 3 packages required for your plugins to work.
|
||||||
list of Python 3 packages required for your plugins to work.
|
This option accepts a function that takes a Python 3 package set as an argument,
|
||||||
|
and selects the required Python 3 packages from this package set.
|
||||||
|
See the example for more info.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# We get the Lua package from the final package and use its
|
||||||
|
# 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.
|
||||||
extraLuaPackages = mkOption {
|
extraLuaPackages = mkOption {
|
||||||
type = with types; either extraLua51PackageType (listOf package);
|
type = with types;
|
||||||
default = [ ];
|
let fromType = listOf package;
|
||||||
defaultText = literalExpression "[ ]";
|
in coercedTo fromType (flip warn const ''
|
||||||
example = literalExpression "(ps: with ps; [ luautf8 ])";
|
Assigning a plain list to extraLuaPackages is deprecated.
|
||||||
|
Please assign a function taking a package set as argument, so
|
||||||
|
extraLuaPackages = [ pkgs.lua51Packages.xxx ];
|
||||||
|
should become
|
||||||
|
extraLuaPackages = ps: [ ps.xxx ];
|
||||||
|
'') (functionTo fromType);
|
||||||
|
default = _: [ ];
|
||||||
|
defaultText = literalExpression "ps: [ ]";
|
||||||
|
example = literalExpression "luaPkgs: with luaPkgs; [ luautf8 ]";
|
||||||
description = ''
|
description = ''
|
||||||
A function in lua5_1.withPackages format, which returns a
|
The extra Lua packages required for your plugins to work.
|
||||||
list of Lua packages required for your plugins to work.
|
This option accepts a function that takes a Lua package set as an argument,
|
||||||
|
and selects the required Lua packages from this package set.
|
||||||
|
See the example for more info.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -280,7 +292,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = jsonFormat.type;
|
inherit (jsonFormat) type;
|
||||||
default = { };
|
default = { };
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
{
|
{
|
||||||
|
@ -354,7 +366,7 @@ in {
|
||||||
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
||||||
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 mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals))
|
||||||
grouped;
|
grouped;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ with lib;
|
||||||
|
|
||||||
{
|
{
|
||||||
config = {
|
config = {
|
||||||
programs.neovim = {
|
programs.neovim = lib.mkMerge [
|
||||||
|
{
|
||||||
enable = true;
|
enable = true;
|
||||||
plugins = with pkgs.vimPlugins; [
|
plugins = with pkgs.vimPlugins; [
|
||||||
vim-nix
|
vim-nix
|
||||||
|
@ -19,13 +20,20 @@ with lib;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
extraPython3Packages = ps: with ps; [ jedi pynvim ];
|
||||||
|
extraLuaPackages = ps: with ps; [ luacheck ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
extraPython3Packages = with pkgs.python3Packages; [ jedi pynvim ];
|
||||||
|
extraLuaPackages = with pkgs.lua51Packages; [ luacheck ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
extraPython3Packages = (ps: with ps; [ jedi pynvim ]);
|
|
||||||
};
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
ftplugin="home-files/.config/nvim/after/ftplugin/c.vim"
|
ftplugin="home-files/.config/nvim/after/ftplugin/c.vim"
|
||||||
assertFileExists "$ftplugin"
|
assertFileExists "$ftplugin"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue