wrapper: add built package as option

This commit is contained in:
Ching Pei Yang 2024-12-22 21:49:11 +01:00 committed by raf
commit 26398b6b14
5 changed files with 130 additions and 0 deletions

View file

@ -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;
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./options.nix
./config.nix
];
}

View file

@ -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";
};
};
}

View file

@ -0,0 +1,41 @@
diff --git a/lua/flutter-tools/executable.lua b/lua/flutter-tools/executable.lua
index 3807a4f..3345760 100644
--- a/lua/flutter-tools/executable.lua
+++ b/lua/flutter-tools/executable.lua
@@ -31,12 +31,12 @@ local function _dart_sdk_root(paths)
end
if utils.executable("flutter") then
- local flutter_path = fn.resolve(fn.exepath("flutter"))
+ local flutter_path = fn.exepath("flutter")
local flutter_bin = fn.fnamemodify(flutter_path, ":h")
return path.join(flutter_bin, dart_sdk)
end
- if utils.executable("dart") then return fn.resolve(fn.exepath("dart")) end
+ if utils.executable("dart") then return fn.exepath("dart") end
return ""
end
@@ -50,10 +50,10 @@ end
---Get paths for flutter and dart based on the binary locations
---@return table<string, string>
local function get_default_binaries()
- local flutter_bin = fn.resolve(fn.exepath("flutter"))
+ local flutter_bin = fn.exepath("flutter")
return {
flutter_bin = flutter_bin,
- dart_bin = fn.resolve(fn.exepath("dart")),
+ dart_bin = fn.exepath("dart"),
flutter_sdk = _flutter_sdk_root(flutter_bin),
}
end
@@ -119,7 +119,7 @@ function M.get(callback)
end
if config.flutter_path then
- local flutter_path = fn.resolve(config.flutter_path)
+ local flutter_path = config.flutter_path
_paths = { flutter_bin = flutter_path, flutter_sdk = _flutter_sdk_root(flutter_path) }
_paths.dart_sdk = _dart_sdk_root(_paths)
_paths.dart_bin = _flutter_sdk_dart_bin(_paths.flutter_sdk)