2022-07-15 13:11:54 +02:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2023-03-04 13:22:48 +01:00
|
|
|
cfg = config.my.programs.nvim;
|
2023-06-10 21:52:57 +02:00
|
|
|
boolToString = bool: if bool then "true" else "false";
|
|
|
|
quote = str: ''"${toString str}"'';
|
2023-06-11 10:22:19 +02:00
|
|
|
id = x: x;
|
|
|
|
listToString = sep: f: list: ''{ ${concatStringsSep sep (map f list)} }'';
|
|
|
|
listToStringOneLine = listToString ", ";
|
2023-08-11 18:59:52 +02:00
|
|
|
listToStringMultiLine' = listToString ",\n" id;
|
|
|
|
keybinding = { key, cmd, func, mode, desc }:
|
2023-03-11 17:00:32 +01:00
|
|
|
let
|
2023-06-10 21:52:57 +02:00
|
|
|
cmdString =
|
|
|
|
if cmd != null
|
|
|
|
then quote cmd
|
|
|
|
else
|
|
|
|
(
|
|
|
|
if func != null
|
|
|
|
then func
|
|
|
|
else abort "Either cmd or function must be set"
|
|
|
|
);
|
2023-08-11 19:00:11 +02:00
|
|
|
descString = optionalString (desc != null) "desc = ${quote desc},";
|
2023-03-11 17:00:32 +01:00
|
|
|
in
|
2023-08-11 19:00:11 +02:00
|
|
|
''{ ${quote key}, ${cmdString}, mode = ${quote mode}, ${descString} }'';
|
2023-06-10 21:52:57 +02:00
|
|
|
lazySpecFromPlugin =
|
2023-08-11 19:00:11 +02:00
|
|
|
{ plugin, dependencies, init, conf, lazy, event, enabled, cmd, ft, priority, keys }:
|
|
|
|
listToStringMultiLine'
|
2023-06-11 10:22:19 +02:00
|
|
|
([
|
|
|
|
"dir = ${quote plugin}"
|
2023-07-15 12:45:11 +02:00
|
|
|
"name = ${quote (getName plugin)}"
|
2023-06-11 10:22:19 +02:00
|
|
|
]
|
2023-07-29 17:02:26 +02:00
|
|
|
++ (optional (lazy != null) "lazy = ${boolToString lazy}")
|
2023-06-11 10:22:19 +02:00
|
|
|
++ (optional (!enabled) "enabled = ${boolToString enabled}")
|
2023-08-11 19:00:11 +02:00
|
|
|
++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine' (map lazySpecFromPlugin dependencies)}")
|
2023-06-11 10:22:19 +02:00
|
|
|
++ (optional (init != null) "init = function(plugin)\n${toString init}\nend")
|
|
|
|
++ (optional (conf != null) "config = function(plugin, opts)\n${toString conf}\nend")
|
2023-08-11 19:00:11 +02:00
|
|
|
++ (optional (keys != [ ]) "keys = ${listToStringMultiLine' (map keybinding keys)}")
|
2023-06-11 10:22:19 +02:00
|
|
|
++ (optional (event != [ ]) "event = ${listToStringOneLine quote event}")
|
|
|
|
++ (optional (cmd != [ ]) "cmd = ${listToStringOneLine quote cmd}")
|
|
|
|
++ (optional (ft != [ ]) "ft = ${listToStringOneLine quote ft}")
|
2023-07-29 17:02:26 +02:00
|
|
|
++ (optional (priority != null) "priority = ${toString priority}")
|
2023-06-11 10:22:19 +02:00
|
|
|
);
|
2023-08-11 19:00:11 +02:00
|
|
|
lazySpecs = listToStringMultiLine' (map lazySpecFromPlugin cfg.plugins);
|
2023-08-11 18:59:52 +02:00
|
|
|
lazy = /* lua */ ''
|
2023-08-10 18:40:41 +02:00
|
|
|
require("lazy").setup(${lazySpecs})
|
2023-06-10 21:52:57 +02:00
|
|
|
'';
|
2022-07-15 13:11:54 +02:00
|
|
|
in
|
|
|
|
{
|
2023-06-10 21:52:57 +02:00
|
|
|
imports = [ ./plugins ];
|
|
|
|
|
|
|
|
options.my.programs.nvim = {
|
|
|
|
enable = mkEnableOption "nvim";
|
|
|
|
plugins = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
List of plugins with config.
|
|
|
|
'';
|
|
|
|
type = with types; listOf (
|
|
|
|
let
|
|
|
|
sub = submodule {
|
|
|
|
options = {
|
|
|
|
conf = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
2023-07-29 17:02:26 +02:00
|
|
|
Lua function to be executed when the plugin is loaded.
|
2023-06-10 21:52:57 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
dependencies = mkOption {
|
|
|
|
type = listOf sub;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
List of plugins this plugin depends on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
init = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Lua code to be executed when the plugin is initialized.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
event = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Event to load the plugin on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
lazy = mkOption {
|
2023-07-29 17:02:26 +02:00
|
|
|
type = nullOr bool;
|
|
|
|
default = null;
|
2023-06-10 21:52:57 +02:00
|
|
|
description = ''
|
|
|
|
Whether to load the plugin lazily.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
plugin = mkOption {
|
|
|
|
type = package;
|
|
|
|
description = ''
|
|
|
|
The plugin package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
enabled = mkOption {
|
|
|
|
type = bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the plugin.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
cmd = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Command to load the plugin.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
ft = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Filetype to load the plugin on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
priority = mkOption {
|
2023-07-29 17:02:26 +02:00
|
|
|
type = nullOr int;
|
|
|
|
default = null;
|
2023-06-10 21:52:57 +02:00
|
|
|
description = ''
|
|
|
|
Priority to load the plugin.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
keys = mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
List of keybindings.
|
|
|
|
'';
|
|
|
|
type = listOf (submodule {
|
|
|
|
options = {
|
|
|
|
key = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = ''
|
|
|
|
Key to bind.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
cmd = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Command to execute.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
func = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Function to execute.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
mode = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "n";
|
|
|
|
description = ''
|
|
|
|
Mode to bind the key in.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
desc = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Description of the keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
sub
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-15 13:11:54 +02:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-03-02 09:13:46 +01:00
|
|
|
home-manager.users.moritz = {
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
(
|
|
|
|
if config.my.programs.hyprland.enable
|
|
|
|
then neovide-hyprland
|
|
|
|
else neovide
|
|
|
|
)
|
2023-02-16 18:03:55 +01:00
|
|
|
];
|
2023-08-10 18:40:41 +02:00
|
|
|
xdg.configFile."nvim/init.lua" = {
|
|
|
|
source =
|
|
|
|
let
|
|
|
|
text = lib.concatLines [ (builtins.readFile ./options.lua) lazy ];
|
|
|
|
in
|
|
|
|
pkgs.runCommand "init.lua" { inherit text; } ''
|
|
|
|
touch $out
|
|
|
|
echo -n "$text" > $out
|
|
|
|
${getExe pkgs.stylua} $out
|
|
|
|
'';
|
|
|
|
};
|
2023-03-02 09:13:46 +01:00
|
|
|
programs.neovim = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.neovim-nightly;
|
|
|
|
vimAlias = true;
|
|
|
|
vimdiffAlias = true;
|
|
|
|
withNodeJs = true;
|
|
|
|
withPython3 = true;
|
2023-07-24 18:44:03 +02:00
|
|
|
extraPython3Packages = ps:
|
|
|
|
let
|
|
|
|
plugins = map (getAttr "plugin") cfg.plugins;
|
|
|
|
depAttrName = "python3Dependencies";
|
|
|
|
filtered = filter (hasAttr depAttrName) plugins;
|
|
|
|
funcs = map (getAttr depAttrName) filtered;
|
|
|
|
in
|
|
|
|
foldl (list: f: list ++ (f ps)) [ ] funcs;
|
|
|
|
extraPackages = with pkgs;
|
|
|
|
[
|
|
|
|
alejandra
|
|
|
|
black
|
|
|
|
deadnix
|
|
|
|
isort
|
|
|
|
jq
|
|
|
|
nil
|
|
|
|
nixpkgs-fmt
|
|
|
|
nodePackages.bash-language-server
|
|
|
|
rustfmt
|
|
|
|
shellcheck
|
|
|
|
shfmt
|
|
|
|
statix
|
|
|
|
stylua
|
|
|
|
sumneko-lua-language-server
|
|
|
|
taplo
|
|
|
|
typst
|
|
|
|
typst-lsp
|
|
|
|
yamlfmt
|
|
|
|
];
|
2023-06-27 22:04:17 +02:00
|
|
|
plugins = [
|
|
|
|
pkgs.vimPlugins.lazy-nvim
|
2023-06-10 21:52:57 +02:00
|
|
|
];
|
2023-03-02 09:13:46 +01:00
|
|
|
};
|
2022-07-15 13:11:54 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|