treewide: Reformat with nixfmt

This commit is contained in:
traxys 2024-05-05 19:39:35 +02:00
parent c6281260dc
commit 62f32bfc71
459 changed files with 28139 additions and 26377 deletions

View file

@ -5,40 +5,46 @@
pkgs,
...
}:
with lib; let
with lib;
let
cfg = config.plugins.lazy;
lazyPlugins = cfg.plugins;
processPlugin = plugin: let
mkEntryFromDrv = p:
if lib.isDerivation p
then {
name = "${lib.getName p}";
path = p;
}
else {
name = "${lib.getName p.pkg}";
path = p.pkg;
};
processDependencies =
if plugin ? dependencies && plugin.dependencies != null
then builtins.concatMap processPlugin plugin.dependencies
else [];
in
[(mkEntryFromDrv plugin)] ++ processDependencies;
processPlugin =
plugin:
let
mkEntryFromDrv =
p:
if lib.isDerivation p then
{
name = "${lib.getName p}";
path = p;
}
else
{
name = "${lib.getName p.pkg}";
path = p.pkg;
};
processDependencies =
if plugin ? dependencies && plugin.dependencies != null then
builtins.concatMap processPlugin plugin.dependencies
else
[ ];
in
[ (mkEntryFromDrv plugin) ] ++ processDependencies;
processedPlugins = builtins.concatLists (builtins.map processPlugin lazyPlugins);
lazyPath = pkgs.linkFarm "lazy-plugins" processedPlugins;
in {
in
{
options = {
plugins.lazy = {
enable = mkEnableOption "lazy.nvim";
plugins = with types; let
pluginType =
either
package
(submodule {
plugins =
with types;
let
pluginType = either package (submodule {
options = {
dir = helpers.mkNullOrOption str "A directory pointing to a local plugin";
@ -64,23 +70,17 @@ in {
When false then this plugin will not be included in the spec. (accepts fun():boolean)
'';
cond =
helpers.defaultNullOpts.mkStrLuaFnOr types.bool "`true`"
''
When false, or if the function returns false,
then this plugin will not be loaded. Useful to disable some plugins in vscode,
or firenvim for example. (accepts fun(LazyPlugin):boolean)
'';
cond = helpers.defaultNullOpts.mkStrLuaFnOr types.bool "`true`" ''
When false, or if the function returns false,
then this plugin will not be loaded. Useful to disable some plugins in vscode,
or firenvim for example. (accepts fun(LazyPlugin):boolean)
'';
dependencies =
helpers.mkNullOrOption (helpers.nixvimTypes.eitherRecursive str listOfPlugins)
"Plugin dependencies";
dependencies = helpers.mkNullOrOption (helpers.nixvimTypes.eitherRecursive str listOfPlugins) "Plugin dependencies";
init =
helpers.mkNullOrLuaFn
"init functions are always executed during startup";
init = helpers.mkNullOrLuaFn "init functions are always executed during startup";
config = helpers.mkNullOrStrLuaFnOr (types.enum [true]) ''
config = helpers.mkNullOrStrLuaFnOr (types.enum [ true ]) ''
config is executed when the plugin loads.
The default implementation will automatically run require(MAIN).setup(opts).
Lazy uses several heuristics to determine the plugin's MAIN module automatically based on the plugin's name.
@ -97,23 +97,23 @@ in {
Defaults to true
'';
event = with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str)))
"Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
event =
with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
cmd = with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str)))
"Lazy-load on command";
cmd =
with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on command";
ft = with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str)))
"Lazy-load on filetype";
ft =
with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on filetype";
keys = with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str)))
"Lazy-load on key mapping";
keys =
with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (either str (listOf str))) "Lazy-load on key mapping";
module = helpers.mkNullOrOption (enum [false]) ''
module = helpers.mkNullOrOption (enum [ false ]) ''
Do not automatically load this Lua module when it's required somewhere
'';
@ -129,7 +129,8 @@ in {
of the user's plugins
'';
opts = with helpers.nixvimTypes;
opts =
with helpers.nixvimTypes;
helpers.mkNullOrOption (maybeRaw (attrsOf anything)) ''
opts should be a table (will be merged with parent specs),
return a table (replaces parent specs) or should change a table.
@ -139,76 +140,68 @@ in {
};
});
listOfPlugins = types.listOf pluginType;
in
listOfPlugins = types.listOf pluginType;
in
mkOption {
type = listOfPlugins;
default = [];
default = [ ];
description = "List of plugins";
};
};
};
config = mkIf cfg.enable {
extraPlugins = [pkgs.vimPlugins.lazy-nvim];
extraPackages = [pkgs.git];
extraPlugins = [ pkgs.vimPlugins.lazy-nvim ];
extraPackages = [ pkgs.git ];
extraConfigLua = let
pluginToLua = plugin: let
keyExists = keyToCheck: attrSet: lib.elem keyToCheck (lib.attrNames attrSet);
extraConfigLua =
let
pluginToLua =
plugin:
let
keyExists = keyToCheck: attrSet: lib.elem keyToCheck (lib.attrNames attrSet);
in
if isDerivation plugin then
{ dir = "${lazyPath}/${lib.getName plugin}"; }
else
{
"__unkeyed" = plugin.name;
inherit (plugin)
cmd
cond
config
dev
enabled
event
ft
init
keys
lazy
main
module
name
optional
opts
priority
submodules
;
dependencies = helpers.ifNonNull' plugin.dependencies (
if isList plugin.dependencies then (pluginListToLua plugin.dependencies) else plugin.dependencies
);
dir =
if plugin ? dir && plugin.dir != null then plugin.dir else "${lazyPath}/${lib.getName plugin.pkg}";
};
pluginListToLua = map pluginToLua;
plugins = pluginListToLua cfg.plugins;
packedPlugins = if length plugins == 1 then head plugins else plugins;
in
if isDerivation plugin
then {
dir = "${lazyPath}/${lib.getName plugin}";
}
else {
"__unkeyed" = plugin.name;
inherit
(plugin)
cmd
cond
config
dev
enabled
event
ft
init
keys
lazy
main
module
name
optional
opts
priority
submodules
;
dependencies =
helpers.ifNonNull' plugin.dependencies
(
if isList plugin.dependencies
then (pluginListToLua plugin.dependencies)
else plugin.dependencies
);
dir =
if plugin ? dir && plugin.dir != null
then plugin.dir
else "${lazyPath}/${lib.getName plugin.pkg}";
};
pluginListToLua = map pluginToLua;
plugins = pluginListToLua cfg.plugins;
packedPlugins =
if length plugins == 1
then head plugins
else plugins;
in
mkIf (cfg.plugins != []) ''
mkIf (cfg.plugins != [ ]) ''
require('lazy').setup(
{
dev = {

View file

@ -5,18 +5,19 @@
pkgs,
...
}:
with lib; let
with lib;
let
cfg = config.plugins.packer;
in {
in
{
options = {
plugins.packer = {
enable = mkEnableOption "packer.nvim";
plugins = with types; let
pluginType =
either
str
(submodule {
plugins =
with types;
let
pluginType = either str (submodule {
options = {
name = mkOption {
type = str;
@ -25,21 +26,15 @@ in {
disable = helpers.mkNullOrOption bool "Mark plugin as inactive";
as =
helpers.mkNullOrOption str
"Specifies an alias under which to install the plugin";
as = helpers.mkNullOrOption str "Specifies an alias under which to install the plugin";
installer = helpers.defaultNullOpts.mkLuaFn "nil" "A custom installer";
updater = helpers.defaultNullOpts.mkLuaFn "nil" "A custom updater";
after =
helpers.mkNullOrOption (either str (listOf str))
"Plugins to load after this plugin";
after = helpers.mkNullOrOption (either str (listOf str)) "Plugins to load after this plugin";
rtp =
helpers.mkNullOrOption str
"Specifies a subdirectory of the plugin to add to runtimepath";
rtp = helpers.mkNullOrOption str "Specifies a subdirectory of the plugin to add to runtimepath";
opt = helpers.mkNullOrOption bool "Marks a plugin as optional";
@ -51,78 +46,52 @@ in {
lock = helpers.mkNullOrOption bool "Skip this plugin in updates";
run =
helpers.mkNullOrOption
(oneOf [
str
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
])
"Post-install hook";
run = helpers.mkNullOrOption (oneOf [
str
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
]) "Post-install hook";
requires =
helpers.mkNullOrOption (helpers.nixvimTypes.eitherRecursive str listOfPlugins)
"Plugin dependencies";
requires = helpers.mkNullOrOption (helpers.nixvimTypes.eitherRecursive str listOfPlugins) "Plugin dependencies";
rocks =
helpers.mkNullOrOption (either str (listOf (either str attrs)))
"Luarocks dependencies";
rocks = helpers.mkNullOrOption (either str (listOf (either str attrs))) "Luarocks dependencies";
config =
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
"Code to run after this plugin is loaded";
config = helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua) "Code to run after this plugin is loaded";
setup =
helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua)
"Code to be run before this plugin is loaded";
setup = helpers.mkNullOrOption (either str helpers.nixvimTypes.rawLua) "Code to be run before this plugin is loaded";
cmd =
helpers.mkNullOrOption (either str (listOf str))
"Commands which load this plugin";
cmd = helpers.mkNullOrOption (either str (listOf str)) "Commands which load this plugin";
ft =
helpers.mkNullOrOption (either str (listOf str))
"Filetypes which load this plugin";
ft = helpers.mkNullOrOption (either str (listOf str)) "Filetypes which load this plugin";
keys =
helpers.mkNullOrOption (either str (listOf str))
"Keymaps which load this plugin";
keys = helpers.mkNullOrOption (either str (listOf str)) "Keymaps which load this plugin";
event =
helpers.mkNullOrOption (either str (listOf str))
"Autocommand events which load this plugin";
event = helpers.mkNullOrOption (either str (listOf str)) "Autocommand events which load this plugin";
fn =
helpers.mkNullOrOption (either str (listOf str))
"Functions which load this plugin";
fn = helpers.mkNullOrOption (either str (listOf str)) "Functions which load this plugin";
cond =
helpers.mkNullOrOption
(oneOf [
str
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
])
"Conditional test to load this plugin";
cond = helpers.mkNullOrOption (oneOf [
str
helpers.nixvimTypes.rawLua
(listOf (either str helpers.nixvimTypes.rawLua))
]) "Conditional test to load this plugin";
module =
helpers.mkNullOrOption (either str (listOf str))
"Patterns of module names which load this plugin";
module = helpers.mkNullOrOption (either str (listOf str)) "Patterns of module names which load this plugin";
};
});
listOfPlugins = types.listOf pluginType;
in
listOfPlugins = types.listOf pluginType;
in
mkOption {
type = listOfPlugins;
default = [];
default = [ ];
description = "List of plugins";
};
rockPlugins = mkOption {
type = with types; listOf (either str attrs);
description = "List of lua rock plugins";
default = [];
default = [ ];
example = ''
[
"penlight"
@ -135,92 +104,82 @@ in {
};
config = mkIf cfg.enable {
extraPlugins = [(pkgs.vimPlugins.packer-nvim.overrideAttrs (_: {pname = "packer.nvim";}))];
extraPackages = [pkgs.git];
extraPlugins = [
(pkgs.vimPlugins.packer-nvim.overrideAttrs (_: {
pname = "packer.nvim";
}))
];
extraPackages = [ pkgs.git ];
extraConfigLua = let
luaRockPluginToLua = luaRockPlugin:
if isAttrs luaRockPlugin
then
mapAttrs'
(k: v: {
name =
if k == "name"
then "__unkeyed"
else k;
value = v;
})
luaRockPlugin
else luaRockPlugin;
luaRockListToLua = map luaRockPluginToLua;
extraConfigLua =
let
luaRockPluginToLua =
luaRockPlugin:
if isAttrs luaRockPlugin then
mapAttrs' (k: v: {
name = if k == "name" then "__unkeyed" else k;
value = v;
}) luaRockPlugin
else
luaRockPlugin;
luaRockListToLua = map luaRockPluginToLua;
pluginToLua = plugin:
if isAttrs plugin
then {
"__unkeyed" = plugin.name;
pluginToLua =
plugin:
if isAttrs plugin then
{
"__unkeyed" = plugin.name;
inherit
(plugin)
disable
as
installer
updater
after
rtp
opt
branch
tag
commit
lock
run
;
inherit (plugin)
disable
as
installer
updater
after
rtp
opt
branch
tag
commit
lock
run
;
requires =
helpers.ifNonNull' plugin.requires
(
if isList plugin.requires
then (pluginListToLua plugin.requires)
else plugin.requires
);
requires = helpers.ifNonNull' plugin.requires (
if isList plugin.requires then (pluginListToLua plugin.requires) else plugin.requires
);
rocks =
helpers.ifNonNull' plugin.rocks
(
if isList plugin.rocks
then luaRockListToLua plugin.rocks
else plugin.rocks
);
rocks = helpers.ifNonNull' plugin.rocks (
if isList plugin.rocks then luaRockListToLua plugin.rocks else plugin.rocks
);
inherit
(plugin)
config
setup
cmd
ft
keys
event
fn
cond
module
;
}
else plugin;
inherit (plugin)
config
setup
cmd
ft
keys
event
fn
cond
module
;
}
else
plugin;
pluginListToLua = map pluginToLua;
pluginListToLua = map pluginToLua;
plugins = pluginListToLua cfg.plugins;
plugins = pluginListToLua cfg.plugins;
packedPlugins =
if length plugins == 1
then head plugins
else plugins;
packedPlugins = if length plugins == 1 then head plugins else plugins;
luaRockPlugins = luaRockListToLua cfg.rockPlugins;
luaRocksString =
optionalString (cfg.rockPlugins != [])
"use_rocks ${helpers.toLuaObject luaRockPlugins}";
in
mkIf (cfg.plugins != []) ''
luaRockPlugins = luaRockListToLua cfg.rockPlugins;
luaRocksString = optionalString (
cfg.rockPlugins != [ ]
) "use_rocks ${helpers.toLuaObject luaRockPlugins}";
in
mkIf (cfg.plugins != [ ]) ''
require('packer').startup(function()
use ${helpers.toLuaObject packedPlugins}
${luaRocksString}