From 234613d77c939ff2e2c0f2c476a56d80930e5b8b Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 30 Jan 2025 13:46:03 -0600 Subject: [PATCH] neovim: remove with lib --- modules/programs/neovim.nix | 77 ++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index 2ee568c28..af7a1a1f0 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -1,8 +1,8 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) + literalExpression mkEnableOption mkIf mkOption mkRemovedOptionModule types; 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"; plugin = cfg.coc.package; config = cfg.coc.pluginConfig; @@ -155,15 +155,14 @@ in { # In case we get a plain list, we need to turn it into a function, # 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); + type = let fromType = types.listOf types.package; + in types.coercedTo fromType (lib.flip lib.warn lib.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 ]; + '') (types.functionTo fromType); default = _: [ ]; defaultText = literalExpression "ps: [ ]"; example = @@ -180,15 +179,14 @@ in { # 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 { - type = with types; - let fromType = listOf package; - in coercedTo fromType (flip warn const '' - 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); + type = let fromType = types.listOf types.package; + in types.coercedTo fromType (lib.flip lib.warn lib.const '' + 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 ]; + '') (types.functionTo fromType); default = _: [ ]; defaultText = literalExpression "ps: [ ]"; example = literalExpression "luaPkgs: with luaPkgs; [ luautf8 ]"; @@ -416,7 +414,7 @@ in { concatConfigs = lib.concatMapStrings (p: p.config); configsOnly = lib.foldl (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; home.packages = [ cfg.finalPackage ]; @@ -425,25 +423,24 @@ in { home.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; }; - xdg.configFile = - let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs; - in mkMerge ( - # writes runtime - (map (x: x.runtime) pluginsNormalized) ++ [{ - "nvim/init.lua" = let - luaRcContent = lib.optionalString (wrappedNeovim'.initRc != "") - "vim.cmd [[source ${ - pkgs.writeText "nvim-init-home-manager.vim" - wrappedNeovim'.initRc - }]]" + config.programs.neovim.extraLuaConfig - + lib.optionalString hasLuaConfig - config.programs.neovim.generatedConfigs.lua; - in mkIf (luaRcContent != "") { text = luaRcContent; }; + xdg.configFile = let + hasLuaConfig = lib.hasAttr "lua" config.programs.neovim.generatedConfigs; + in lib.mkMerge ( + # writes runtime + (map (x: x.runtime) pluginsNormalized) ++ [{ + "nvim/init.lua" = let + luaRcContent = lib.optionalString (wrappedNeovim'.initRc != "") + "vim.cmd [[source ${ + pkgs.writeText "nvim-init-home-manager.vim" wrappedNeovim'.initRc + }]]" + config.programs.neovim.extraLuaConfig + + lib.optionalString hasLuaConfig + config.programs.neovim.generatedConfigs.lua; + in mkIf (luaRcContent != "") { text = luaRcContent; }; - "nvim/coc-settings.json" = mkIf cfg.coc.enable { - source = jsonFormat.generate "coc-settings.json" cfg.coc.settings; - }; - }]); + "nvim/coc-settings.json" = mkIf cfg.coc.enable { + source = jsonFormat.generate "coc-settings.json" cfg.coc.settings; + }; + }]); programs.neovim.finalPackage = wrappedNeovim'; };