nix-community.nixvim/lib/vim-plugin.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

147 lines
4.7 KiB
Nix
Raw Permalink Normal View History

{ lib }:
{
mkVimPlugin =
2024-05-05 19:39:35 +02:00
{
name,
url ? throw "default",
maintainers,
imports ? [ ],
description ? null,
# deprecations
deprecateExtraConfig ? false,
optionsRenamedToSettings ? [ ],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
# Can be a string, a list of strings, or a module option:
# - A string will be intrpreted as `pkgs.vimPlugins.${package}`
# - A list will be interpreted as a "pkgs path", e.g. `pkgs.${elem1}.${elem2}.${etc...}`
# - An option will be used as-is, but should be built using `lib.mkPackageOption`
# Defaults to `name`, i.e. `pkgs.vimPlugins.${name}`
package ? name,
settingsOptions ? { },
settingsExample ? null,
globalPrefix ? "",
extraOptions ? { },
# config
extraConfig ? cfg: { },
extraPlugins ? [ ],
extraPackages ? [ ],
}@args:
let
namespace = if isColorscheme then "colorschemes" else "plugins";
2024-08-30 14:49:20 -05:00
createSettingsOption = (lib.isString globalPrefix) && (globalPrefix != "");
2024-08-30 14:49:20 -05:00
settingsOption = lib.optionalAttrs createSettingsOption {
settings = lib.nixvim.mkSettingsOption {
options = settingsOptions;
example = settingsExample;
description = ''
The configuration options for **${name}** without the `${globalPrefix}` prefix.
For example, the following settings are equivialent to these `:setglobal` commands:
- `foo_bar = 1` -> `:setglobal ${globalPrefix}foo_bar=1`
- `hello = "world"` -> `:setglobal ${globalPrefix}hello="world"`
- `some_toggle = true` -> `:setglobal ${globalPrefix}some_toggle`
- `other_toggle = false` -> `:setglobal no${globalPrefix}other_toggle`
'';
};
};
module =
{
config,
options,
pkgs,
...
}:
let
cfg = config.${namespace}.${name};
opts = options.${namespace}.${name};
in
{
meta = {
inherit maintainers;
nixvimInfo = {
inherit description;
url = args.url or opts.package.default.meta.homepage;
path = [
namespace
name
];
};
};
flake.lock: Update Flake lock file updates: • Updated input 'flake-parts': 'github:hercules-ci/flake-parts/506278e768c2a08bec68eb62932193e341f55c90?narHash=sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS%2Bb4tfNFCwE%3D' (2024-11-01) → 'github:hercules-ci/flake-parts/205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9?narHash=sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c%3D' (2024-12-04) • Updated input 'git-hooks': 'github:cachix/git-hooks.nix/3308484d1a443fc5bc92012435d79e80458fe43c?narHash=sha256-mnTbjpdqF0luOkou8ZFi2asa1N3AA2CchR/RqCNmsGE%3D' (2024-11-19) → 'github:cachix/git-hooks.nix/6f4e2a2112050951a314d2733a994fbab94864c6?narHash=sha256-SVQVsbafSM1dJ4fpgyBqLZ%2BLft%2BjcQuMtEL3lQWx2Sk%3D' (2024-12-04) • Updated input 'home-manager': 'github:nix-community/home-manager/62d536255879be574ebfe9b87c4ac194febf47c5?narHash=sha256-lYnT%2BEYE47f5yY3KS/Kd4pJ6CO9fhCqumkYYkQ3TK20%3D' (2024-12-01) → 'github:nix-community/home-manager/c7ffc9727d115e433fd884a62dc164b587ff651d?narHash=sha256-zjO6m5BqxXIyjrnUziAzk4%2BT4VleqjstNudSqWcpsHI%3D' (2024-12-07) • Updated input 'nix-darwin': 'github:lnl7/nix-darwin/c6b65d946097baf3915dd51373251de98199280d?narHash=sha256-Qs3YmoLYUJ8g4RkFj2rMrzrP91e4ShAioC9s%2BvG6ENM%3D' (2024-12-02) → 'github:lnl7/nix-darwin/a35b08d09efda83625bef267eb24347b446c80b8?narHash=sha256-sQJAxY1TYWD1UyibN/FnN97paTFuwBw3Vp3DNCyKsMk%3D' (2024-12-07) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/f9f0d5c5380be0a599b1fb54641fa99af8281539?narHash=sha256-En%2BgSoVJ3iQKPDU1FHrR6zIxSLXKjzKY%2Bpnh9tt%2BYts%3D' (2024-12-02) → 'github:NixOS/nixpkgs/4dc2fc4e62dbf62b84132fe526356fbac7b03541?narHash=sha256-FillH0qdWDt/nlO6ED7h4cmN%2BG9uXwGjwmCnHs0QVYM%3D' (2024-12-05) • Updated input 'nuschtosSearch': 'github:NuschtOS/search/16307548b7a1247291c84ae6a12c0aacb07dfba2?narHash=sha256-BC1CecAQISV5Q4LZK72Gx0%2BfaemOwaChiD9rMVfDPoA%3D' (2024-11-30) → 'github:NuschtOS/search/68e9fad70d95d08156cf10a030bd39487bed8ffe?narHash=sha256-315rJ7O9cOllPDaFscnJhcMleORHbxon0Kq9LAKJ5p4%3D' (2024-12-05) • Updated input 'treefmt-nix': 'github:numtide/treefmt-nix/6209c381904cab55796c5d7350e89681d3b2a8ef?narHash=sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII%2BoAc%3D' (2024-11-29) → 'github:numtide/treefmt-nix/50862ba6a8a0255b87377b9d2d4565e96f29b410?narHash=sha256-qKL3vjO%2BIXFQ0nTinFDqNq/sbbnnS5bMI1y0xX215fU%3D' (2024-12-05)
2024-12-07 12:35:11 +00:00
options.${namespace}.${name} =
{
enable = lib.mkEnableOption originalName;
package =
if lib.isOption package then
package
else
lib.mkPackageOption pkgs originalName {
default =
if builtins.isList package then
package
flake.lock: Update Flake lock file updates: • Updated input 'flake-parts': 'github:hercules-ci/flake-parts/506278e768c2a08bec68eb62932193e341f55c90?narHash=sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS%2Bb4tfNFCwE%3D' (2024-11-01) → 'github:hercules-ci/flake-parts/205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9?narHash=sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c%3D' (2024-12-04) • Updated input 'git-hooks': 'github:cachix/git-hooks.nix/3308484d1a443fc5bc92012435d79e80458fe43c?narHash=sha256-mnTbjpdqF0luOkou8ZFi2asa1N3AA2CchR/RqCNmsGE%3D' (2024-11-19) → 'github:cachix/git-hooks.nix/6f4e2a2112050951a314d2733a994fbab94864c6?narHash=sha256-SVQVsbafSM1dJ4fpgyBqLZ%2BLft%2BjcQuMtEL3lQWx2Sk%3D' (2024-12-04) • Updated input 'home-manager': 'github:nix-community/home-manager/62d536255879be574ebfe9b87c4ac194febf47c5?narHash=sha256-lYnT%2BEYE47f5yY3KS/Kd4pJ6CO9fhCqumkYYkQ3TK20%3D' (2024-12-01) → 'github:nix-community/home-manager/c7ffc9727d115e433fd884a62dc164b587ff651d?narHash=sha256-zjO6m5BqxXIyjrnUziAzk4%2BT4VleqjstNudSqWcpsHI%3D' (2024-12-07) • Updated input 'nix-darwin': 'github:lnl7/nix-darwin/c6b65d946097baf3915dd51373251de98199280d?narHash=sha256-Qs3YmoLYUJ8g4RkFj2rMrzrP91e4ShAioC9s%2BvG6ENM%3D' (2024-12-02) → 'github:lnl7/nix-darwin/a35b08d09efda83625bef267eb24347b446c80b8?narHash=sha256-sQJAxY1TYWD1UyibN/FnN97paTFuwBw3Vp3DNCyKsMk%3D' (2024-12-07) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/f9f0d5c5380be0a599b1fb54641fa99af8281539?narHash=sha256-En%2BgSoVJ3iQKPDU1FHrR6zIxSLXKjzKY%2Bpnh9tt%2BYts%3D' (2024-12-02) → 'github:NixOS/nixpkgs/4dc2fc4e62dbf62b84132fe526356fbac7b03541?narHash=sha256-FillH0qdWDt/nlO6ED7h4cmN%2BG9uXwGjwmCnHs0QVYM%3D' (2024-12-05) • Updated input 'nuschtosSearch': 'github:NuschtOS/search/16307548b7a1247291c84ae6a12c0aacb07dfba2?narHash=sha256-BC1CecAQISV5Q4LZK72Gx0%2BfaemOwaChiD9rMVfDPoA%3D' (2024-11-30) → 'github:NuschtOS/search/68e9fad70d95d08156cf10a030bd39487bed8ffe?narHash=sha256-315rJ7O9cOllPDaFscnJhcMleORHbxon0Kq9LAKJ5p4%3D' (2024-12-05) • Updated input 'treefmt-nix': 'github:numtide/treefmt-nix/6209c381904cab55796c5d7350e89681d3b2a8ef?narHash=sha256-2qbdorpq0TXHBWbVXaTqKoikN4bqAtAplTwGuII%2BoAc%3D' (2024-11-29) → 'github:numtide/treefmt-nix/50862ba6a8a0255b87377b9d2d4565e96f29b410?narHash=sha256-qKL3vjO%2BIXFQ0nTinFDqNq/sbbnnS5bMI1y0xX215fU%3D' (2024-12-05)
2024-12-07 12:35:11 +00:00
else
[
"vimPlugins"
package
];
};
packageDecorator = lib.mkOption {
type = lib.types.functionTo lib.types.package;
default = lib.id;
defaultText = lib.literalExpression "x: x";
description = ''
Additional transformations to apply to the final installed package.
The result of these transformations is **not** visible in the `package` option's value.
'';
internal = true;
};
}
// settingsOption
// extraOptions;
2024-08-30 14:49:20 -05:00
config = lib.mkIf cfg.enable (
lib.mkMerge [
{
inherit extraPackages;
extraPlugins = extraPlugins ++ [
(cfg.packageDecorator cfg.package)
];
2024-08-30 14:49:20 -05:00
globals = lib.mapAttrs' (n: lib.nameValuePair (globalPrefix + n)) (cfg.settings or { });
}
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
colorscheme = lib.mkDefault colorscheme;
})
(lib.optionalAttrs (args ? extraConfig) (
lib.nixvim.modules.applyExtraConfig {
inherit extraConfig cfg opts;
}
))
2024-08-30 14:49:20 -05:00
]
);
};
in
{
imports =
let
basePluginPath = [
namespace
name
];
settingsPath = basePluginPath ++ [ "settings" ];
in
imports
++ [ module ]
2024-08-30 14:49:20 -05:00
++ (lib.optional (deprecateExtraConfig && createSettingsOption) (
lib.mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
))
2024-08-30 14:49:20 -05:00
++ (lib.nixvim.mkSettingsRenamedOptionModules basePluginPath settingsPath optionsRenamedToSettings);
};
}