From 4e867c54250b5b126a878feed85fc7663e2ead89 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 21:46:17 +0100 Subject: [PATCH 01/31] wrapper: rename build dir to environemnt --- modules/modules.nix | 2 +- modules/wrapper/{build => environment}/config.nix | 0 modules/wrapper/{build => environment}/default.nix | 0 modules/wrapper/{build => environment}/options.nix | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename modules/wrapper/{build => environment}/config.nix (100%) rename modules/wrapper/{build => environment}/default.nix (100%) rename modules/wrapper/{build => environment}/options.nix (100%) diff --git a/modules/modules.nix b/modules/modules.nix index bc441e96..ee37a0e7 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -48,7 +48,7 @@ # The neovim wrapper, used to build a wrapped neovim package # using the configuration passed in `neovim` and `plugins` modules. wrapper = map (p: ./wrapper + "/${p}") [ - "build" + "environment" "rc" "warnings" "lazy" diff --git a/modules/wrapper/build/config.nix b/modules/wrapper/environment/config.nix similarity index 100% rename from modules/wrapper/build/config.nix rename to modules/wrapper/environment/config.nix diff --git a/modules/wrapper/build/default.nix b/modules/wrapper/environment/default.nix similarity index 100% rename from modules/wrapper/build/default.nix rename to modules/wrapper/environment/default.nix diff --git a/modules/wrapper/build/options.nix b/modules/wrapper/environment/options.nix similarity index 100% rename from modules/wrapper/build/options.nix rename to modules/wrapper/environment/options.nix From 2217565730056e33f92e24b5a996a4e87e350785 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 21:49:11 +0100 Subject: [PATCH 02/31] wrapper: add built package as option --- modules/modules.nix | 1 + modules/wrapper/build/config.nix | 111 ++++++++++++++++++++++++++++++ modules/wrapper/build/default.nix | 6 ++ modules/wrapper/build/options.nix | 12 ++++ 4 files changed, 130 insertions(+) create mode 100644 modules/wrapper/build/config.nix create mode 100644 modules/wrapper/build/default.nix create mode 100644 modules/wrapper/build/options.nix diff --git a/modules/modules.nix b/modules/modules.nix index ee37a0e7..6e05c592 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -48,6 +48,7 @@ # The neovim wrapper, used to build a wrapped neovim package # using the configuration passed in `neovim` and `plugins` modules. wrapper = map (p: ./wrapper + "/${p}") [ + "build" "environment" "rc" "warnings" diff --git a/modules/wrapper/build/config.nix b/modules/wrapper/build/config.nix new file mode 100644 index 00000000..85c87dd6 --- /dev/null +++ b/modules/wrapper/build/config.nix @@ -0,0 +1,111 @@ +{ + inputs, + lib, + config, + pkgs, + ... +} +: let + inherit (pkgs) vimPlugins; + inherit (lib.strings) isString; + inherit (lib.lists) filter map; + + # alias to the internal configuration + vimOptions = config.vim; + + noBuildPlug = {pname, ...} @ attrs: let + src = inputs."plugin-${attrs.pname}"; + in + { + version = src.shortRev or src.shortDirtyRev or "dirty"; + outPath = src; + passthru.vimPlugin = false; + } + // attrs; + + # build a vim plugin with the given name and arguments + # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug + # instead + buildPlug = attrs: let + src = inputs."plugin-${attrs.pname}"; + in + pkgs.vimUtils.buildVimPlugin ( + { + version = src.shortRev or src.shortDirtyRev or "dirty"; + inherit src; + } + // attrs + ); + + buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); + + pluginBuilders = { + nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars; + flutter-tools-patched = buildPlug { + pname = "flutter-tools"; + patches = [../patches/flutter-tools.patch]; + }; + }; + + buildConfigPlugins = plugins: + map ( + plug: + if (isString plug) + then pluginBuilders.${plug} or (noBuildPlug {pname = plug;}) + else plug + ) (filter (f: f != null) plugins); + + # built (or "normalized") plugins that are modified + builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; + builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins); + + # additional Lua and Python3 packages, mapped to their respective functions + # to conform to the format mnw expects. end user should + # only ever need to pass a list of packages, which are modified + # here + extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; + extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages; + + # Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to + # generate a wrapped Neovim package. + neovim-wrapped = inputs.mnw.lib.wrap pkgs { + neovim = vimOptions.package; + plugins = builtStartPlugins ++ builtOptPlugins; + appName = "nvf"; + extraBinPath = vimOptions.extraPackages; + initLua = vimOptions.builtLuaConfigRC; + luaFiles = vimOptions.extraLuaFiles; + + inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3; + inherit extraLuaPackages extraPython3Packages; + }; + + dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC; + # Additional helper scripts for printing and displaying nvf configuration + # in your commandline. + printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; + printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}"; + + # Expose wrapped neovim-package for userspace + # or module consumption. + neovim = pkgs.symlinkJoin { + name = "nvf-with-helpers"; + paths = [neovim-wrapped printConfig printConfigPath]; + postBuild = "echo Helpers added"; + + # Allow evaluating vimOptions, i.e., config.vim from the packages' passthru + # attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig + # will return the configuration in full. + passthru.neovimConfig = vimOptions; + + meta = + neovim-wrapped.meta + // { + description = "Wrapped Neovim package with helper scripts to print the config (path)"; + }; + }; +in { + config.vim.build = { + finalPackage = neovim; + }; +} diff --git a/modules/wrapper/build/default.nix b/modules/wrapper/build/default.nix new file mode 100644 index 00000000..0ebefe45 --- /dev/null +++ b/modules/wrapper/build/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./options.nix + ./config.nix + ]; +} diff --git a/modules/wrapper/build/options.nix b/modules/wrapper/build/options.nix new file mode 100644 index 00000000..fa1db61e --- /dev/null +++ b/modules/wrapper/build/options.nix @@ -0,0 +1,12 @@ +{lib, ...}: let + inherit (lib.types) package; + inherit (lib.options) mkOption; +in { + options.vim.build = { + finalPackage = mkOption { + type = package; + readOnly = true; + description = "final output package"; + }; + }; +} From dc5551b0508aa099125c6a7606ae4fe5183fd05f Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 21:50:13 +0100 Subject: [PATCH 03/31] home-manager: use proper submodule type for settings --- flake.nix | 2 +- flake/modules/home-manager.nix | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 161ba43f..3a177517 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ }; homeManagerModules = { - nvf = import ./flake/modules/home-manager.nix self.packages lib; + nvf = import ./flake/modules/home-manager.nix self.packages lib inputs; default = self.homeManagerModules.nvf; neovim-flake = lib.warn '' diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index 77b8448c..d1e85368 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -1,5 +1,5 @@ # Home Manager module -packages: lib: { +packages: lib: inputs: { config, pkgs, ... @@ -8,15 +8,19 @@ packages: lib: { inherit (lib.modules) mkIf mkAliasOptionModule; inherit (lib.lists) optional; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrsOf anything bool; - inherit (lib.nvim) neovimConfiguration; - inherit (lib.nvim.types) anythingConcatLists; + inherit (lib.types) anything bool submoduleWith; cfg = config.programs.nvf; - neovimConfigured = neovimConfiguration { - inherit pkgs; - modules = [cfg.settings]; + nvfModule = submoduleWith { + description = "Nvf module"; + class = "nvf"; + specialArgs = { + inherit pkgs lib inputs; + }; + modules = [ + {imports = import ../../modules/modules.nix {inherit pkgs lib;};} + ]; }; in { imports = [ @@ -55,7 +59,7 @@ in { }; settings = mkOption { - type = attrsOf anythingConcatLists; + type = nvfModule; default = {}; description = "Attribute set of nvf preferences."; example = literalExpression '' @@ -78,7 +82,7 @@ in { }; config = mkIf cfg.enable { - programs.nvf.finalPackage = neovimConfigured.neovim; + programs.nvf.finalPackage = cfg.settings.vim.build.finalPackage; home = { sessionVariables = mkIf cfg.defaultEditor {EDITOR = "nvim";}; From e9cc77dff7191d923c7368993f1d7a2f38471d8c Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 21:59:24 +0100 Subject: [PATCH 04/31] module: remove redundant code the bulk of the build step is moved to modules/wrapper/build --- modules/default.nix | 105 ++++---------------------------------------- 1 file changed, 9 insertions(+), 96 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index a2f8730d..a207e0d1 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,9 +9,8 @@ extraModules ? [], configuration ? {}, }: let - inherit (pkgs) vimPlugins; - inherit (lib.strings) isString toString; - inherit (lib.lists) filter map concatLists; + inherit (lib.strings) toString; + inherit (lib.lists) concatLists; # import modules.nix with `check`, `pkgs` and `lib` as arguments # check can be disabled while calling this file is called @@ -21,7 +20,12 @@ # evaluate the extended library with the modules # optionally with any additional modules passed by the user module = lib.evalModules { - specialArgs = extraSpecialArgs // {modulesPath = toString ./.;}; + specialArgs = + extraSpecialArgs + // { + inherit inputs; + modulesPath = toString ./.; + }; modules = concatLists [ nvimModules modules @@ -36,102 +40,11 @@ extraModules)) ]; }; - - # alias to the internal configuration - vimOptions = module.config.vim; - - noBuildPlug = {pname, ...} @ attrs: let - src = inputs."plugin-${attrs.pname}"; - in - { - version = src.shortRev or src.shortDirtyRev or "dirty"; - outPath = src; - passthru.vimPlugin = false; - } - // attrs; - - # build a vim plugin with the given name and arguments - # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug - # instead - buildPlug = attrs: let - src = inputs."plugin-${attrs.pname}"; - in - pkgs.vimUtils.buildVimPlugin ( - { - version = src.shortRev or src.shortDirtyRev or "dirty"; - inherit src; - } - // attrs - ); - - buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); - - pluginBuilders = { - nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars; - flutter-tools-patched = buildPlug { - pname = "flutter-tools"; - patches = [../patches/flutter-tools.patch]; - }; - }; - - buildConfigPlugins = plugins: - map ( - plug: - if (isString plug) - then pluginBuilders.${plug} or (noBuildPlug {pname = plug;}) - else plug - ) (filter (f: f != null) plugins); - - # built (or "normalized") plugins that are modified - builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; - builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins); - - # additional Lua and Python3 packages, mapped to their respective functions - # to conform to the format mnw expects. end user should - # only ever need to pass a list of packages, which are modified - # here - extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; - extraPython3Packages = ps: map (x: ps.${x}) vimOptions.python3Packages; - - # Wrap the user's desired (unwrapped) Neovim package with arguments that'll be used to - # generate a wrapped Neovim package. - neovim-wrapped = inputs.mnw.lib.wrap pkgs { - neovim = vimOptions.package; - plugins = builtStartPlugins ++ builtOptPlugins; - appName = "nvf"; - extraBinPath = vimOptions.extraPackages; - initLua = vimOptions.builtLuaConfigRC; - luaFiles = vimOptions.extraLuaFiles; - - inherit (vimOptions) viAlias vimAlias withRuby withNodeJs withPython3; - inherit extraLuaPackages extraPython3Packages; - }; - - dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC; - # Additional helper scripts for printing and displaying nvf configuration - # in your commandline. - printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; - printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}"; in { inherit (module) options config; inherit (module._module.args) pkgs; # Expose wrapped neovim-package for userspace # or module consumption. - neovim = pkgs.symlinkJoin { - name = "nvf-with-helpers"; - paths = [neovim-wrapped printConfig printConfigPath]; - postBuild = "echo Helpers added"; - - # Allow evaluating vimOptions, i.e., config.vim from the packages' passthru - # attribute. For example, packages.x86_64-linux.neovim.passthru.neovimConfig - # will return the configuration in full. - passthru.neovimConfig = vimOptions; - - meta = - neovim-wrapped.meta - // { - description = "Wrapped Neovim package with helper scripts to print the config (path)"; - }; - }; + neovim = module.config.vim.build.finalPackage; } From f8780947b71cc133204e88e26051ffb97ed2fae3 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 23:05:06 +0100 Subject: [PATCH 05/31] nixos: use proper submodule type for settings --- flake.nix | 2 +- flake/modules/nixos.nix | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 3a177517..095419d5 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ }; nixosModules = { - nvf = import ./flake/modules/nixos.nix self.packages lib; + nvf = import ./flake/modules/nixos.nix self.packages lib inputs; default = self.nixosModules.nvf; neovim-flake = lib.warn '' diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index 022b3d94..b4957700 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -1,5 +1,5 @@ # NixOS module -packages: lib: { +packages: lib: inputs: { config, pkgs, ... @@ -8,15 +8,19 @@ packages: lib: { inherit (lib.modules) mkIf mkOverride mkAliasOptionModule; inherit (lib.lists) optional; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrsOf anything bool; - inherit (lib.nvim) neovimConfiguration; - inherit (lib.nvim.types) anythingConcatLists; + inherit (lib.types) anything bool submoduleWith; cfg = config.programs.nvf; - neovimConfigured = neovimConfiguration { - inherit pkgs; - modules = [cfg.settings]; + nvfModule = submoduleWith { + description = "Nvf module"; + class = "nvf"; + specialArgs = { + inherit pkgs lib inputs; + }; + modules = [ + {imports = import ../../modules/modules.nix {inherit pkgs lib;};} + ]; }; in { imports = [ @@ -55,7 +59,7 @@ in { }; settings = mkOption { - type = attrsOf anythingConcatLists; + type = nvfModule; default = {}; description = "Attribute set of nvf preferences."; example = literalExpression '' @@ -78,7 +82,7 @@ in { }; config = mkIf cfg.enable { - programs.nvf.finalPackage = neovimConfigured.neovim; + programs.nvf.finalPackage = cfg.settings.vim.build.finalPackage; environment = { variables.EDITOR = mkIf cfg.defaultEditor (mkOverride 900 "nvim"); From 27f343029678231f93baa0f87d2e8f84c147549b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 22 Dec 2024 23:00:26 +0100 Subject: [PATCH 06/31] lib: remove anythingConcatLists --- lib/types/custom.nix | 55 +++---------------------------------------- lib/types/default.nix | 2 +- 2 files changed, 4 insertions(+), 53 deletions(-) diff --git a/lib/types/custom.nix b/lib/types/custom.nix index 3d4a2bcb..c42cd2ce 100644 --- a/lib/types/custom.nix +++ b/lib/types/custom.nix @@ -1,57 +1,8 @@ {lib}: let - inherit (lib.options) showOption showFiles getFiles mergeOneOption mergeEqualOption; - inherit (lib.strings) isString isStringLike; - inherit (lib.types) anything attrsOf listOf mkOptionType; - inherit (lib.nvim.types) anythingConcatLists; - inherit (builtins) typeOf isAttrs any head concatLists stringLength match; + inherit (lib.options) mergeEqualOption; + inherit (lib.strings) isString stringLength match; + inherit (lib.types) listOf mkOptionType; in { - # HACK: Does this break anything in our case? - # A modified version of the nixpkgs anything type that concatenates lists - # This isn't the default because the order in which the lists are concatenated depends on the order in which the modules are imported, - # which makes it non-deterministic - anythingConcatLists = - anything - // { - merge = loc: defs: let - getType = value: - if isAttrs value && isStringLike value - then "stringCoercibleSet" - else typeOf value; - - # Throw an error if not all defs have the same type - checkType = getType (head defs).value; - commonType = - if any (def: getType def.value != checkType) defs - then throw "The option `${showOption loc}' has conflicting option types in ${showFiles (getFiles defs)}" - else checkType; - - mergeFunctions = { - # Recursively merge attribute sets - set = (attrsOf anythingConcatLists).merge; - - # Overridden behavior for lists, that concatenates lists - list = _: defs: concatLists (map (e: e.value) defs); - - # This means it's a package, only accept a single definition - stringCoercibleSet = mergeOneOption; - - # This works by passing the argument to the functions, - # and merging their returns values instead - lambda = loc: defs: arg: - anythingConcatLists.merge - (loc ++ [""]) - (map (def: { - inherit (def) file; - value = def.value arg; - }) - defs); - }; - in - # Merge the defs with the correct function from above, if available - # otherwise only allow equal values - (mergeFunctions.${commonType} or mergeEqualOption) loc defs; - }; - mergelessListOf = elemType: let super = listOf elemType; in diff --git a/lib/types/default.nix b/lib/types/default.nix index 73b35956..c1c16715 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -11,5 +11,5 @@ in { inherit (typesDag) dagOf; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; - inherit (customTypes) anythingConcatLists char hexColor mergelessListOf; + inherit (customTypes) char hexColor mergelessListOf; } From fb96ccb85b37e8645e8d9e9a2dd69c13412396c0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 29 Dec 2024 18:20:51 +0100 Subject: [PATCH 07/31] home-manager: remove redundant import module --- flake/modules/home-manager.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index d1e85368..c109e774 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -18,9 +18,7 @@ packages: lib: inputs: { specialArgs = { inherit pkgs lib inputs; }; - modules = [ - {imports = import ../../modules/modules.nix {inherit pkgs lib;};} - ]; + modules = import ../../modules/modules.nix {inherit pkgs lib;}; }; in { imports = [ From 835b775fa9d44b00eed47c29bfc381b8375719af Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 29 Dec 2024 18:25:20 +0100 Subject: [PATCH 08/31] nixos: remove redundant import module --- flake/modules/nixos.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index b4957700..b53d4fc9 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -18,9 +18,7 @@ packages: lib: inputs: { specialArgs = { inherit pkgs lib inputs; }; - modules = [ - {imports = import ../../modules/modules.nix {inherit pkgs lib;};} - ]; + modules = import ../../modules/modules.nix {inherit pkgs lib;}; }; in { imports = [ From 6daec44f40be7a69a34eac0bd6de6fc91665aff9 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 29 Dec 2024 18:46:55 +0100 Subject: [PATCH 09/31] home-manager: use attr for long function args --- flake.nix | 2 +- flake/modules/home-manager.nix | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 095419d5..d6e700aa 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ }; homeManagerModules = { - nvf = import ./flake/modules/home-manager.nix self.packages lib inputs; + nvf = import ./flake/modules/home-manager.nix {inherit lib self;}; default = self.homeManagerModules.nvf; neovim-flake = lib.warn '' diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index c109e774..715f7537 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -1,9 +1,13 @@ # Home Manager module -packages: lib: inputs: { +{ + self, + lib, +}: { config, pkgs, ... }: let + inherit (self) packages inputs; inherit (lib) maintainers; inherit (lib.modules) mkIf mkAliasOptionModule; inherit (lib.lists) optional; From d14c5e57db4bcfceba5633e7507672501971a9d5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 29 Dec 2024 18:47:22 +0100 Subject: [PATCH 10/31] nixos: use attrset for long function args --- flake.nix | 2 +- flake/modules/nixos.nix | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index d6e700aa..c4814296 100644 --- a/flake.nix +++ b/flake.nix @@ -42,7 +42,7 @@ }; nixosModules = { - nvf = import ./flake/modules/nixos.nix self.packages lib inputs; + nvf = import ./flake/modules/nixos.nix {inherit lib self;}; default = self.nixosModules.nvf; neovim-flake = lib.warn '' diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index b53d4fc9..ecc173a1 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -1,9 +1,13 @@ # NixOS module -packages: lib: inputs: { +{ + self, + lib, +}: { config, pkgs, ... }: let + inherit (self) inputs packages; inherit (lib) maintainers; inherit (lib.modules) mkIf mkOverride mkAliasOptionModule; inherit (lib.lists) optional; From 16fc1a7de27d7bb36e4cf7f01450a04327e1edf0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 01:24:06 +0100 Subject: [PATCH 11/31] blink: init --- .../completion/blink-cmp/blink-cmp.nix | 16 ++++++++++++++++ .../plugins/completion/blink-cmp/config.nix | 19 +++++++++++++++++++ .../plugins/completion/blink-cmp/default.nix | 3 +++ modules/plugins/completion/default.nix | 1 + modules/plugins/completion/options.nix | 7 +++++++ 5 files changed, 46 insertions(+) create mode 100644 modules/plugins/completion/blink-cmp/blink-cmp.nix create mode 100644 modules/plugins/completion/blink-cmp/config.nix create mode 100644 modules/plugins/completion/blink-cmp/default.nix create mode 100644 modules/plugins/completion/options.nix diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix new file mode 100644 index 00000000..65abbdf9 --- /dev/null +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -0,0 +1,16 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) listOf string; + inherit (lib.nvim.types) mkPluginSetupOption; +in { + options.vim.autocomplete.blink-cmp = { + enable = mkEnableOption "blink.cmp"; + setupOpts = mkPluginSetupOption "blink.cmp" { + sources = mkOption { + type = listOf string; + description = "List of sources to enable for completion."; + default = ["lsp" "path" "snippets" "buffer"]; + }; + }; + }; +} diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix new file mode 100644 index 00000000..15391a24 --- /dev/null +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -0,0 +1,19 @@ +{ + lib, + config, + ... +}: let + inherit (lib.modules) mkIf; + cfg = config.vim.autocomplete.blink-nvim; +in { + vim = mkIf cfg.enable { + lazy.plugins = [ + { + package = "blink-cmp"; + setupModule = "blink"; + inherit (cfg) setupOpts; + event = ["InsertEnter" "CmdlineEnter"]; + } + ]; + }; +} diff --git a/modules/plugins/completion/blink-cmp/default.nix b/modules/plugins/completion/blink-cmp/default.nix new file mode 100644 index 00000000..b781f3f6 --- /dev/null +++ b/modules/plugins/completion/blink-cmp/default.nix @@ -0,0 +1,3 @@ +{ + imports = [./blink-cmp.nix ./config.nix]; +} diff --git a/modules/plugins/completion/default.nix b/modules/plugins/completion/default.nix index 0cae45f6..0c0a61a0 100644 --- a/modules/plugins/completion/default.nix +++ b/modules/plugins/completion/default.nix @@ -1,5 +1,6 @@ { imports = [ ./nvim-cmp + ./blink-cmp ]; } diff --git a/modules/plugins/completion/options.nix b/modules/plugins/completion/options.nix new file mode 100644 index 00000000..b919b8ae --- /dev/null +++ b/modules/plugins/completion/options.nix @@ -0,0 +1,7 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption; +in { + options.vim.autocomplete = { + enableSharedCmpSources = mkEnableOption "cmp sources that can work in nvim-cmp and blink.cmp"; + }; +} From 593ac3b751792b83f174665b704d512c719edb26 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:00:47 +0100 Subject: [PATCH 12/31] cmp: move source plugin into parent option --- modules/plugins/completion/config.nix | 34 +++++++++ modules/plugins/completion/default.nix | 3 + .../plugins/completion/nvim-cmp/config.nix | 70 ++++++++----------- .../plugins/completion/nvim-cmp/nvim-cmp.nix | 10 +-- modules/plugins/completion/options.nix | 12 +++- 5 files changed, 77 insertions(+), 52 deletions(-) create mode 100644 modules/plugins/completion/config.nix diff --git a/modules/plugins/completion/config.nix b/modules/plugins/completion/config.nix new file mode 100644 index 00000000..809dc3af --- /dev/null +++ b/modules/plugins/completion/config.nix @@ -0,0 +1,34 @@ +{ + lib, + config, + ... +}: let + inherit (builtins) typeOf tryEval; + inherit (lib.modules) mkIf; + inherit (lib.nvim.attrsets) mapListToAttrs; + cfg = config.vim.autocomplete; + + getPluginName = plugin: + if typeOf plugin == "string" + then plugin + else if (plugin ? pname && (tryEval plugin.pname).success) + then plugin.pname + else plugin.name; +in { + vim = mkIf cfg.enableSharedCmpSources { + startPlugins = ["rtp-nvim"]; + lazy.plugins = + mapListToAttrs (package: { + name = getPluginName package; + value = { + inherit package; + lazy = true; + after = '' + local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}') + require("rtp_nvim").source_after_plugin_dir(path) + ''; + }; + }) + cfg.sourcePlugins; + }; +} diff --git a/modules/plugins/completion/default.nix b/modules/plugins/completion/default.nix index 0c0a61a0..2695606c 100644 --- a/modules/plugins/completion/default.nix +++ b/modules/plugins/completion/default.nix @@ -1,5 +1,8 @@ { imports = [ + ./config.nix + ./options.nix + ./nvim-cmp ./blink-cmp ]; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index cfd3e53a..62f6c7d4 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -3,11 +3,10 @@ config, ... }: let - inherit (lib.modules) mkIf mkMerge; + inherit (lib.modules) mkIf; inherit (lib.strings) optionalString; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (builtins) attrNames typeOf tryEval concatStringsSep; borders = config.vim.ui.borders.plugins.nvim-cmp; @@ -24,52 +23,39 @@ in { config = mkIf cfg.enable { vim = { - startPlugins = ["rtp-nvim"]; - lazy.plugins = mkMerge [ - (mapListToAttrs (package: { - name = getPluginName package; - value = { - inherit package; - lazy = true; - after = '' - local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}') - require("rtp_nvim").source_after_plugin_dir(path) - ''; - }; - }) - cfg.sourcePlugins) - { - nvim-cmp = { - package = "nvim-cmp"; - after = '' - ${optionalString luasnipEnable "local luasnip = require('luasnip')"} - local cmp = require("cmp") + autocomplete.enableSharedCmpSources = true; - local kinds = require("cmp.types").lsp.CompletionItemKind - local deprio = function(kind) - return function(e1, e2) - if e1:get_kind() == kind then - return false - end - if e2:get_kind() == kind then - return true - end - return nil + lazy.plugins = { + nvim-cmp = { + package = "nvim-cmp"; + after = '' + ${optionalString luasnipEnable "local luasnip = require('luasnip')"} + local cmp = require("cmp") + + local kinds = require("cmp.types").lsp.CompletionItemKind + local deprio = function(kind) + return function(e1, e2) + if e1:get_kind() == kind then + return false end + if e2:get_kind() == kind then + return true + end + return nil end + end - cmp.setup(${toLuaObject cfg.setupOpts}) + cmp.setup(${toLuaObject cfg.setupOpts}) - ${optionalString config.vim.lazy.enable - (concatStringsSep "\n" (map - (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") - cfg.sourcePlugins))} - ''; + ${optionalString config.vim.lazy.enable + (concatStringsSep "\n" (map + (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") + cfg.sourcePlugins))} + ''; - event = ["InsertEnter" "CmdlineEnter"]; - }; - } - ]; + event = ["InsertEnter" "CmdlineEnter"]; + }; + }; autocomplete.nvim-cmp = { sources = { diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 0c790455..00e8c056 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -4,10 +4,10 @@ ... }: let inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; - inherit (lib.types) str attrsOf nullOr either listOf; + inherit (lib.types) str attrsOf nullOr either; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.binds) mkMappingOption; - inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType; + inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf; inherit (lib.nvim.lua) toLuaObject; inherit (builtins) isString; @@ -107,11 +107,5 @@ in { } ''; }; - - sourcePlugins = mkOption { - type = listOf pluginType; - default = []; - description = "List of source plugins used by nvim-cmp."; - }; }; } diff --git a/modules/plugins/completion/options.nix b/modules/plugins/completion/options.nix index b919b8ae..4066ddf9 100644 --- a/modules/plugins/completion/options.nix +++ b/modules/plugins/completion/options.nix @@ -1,7 +1,15 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) listOf; + inherit (lib.nvim.types) pluginType; in { options.vim.autocomplete = { - enableSharedCmpSources = mkEnableOption "cmp sources that can work in nvim-cmp and blink.cmp"; + enableSharedCmpSources = mkEnableOption "cmp sources shared by nvim-cmp and blink.cmp"; + + cmpSourcePlugins = mkOption { + type = listOf pluginType; + default = []; + description = "List of cmp source plugins."; + }; }; } From 0d0c885d7051f0e9ca4538dcf3153440a745c597 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:48:03 +0100 Subject: [PATCH 13/31] completion: migrate to shared cmp source options --- modules/plugins/assistant/copilot/config.nix | 4 +- .../plugins/completion/nvim-cmp/config.nix | 114 +++++++++--------- modules/plugins/completion/options.nix | 2 +- modules/plugins/lsp/config.nix | 9 +- modules/plugins/lsp/lspkind/config.nix | 3 +- modules/plugins/notes/obsidian/obsidian.nix | 2 +- modules/plugins/snippets/luasnip/config.nix | 4 +- modules/plugins/treesitter/config.nix | 4 +- 8 files changed, 75 insertions(+), 67 deletions(-) diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 37da046f..1a070fe3 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -58,8 +58,8 @@ in { }; }; - autocomplete.nvim-cmp = { - sources = {copilot = "[Copilot]";}; + autocomplete = { + nvim-cmp.sources = {copilot = "[Copilot]";}; sourcePlugins = ["copilot-cmp"]; }; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 62f6c7d4..7745cb21 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -12,6 +12,7 @@ borders = config.vim.ui.borders.plugins.nvim-cmp; cfg = config.vim.autocomplete.nvim-cmp; + autocompleteCfg = config.vim.autocomplete; luasnipEnable = config.vim.snippets.luasnip.enable; getPluginName = plugin: if typeOf plugin == "string" @@ -23,8 +24,6 @@ in { config = mkIf cfg.enable { vim = { - autocomplete.enableSharedCmpSources = true; - lazy.plugins = { nvim-cmp = { package = "nvim-cmp"; @@ -50,74 +49,77 @@ in { ${optionalString config.vim.lazy.enable (concatStringsSep "\n" (map (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") - cfg.sourcePlugins))} + autocompleteCfg.sourcePlugins))} ''; event = ["InsertEnter" "CmdlineEnter"]; }; }; - autocomplete.nvim-cmp = { - sources = { - nvim-cmp = null; - buffer = "[Buffer]"; - path = "[Path]"; - }; - + autocomplete = { + enableSharedCmpSources = true; sourcePlugins = ["cmp-buffer" "cmp-path"]; - setupOpts = { - sources = map (s: {name = s;}) (attrNames cfg.sources); - - window = mkIf borders.enable { - completion.border = borders.style; - documentation.border = borders.style; + nvim-cmp = { + sources = { + nvim-cmp = null; + buffer = "[Buffer]"; + path = "[Path]"; }; - formatting.format = cfg.format; + setupOpts = { + sources = map (s: {name = s;}) (attrNames cfg.sources); - # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section - mapping = { - ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; - ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; - ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; - ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; - ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; + window = mkIf borders.enable { + completion.border = borders.style; + documentation.border = borders.style; + }; - ${mappings.next} = mkLuaInline '' - cmp.mapping(function(fallback) - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end + formatting.format = cfg.format; - if cmp.visible() then - cmp.select_next_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(1) then - luasnip.jump(1) - ''} - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end) - ''; + # `cmp` and `luasnip` are defined above, in the `nvim-cmp` section + mapping = { + ${mappings.complete} = mkLuaInline "cmp.mapping.complete()"; + ${mappings.close} = mkLuaInline "cmp.mapping.abort()"; + ${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)"; + ${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)"; + ${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })"; - ${mappings.previous} = mkLuaInline '' - cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - ${optionalString luasnipEnable '' - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - ''} - else - fallback() - end - end) - ''; + ${mappings.next} = mkLuaInline '' + cmp.mapping(function(fallback) + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + if cmp.visible() then + cmp.select_next_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(1) then + luasnip.jump(1) + ''} + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end) + ''; + + ${mappings.previous} = mkLuaInline '' + cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + ${optionalString luasnipEnable '' + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + ''} + else + fallback() + end + end) + ''; + }; }; }; }; diff --git a/modules/plugins/completion/options.nix b/modules/plugins/completion/options.nix index 4066ddf9..330fbaf4 100644 --- a/modules/plugins/completion/options.nix +++ b/modules/plugins/completion/options.nix @@ -6,7 +6,7 @@ in { options.vim.autocomplete = { enableSharedCmpSources = mkEnableOption "cmp sources shared by nvim-cmp and blink.cmp"; - cmpSourcePlugins = mkOption { + sourcePlugins = mkOption { type = listOf pluginType; default = []; description = "List of cmp source plugins."; diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index e73a5387..e0a6660f 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -11,6 +11,7 @@ cfg = config.vim.lsp; usingNvimCmp = config.vim.autocomplete.nvim-cmp.enable; + usingBlinkCmp = config.vim.autocomplete.blink-cmp.enable; self = import ./module.nix {inherit config lib pkgs;}; mappingDefinitions = self.options.vim.lsp.mappings; @@ -22,8 +23,8 @@ in { config = mkIf cfg.enable { vim = { - autocomplete.nvim-cmp = { - sources = {nvim_lsp = "[LSP]";}; + autocomplete = mkIf usingNvimCmp { + nvim-cmp.sources = {nvim_lsp = "[LSP]";}; sourcePlugins = ["cmp-nvim-lsp"]; }; @@ -170,6 +171,10 @@ in { }, } ''} + + ${optionalString usingBlinkCmp '' + -- TODO + ''} ''; }; }; diff --git a/modules/plugins/lsp/lspkind/config.nix b/modules/plugins/lsp/lspkind/config.nix index 2ef20ff8..bad67125 100644 --- a/modules/plugins/lsp/lspkind/config.nix +++ b/modules/plugins/lsp/lspkind/config.nix @@ -8,11 +8,12 @@ inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.lsp.lspkind; + inherit (config.vim) autocomplete; in { config = mkIf cfg.enable { assertions = [ { - assertion = config.vim.autocomplete.nvim-cmp.enable; + assertion = autocomplete.nvim-cmp.enable || autocomplete.blink-cmp.enable; message = '' While lspkind supports Neovim's native lsp upstream, using that over nvim-cmp isn't recommended, nor supported by nvf. diff --git a/modules/plugins/notes/obsidian/obsidian.nix b/modules/plugins/notes/obsidian/obsidian.nix index 2dae5a9c..ca61583f 100644 --- a/modules/plugins/notes/obsidian/obsidian.nix +++ b/modules/plugins/notes/obsidian/obsidian.nix @@ -48,7 +48,7 @@ in { # If using nvim-cmp, otherwise set to false type = bool; description = "If using nvim-cmp, otherwise set to false"; - default = config.vim.autocomplete.nvim-cmp.enable; + default = config.vim.autocomplete.enableSharedCmpSources; }; }; }; diff --git a/modules/plugins/snippets/luasnip/config.nix b/modules/plugins/snippets/luasnip/config.nix index 927b21fd..2e5df6f5 100644 --- a/modules/plugins/snippets/luasnip/config.nix +++ b/modules/plugins/snippets/luasnip/config.nix @@ -17,8 +17,8 @@ in { }; }; startPlugins = cfg.providers; - autocomplete.nvim-cmp = { - sources = {luasnip = "[LuaSnip]";}; + autocomplete = { + nvim-cmp.sources = {luasnip = "[LuaSnip]";}; sourcePlugins = ["cmp-luasnip"]; }; }; diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 566a716e..b7d8c177 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -20,8 +20,8 @@ in { vim = { startPlugins = ["nvim-treesitter"]; - autocomplete.nvim-cmp = { - sources = {treesitter = "[Treesitter]";}; + autocomplete = { + nvim-cmp.sources = {treesitter = "[Treesitter]";}; sourcePlugins = ["cmp-treesitter"]; }; From aa03de57fd5b29d1a8c8d54e8ee3eb81c4f8727b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:48:28 +0100 Subject: [PATCH 14/31] flake: add plugin blink.cmp --- flake.lock | 17 +++++++++++++++++ flake.nix | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/flake.lock b/flake.lock index 3282f58b..52bb43cd 100644 --- a/flake.lock +++ b/flake.lock @@ -188,6 +188,22 @@ "type": "github" } }, + "plugin-blink-cmp": { + "flake": false, + "locked": { + "lastModified": 1734880418, + "narHash": "sha256-jR9fvo+I51DKYQb+N3nFvQ50N+lvYzfFaQtrn7cxDu4=", + "owner": "saghen", + "repo": "blink.cmp", + "rev": "f93af0f486ada13e8c34f42c911788b9232b811f", + "type": "github" + }, + "original": { + "owner": "saghen", + "repo": "blink.cmp", + "type": "github" + } + }, "plugin-bufdelete-nvim": { "flake": false, "locked": { @@ -2076,6 +2092,7 @@ "nmd": "nmd", "plugin-alpha-nvim": "plugin-alpha-nvim", "plugin-base16": "plugin-base16", + "plugin-blink-cmp": "plugin-blink-cmp", "plugin-bufdelete-nvim": "plugin-bufdelete-nvim", "plugin-catppuccin": "plugin-catppuccin", "plugin-ccc": "plugin-ccc", diff --git a/flake.nix b/flake.nix index c4814296..f9669a23 100644 --- a/flake.nix +++ b/flake.nix @@ -288,6 +288,11 @@ flake = false; }; + plugin-blink-cmp = { + url = "github:saghen/blink.cmp"; + flake = false; + }; + plugin-nvim-cmp = { url = "github:hrsh7th/nvim-cmp"; flake = false; From 110b6dbd1864887bc73ea1af61a76407164af244 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:51:21 +0100 Subject: [PATCH 15/31] blink: basic keymap option --- .../completion/blink-cmp/blink-cmp.nix | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 65abbdf9..8b1aeb9c 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,15 +1,37 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) listOf string; - inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.options) mkEnableOption mkOption literalMD; + inherit (lib.types) listOf str either oneOf attrsOf; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; in { options.vim.autocomplete.blink-cmp = { enable = mkEnableOption "blink.cmp"; setupOpts = mkPluginSetupOption "blink.cmp" { - sources = mkOption { - type = listOf string; - description = "List of sources to enable for completion."; - default = ["lsp" "path" "snippets" "buffer"]; + sources = { + default = mkOption { + type = listOf str; + description = "Default list of sources to enable for completion."; + default = ["lsp" "path" "snippets" "buffer"]; + }; + }; + + keymap = mkOption { + type = attrsOf (oneOf [luaInline str (listOf (either str luaInline))]); + default = {}; + description = "blink.cmp keymap"; + example = literalMD '' + ```nix + "" = ["select_prev" "fallback"]; + "" = [ + (lib.generators.mkLuaInline '''' + function(cmp) + if some_condition then return end -- runs the next command + return true -- doesn't run the next command + end, + '''') + "select_next" + ]; + ``` + ''; }; }; }; From c94cf9a47c135fd88132e7399d99fc5829656241 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 02:51:53 +0100 Subject: [PATCH 16/31] blink: add luasnip integration --- .../plugins/completion/blink-cmp/config.nix | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 15391a24..663e19c5 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -4,16 +4,38 @@ ... }: let inherit (lib.modules) mkIf; - cfg = config.vim.autocomplete.blink-nvim; + inherit (lib.generators) mkLuaInline; + cfg = config.vim.autocomplete.blink-cmp; in { vim = mkIf cfg.enable { - lazy.plugins = [ - { - package = "blink-cmp"; - setupModule = "blink"; - inherit (cfg) setupOpts; - event = ["InsertEnter" "CmdlineEnter"]; - } - ]; + lazy.plugins.blink-cmp = { + package = "blink-cmp"; + setupModule = "blink.cmp"; + inherit (cfg) setupOpts; + event = ["InsertEnter" "CmdlineEnter"]; + }; + + autocomplete = { + enableSharedCmpSources = true; + + blink-cmp.setupOpts = { + snippets = mkIf config.vim.snippets.luasnip.enable { + expand = mkLuaInline '' + function(snippet) + return require("luasnip").lsp_expand(snippet) + end + ''; + active = mkLuaInline '' + function(filter) + if filter and filter.direction then + return require('luasnip').jumpable(filter.direction) + end + return require('luasnip').in_snippet() + end + ''; + jump = mkLuaInline "function(direction) require('luasnip').jump(direction) end"; + }; + }; + }; }; } From f2836a687eda94def302d25b2d04b9031981cad1 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 03:59:57 +0100 Subject: [PATCH 17/31] blink: keymap wrapper --- .../completion/blink-cmp/blink-cmp.nix | 50 ++++++++++++++----- .../plugins/completion/blink-cmp/config.nix | 31 ++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 8b1aeb9c..a55dd43d 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,7 +1,19 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalMD; - inherit (lib.types) listOf str either oneOf attrsOf; + inherit (lib.types) listOf str either attrsOf submodule enum; inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.nvim.binds) mkMappingOption; + + keymapType = submodule { + freeformType = attrsOf (listOf (either str luaInline)); + options = { + preset = mkOption { + type = enum ["default" "none" "super-tab" "enter"]; + default = "none"; + description = "keymap presets"; + }; + }; + }; in { options.vim.autocomplete.blink-cmp = { enable = mkEnableOption "blink.cmp"; @@ -15,24 +27,38 @@ in { }; keymap = mkOption { - type = attrsOf (oneOf [luaInline str (listOf (either str luaInline))]); + type = keymapType; default = {}; description = "blink.cmp keymap"; example = literalMD '' ```nix - "" = ["select_prev" "fallback"]; - "" = [ - (lib.generators.mkLuaInline '''' - function(cmp) - if some_condition then return end -- runs the next command - return true -- doesn't run the next command - end, - '''') - "select_next" - ]; + vim.autocomplete.blink-cmp.setupOpts.keymap = { + preset = "none"; + + "" = ["select_prev" "fallback"]; + "" = [ + (lib.generators.mkLuaInline '''' + function(cmp) + if some_condition then return end -- runs the next command + return true -- doesn't run the next command + end, + '''') + "select_next" + ]; + }; ``` ''; }; }; + + mappings = { + complete = mkMappingOption "Complete [blink.cmp]" ""; + confirm = mkMappingOption "Confirm [blink.cmp]" ""; + next = mkMappingOption "Next item [blink.cmp]" ""; + previous = mkMappingOption "Previous item [blink.cmp]" ""; + close = mkMappingOption "Close [blink.cmp]" ""; + scrollDocsUp = mkMappingOption "Scroll docs up [blink.cmp]" ""; + scrollDocsDown = mkMappingOption "Scroll docs down [blink.cmp]" ""; + }; }; } diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 663e19c5..233fff3d 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -5,7 +5,9 @@ }: let inherit (lib.modules) mkIf; inherit (lib.generators) mkLuaInline; + cfg = config.vim.autocomplete.blink-cmp; + inherit (cfg) mappings; in { vim = mkIf cfg.enable { lazy.plugins.blink-cmp = { @@ -35,6 +37,35 @@ in { ''; jump = mkLuaInline "function(direction) require('luasnip').jump(direction) end"; }; + + keymap = { + ${mappings.complete} = ["show" "fallback"]; + ${mappings.close} = ["hide" "fallback"]; + ${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"]; + ${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"]; + ${mappings.confirm} = ["accept" "fallback"]; + + ${mappings.next} = [ + "select_next" + "snippet_forward" + (mkLuaInline '' + function(cmp) + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + + if has_words_before then + return cmp.show() + end + end + '') + "fallback" + ]; + ${mappings.previous} = [ + "select_prev" + "snippet_backward" + "fallback" + ]; + }; }; }; }; From c52a4c7ebca4609443c4be1e5f3d571565d9bac5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 04:02:08 +0100 Subject: [PATCH 18/31] lsp: use blink.cmp capabilities --- modules/plugins/lsp/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index e0a6660f..550f7cc7 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -173,7 +173,7 @@ in { ''} ${optionalString usingBlinkCmp '' - -- TODO + capabilities = require('blink.cmp').get_lsp_capabilities(capabilities) ''} ''; }; From b4711f8685a3c3b62b8b2ec19df927491ef1d8dd Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 04:02:20 +0100 Subject: [PATCH 19/31] blink: disable lazy-loading --- modules/plugins/completion/blink-cmp/config.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 233fff3d..50fe4563 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -14,7 +14,9 @@ in { package = "blink-cmp"; setupModule = "blink.cmp"; inherit (cfg) setupOpts; - event = ["InsertEnter" "CmdlineEnter"]; + # TODO: lazy disabled until lspconfig is lazy loaded + # + # event = ["InsertEnter" "CmdlineEnter"]; }; autocomplete = { From 358ea4b8029076f82930c052a1808474615813f6 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 19:06:19 +0100 Subject: [PATCH 20/31] flake: add blink.compat --- flake.lock | 17 +++++++++++++++++ flake.nix | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/flake.lock b/flake.lock index 52bb43cd..da4eaa54 100644 --- a/flake.lock +++ b/flake.lock @@ -204,6 +204,22 @@ "type": "github" } }, + "plugin-blink-compat": { + "flake": false, + "locked": { + "lastModified": 1734896240, + "narHash": "sha256-Rrrh+O3FbBnaAnCHwPuQyfhH+XueSkQp6ipEkn6esGY=", + "owner": "saghen", + "repo": "blink.compat", + "rev": "74b251a1e9478c4fa6d7c6bc2921d7124e6f6cbb", + "type": "github" + }, + "original": { + "owner": "saghen", + "repo": "blink.compat", + "type": "github" + } + }, "plugin-bufdelete-nvim": { "flake": false, "locked": { @@ -2093,6 +2109,7 @@ "plugin-alpha-nvim": "plugin-alpha-nvim", "plugin-base16": "plugin-base16", "plugin-blink-cmp": "plugin-blink-cmp", + "plugin-blink-compat": "plugin-blink-compat", "plugin-bufdelete-nvim": "plugin-bufdelete-nvim", "plugin-catppuccin": "plugin-catppuccin", "plugin-ccc": "plugin-ccc", diff --git a/flake.nix b/flake.nix index f9669a23..a6cf88bf 100644 --- a/flake.nix +++ b/flake.nix @@ -293,6 +293,11 @@ flake = false; }; + plugin-blink-compat = { + url = "github:saghen/blink.compat"; + flake = false; + }; + plugin-nvim-cmp = { url = "github:hrsh7th/nvim-cmp"; flake = false; From a8334ee719fd84ea0e765696929ee8795960557c Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 20:27:03 +0100 Subject: [PATCH 21/31] blink: add blink.compat support --- .../completion/blink-cmp/blink-cmp.nix | 18 ++++++- .../plugins/completion/blink-cmp/config.nix | 47 +++++++++++++++---- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index a55dd43d..7ca36f57 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,6 +1,6 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalMD; - inherit (lib.types) listOf str either attrsOf submodule enum; + inherit (lib.types) listOf str either attrsOf submodule enum anything; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.binds) mkMappingOption; @@ -14,6 +14,16 @@ }; }; }; + + providerType = submodule { + freeformType = anything; + options = { + module = mkOption { + type = str; + description = "module of the provider"; + }; + }; + }; in { options.vim.autocomplete.blink-cmp = { enable = mkEnableOption "blink.cmp"; @@ -24,6 +34,12 @@ in { description = "Default list of sources to enable for completion."; default = ["lsp" "path" "snippets" "buffer"]; }; + + providers = mkOption { + type = attrsOf providerType; + description = "Providers"; + default = {}; + }; }; keymap = mkOption { diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 50fe4563..295fbde2 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -3,26 +3,57 @@ config, ... }: let - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkDefault; + inherit (lib.strings) optionalString; inherit (lib.generators) mkLuaInline; + inherit (lib.nvim.lua) toLuaObject; + inherit (builtins) concatStringsSep typeOf tryEval attrNames mapAttrs; cfg = config.vim.autocomplete.blink-cmp; + autocompleteCfg = config.vim.autocomplete; inherit (cfg) mappings; + + getPluginName = plugin: + if typeOf plugin == "string" + then plugin + else if (plugin ? pname && (tryEval plugin.pname).success) + then plugin.pname + else plugin.name; in { vim = mkIf cfg.enable { - lazy.plugins.blink-cmp = { - package = "blink-cmp"; - setupModule = "blink.cmp"; - inherit (cfg) setupOpts; - # TODO: lazy disabled until lspconfig is lazy loaded - # - # event = ["InsertEnter" "CmdlineEnter"]; + startPlugins = ["blink-compat"]; + lazy.plugins = { + blink-cmp = { + package = "blink-cmp"; + setupModule = "blink.cmp"; + inherit (cfg) setupOpts; + + # TODO: lazy disabled until lspconfig is lazy loaded + # + # event = ["InsertEnter" "CmdlineEnter"]; + + after = '' + ${optionalString config.vim.lazy.enable + (concatStringsSep "\n" (map + (package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") + autocompleteCfg.sourcePlugins))} + ''; + }; }; autocomplete = { enableSharedCmpSources = true; blink-cmp.setupOpts = { + sources = { + default = mkDefault (attrNames autocompleteCfg.nvim-cmp.sources); + providers = + mapAttrs (name: _: { + inherit name; + module = "blink.compat.source"; + }) + autocompleteCfg.nvim-cmp.sources; + }; snippets = mkIf config.vim.snippets.luasnip.enable { expand = mkLuaInline '' function(snippet) From 85efe03d39c5688cceaf76e6547865a7fdd750cd Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 20:27:27 +0100 Subject: [PATCH 22/31] treesitter-cmp: disable on blink.cmp --- modules/plugins/treesitter/config.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index b7d8c177..fcae3c5c 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -20,7 +20,8 @@ in { vim = { startPlugins = ["nvim-treesitter"]; - autocomplete = { + # cmp-treesitter doesn't work on blink.cmp + autocomplete = mkIf config.vim.autocomplete.nvim-cmp.enable { nvim-cmp.sources = {treesitter = "[Treesitter]";}; sourcePlugins = ["cmp-treesitter"]; }; From 9b9ed537b32d6f87755a8290ea6618c5d7a2afc5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 20:32:48 +0100 Subject: [PATCH 23/31] blink: re-add default sources to cmp ones --- modules/plugins/completion/blink-cmp/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/completion/blink-cmp/config.nix b/modules/plugins/completion/blink-cmp/config.nix index 295fbde2..97f45fdb 100644 --- a/modules/plugins/completion/blink-cmp/config.nix +++ b/modules/plugins/completion/blink-cmp/config.nix @@ -46,7 +46,7 @@ in { blink-cmp.setupOpts = { sources = { - default = mkDefault (attrNames autocompleteCfg.nvim-cmp.sources); + default = ["lsp" "path" "snippets" "buffer"] ++ (attrNames autocompleteCfg.nvim-cmp.sources); providers = mapAttrs (name: _: { inherit name; From a996811955e6b5c03b4d30786a0a6ba861ef06cd Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 20:45:17 +0100 Subject: [PATCH 24/31] blink: auto-show docs by default --- .../plugins/completion/blink-cmp/blink-cmp.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 7ca36f57..5a374940 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,8 +1,9 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalMD; - inherit (lib.types) listOf str either attrsOf submodule enum anything; + inherit (lib.types) listOf str either attrsOf submodule enum anything int; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.config) mkBool; keymapType = submodule { freeformType = attrsOf (listOf (either str luaInline)); @@ -31,14 +32,25 @@ in { sources = { default = mkOption { type = listOf str; - description = "Default list of sources to enable for completion."; default = ["lsp" "path" "snippets" "buffer"]; + description = "Default list of sources to enable for completion."; }; providers = mkOption { type = attrsOf providerType; - description = "Providers"; default = {}; + description = "Providers"; + }; + }; + + completion = { + documentation = { + auto_show = mkBool true "Show documentation whenever an item is selected"; + auto_show_delay_ms = mkOption { + type = int; + default = 200; + description = "Delay before auto show triggers"; + }; }; }; From 1fe5b6d6c0cf5efecc8846a9aa9d3aa14da4b8ac Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Mon, 23 Dec 2024 23:20:22 +0100 Subject: [PATCH 25/31] docs: udpate release notes --- docs/release-notes/rl-0.8.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 567e4e6e..0ab868aa 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -15,6 +15,12 @@ - Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim]. +[horriblename](https://github.com/horriblename): + +[blink.cmp]: https://github.com/saghen/blink.cmp + +- Add [blink.cmp] support + [diniamo](https://github.com/diniamo): - Add Odin support under `vim.languages.odin`. From d31ab256f9138ff6ba99b5db401883ed48fbeec8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 26 Dec 2024 05:05:26 +0100 Subject: [PATCH 26/31] lspsignature: add assertion against blink.cmp --- modules/plugins/lsp/lsp-signature/config.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/plugins/lsp/lsp-signature/config.nix b/modules/plugins/lsp/lsp-signature/config.nix index c9940534..535b2534 100644 --- a/modules/plugins/lsp/lsp-signature/config.nix +++ b/modules/plugins/lsp/lsp-signature/config.nix @@ -10,6 +10,16 @@ cfg = config.vim.lsp; in { config = mkIf (cfg.enable && cfg.lspSignature.enable) { + assertions = [ + { + assertion = !config.vim.autocomplete.blink-cmp.enable; + message = '' + lsp-signature does not work with blink.cmp. Please use blink.cmp's builtin signature feature: + + vim.autocomplete.blink-cmp.setupOpts.signature.enabled = true; + ''; + } + ]; vim = { startPlugins = [ "lsp-signature" From 96e66e5ea20efccb114f10b416ffc254ce1150cf Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 26 Dec 2024 05:23:19 +0100 Subject: [PATCH 27/31] blink: do not inherit vim's lsp capabilities --- modules/plugins/lsp/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/lsp/config.nix b/modules/plugins/lsp/config.nix index 550f7cc7..f91b379f 100644 --- a/modules/plugins/lsp/config.nix +++ b/modules/plugins/lsp/config.nix @@ -173,7 +173,7 @@ in { ''} ${optionalString usingBlinkCmp '' - capabilities = require('blink.cmp').get_lsp_capabilities(capabilities) + capabilities = require('blink.cmp').get_lsp_capabilities() ''} ''; }; From d130845ba14cf5171c5a56657486ede22112c6c2 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 26 Dec 2024 05:38:31 +0100 Subject: [PATCH 28/31] blink: disable cmdline completion --- modules/plugins/completion/blink-cmp/blink-cmp.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index 5a374940..d5839201 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -36,6 +36,12 @@ in { description = "Default list of sources to enable for completion."; }; + cmdline = mkOption { + type = listOf str; + default = []; + description = "List of sources to enable for cmdline"; + }; + providers = mkOption { type = attrsOf providerType; default = {}; From 18e4810a86f0d88d9a6ded3582510c9086c1eb09 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 29 Dec 2024 02:29:18 +0100 Subject: [PATCH 29/31] blink: allow null sources.cmdline --- modules/plugins/completion/blink-cmp/blink-cmp.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/completion/blink-cmp/blink-cmp.nix b/modules/plugins/completion/blink-cmp/blink-cmp.nix index d5839201..021441b2 100644 --- a/modules/plugins/completion/blink-cmp/blink-cmp.nix +++ b/modules/plugins/completion/blink-cmp/blink-cmp.nix @@ -1,6 +1,6 @@ {lib, ...}: let inherit (lib.options) mkEnableOption mkOption literalMD; - inherit (lib.types) listOf str either attrsOf submodule enum anything int; + inherit (lib.types) listOf str either attrsOf submodule enum anything int nullOr; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.config) mkBool; @@ -37,9 +37,9 @@ in { }; cmdline = mkOption { - type = listOf str; + type = nullOr (listOf str); default = []; - description = "List of sources to enable for cmdline"; + description = "List of sources to enable for cmdline. Null means use default source list."; }; providers = mkOption { From 8622fd6871edda38fa93bc0029233481a057daeb Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 1 Jan 2025 11:31:22 +0100 Subject: [PATCH 30/31] flake: expose blink-cmp package --- flake/packages.nix | 7 +++++++ flake/packages/blink-cmp.nix | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 flake/packages/blink-cmp.nix diff --git a/flake/packages.nix b/flake/packages.nix index cf1f81ac..39d75ca1 100644 --- a/flake/packages.nix +++ b/flake/packages.nix @@ -6,6 +6,7 @@ ... }: let docs = import ../docs {inherit pkgs inputs lib;}; + pluginVersion = src: src.shortRev or src.shortDirtyRev or "dirty"; in { packages = { inherit (docs.manual) htmlOpenTool; @@ -66,6 +67,12 @@ Volumes = {"/home/neovim/demo" = {};}; }; }; + + # Plugins that need compiling + blink-cmp = pkgs.callPackage ./packages/blink-cmp.nix { + src = inputs.plugin-blink-cmp; + version = pluginVersion inputs.plugin-blink-cmp; + }; }; }; } diff --git a/flake/packages/blink-cmp.nix b/flake/packages/blink-cmp.nix new file mode 100644 index 00000000..f945249a --- /dev/null +++ b/flake/packages/blink-cmp.nix @@ -0,0 +1,35 @@ +{ + rustPlatform, + hostPlatform, + vimUtils, + src, + version, +}: let + blink-fuzzy-lib = rustPlatform.buildRustPackage { + pname = "blink-fuzzy-lib"; + inherit version src; + + env = { + # TODO: remove this if plugin stops using nightly rust + RUSTC_BOOTSTRAP = true; + }; + cargoLock = { + lockFile = "${src}/Cargo.lock"; + outputHashes = { + "frizbee-0.1.0" = "sha256-pt6sMsRyjXrbrTK7t/YvWeen/n3nU8UUaiNYTY1LczE="; + }; + }; + }; + libExt = + if hostPlatform.isDarwin + then "dylib" + else "so"; +in + vimUtils.buildVimPlugin { + pname = "blink-cmp"; + inherit version src; + preInstall = '' + mkdir -p target/release + ln -s ${blink-fuzzy-lib}/lib/libblink_cmp_fuzzy.${libExt} target/release/libblink_cmp_fuzzy.${libExt} + ''; + } From 460232765dc7ca535bee1495141ee365bcf43493 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 1 Jan 2025 11:07:29 +0100 Subject: [PATCH 31/31] build: use custom-built blink.cmp --- modules/wrapper/build/config.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/wrapper/build/config.nix b/modules/wrapper/build/config.nix index 85c87dd6..c36a0888 100644 --- a/modules/wrapper/build/config.nix +++ b/modules/wrapper/build/config.nix @@ -45,6 +45,11 @@ pname = "flutter-tools"; patches = [../patches/flutter-tools.patch]; }; + blink-cmp = pkgs.callPackage ../../../flake/packages/blink-cmp.nix { + src = inputs.plugin-blink-cmp; + # TODO: extract into helper func + version = inputs.plugin-blink-cmp.shortRev or inputs.plugin-blink-cmp.shortDirtyRev or "dirty"; + }; }; buildConfigPlugins = plugins: