Compare commits

...

3 commits

Author SHA1 Message Date
688e8e2ece
modules/fn: use content instead of settings
move content to content.extra
2024-05-01 02:01:47 +03:00
238e4bf68e
modules: add gitsigns 2024-05-01 01:50:34 +03:00
4cc9de194f
modules: add fn module to define functions 2024-04-30 16:54:58 +03:00
5 changed files with 103 additions and 3 deletions

View file

@ -43,7 +43,7 @@ let
''; '';
}; };
buffer = mkOption { buffer = mkOption {
type = with types; nullOr str; type = with types; nullOr attrs;
default = null; default = null;
description = '' description = ''
The mapping will be effective in the current buffer only. The mapping will be effective in the current buffer only.
@ -129,7 +129,6 @@ let
genConfig = mkOption { genConfig = mkOption {
type = types.attrs; type = types.attrs;
readOnly = true;
internal = true; internal = true;
}; };
}; };

View file

@ -9,11 +9,13 @@
./modules/filetype.nix ./modules/filetype.nix
./modules/input.nix ./modules/input.nix
./modules/plugin.nix ./modules/plugin.nix
./modules/fn.nix
./modules/plugins/theme/catppuccin.nix ./modules/plugins/theme/catppuccin.nix
./modules/plugins/style/neoformat.nix ./modules/plugins/style/neoformat.nix
./modules/plugins/navigation/telescope.nix ./modules/plugins/navigation/telescope.nix
./modules/plugins/navigation/nvim-tree.nix ./modules/plugins/navigation/nvim-tree.nix
./modules/plugins/gitsigns.nix
################################################## ##################################################
(pkgs.path + "/nixos/modules/misc/assertions.nix") (pkgs.path + "/nixos/modules/misc/assertions.nix")

61
modules/fn.nix Normal file
View file

@ -0,0 +1,61 @@
{ lib, ... }:
let
fnOpts = { name, config, ... }: {
options = with lib; {
args = mkOption {
type = with types; listOf str;
default = [ ];
};
content = mkOption {
type = types.functionTo (lib.types.submoduleWith {
modules = [
{
options.extra = with lib; mkOption {
type = with types; nullOr attrs;
default = null;
};
}
./vim/keymap.nix
# ./vim/opts.nix
];
specialArgs = { inherit lib; };
});
default = { };
};
lambda = mkOption {
type = types.attrs;
readOnly = true;
internal = true;
};
};
config = {
lambda = with lib.nix2lua;
let
fnArgs = builtins.listToAttrs (map (v: { name = v; value = raw v; }) config.args);
innerCfg = config.content fnArgs;
in
lambda config.args (lib.flatten [
innerCfg.extra
(lib.flip map innerCfg.vim.keymap.set ({ mode, lhs, rhs, ... } @ vars:
let
buf = lib.optionalString (vars.buffer != null) vars.buffer.raw;
m = if builtins.isList mode then lib.head mode else mode;
in
if innerCfg.vim.keymap._validate."${buf}"."${m}"."${lhs}" == rhs then vars.genConfig
else abort "This case should never happen."
))
]);
};
};
in
{
options.fn = with lib; mkOption {
type = with types; attrsOf (submodule fnOpts);
default = { };
};
}

View file

@ -0,0 +1,38 @@
{ config, lib, pkgs, ... }:
let cfg = config.plugins.gitsigns; in
{
options.plugins.gitsigns = with lib; {
enable = mkEnableOption "gitsigns-nvim";
package = mkPackageOption pkgs.vimPlugins "gitsigns-nvim" { };
settings = mkOption {
type = types.attrs;
default = { };
};
keymap.set = mkOption {
type = with types; listOf keymap;
};
};
config = lib.mkIf cfg.enable {
fn.gitsigns-nvim-on-attach = {
args = [ "bufnr" ];
content = { bufnr }: {
vim.keymap.set = map (attrs: attrs // { buffer = bufnr; }) cfg.keymap.set;
};
};
plugin.gitsigns-nvim = {
name = "gitsigns";
varName = "gs";
package = cfg.package;
setupSettings = cfg.settings // {
on_attach = config.fn.gitsigns-nvim-on-attach.lambda;
};
};
};
}

View file

@ -30,7 +30,7 @@ let cfg = config.vim.keymap; in
else m else m
))); )));
buf = lib.optionalString (buffer != null) buffer; buf = lib.optionalString (buffer != null) buffer.raw;
in in
lib.foldl lib.recursiveUpdate { } lib.foldl lib.recursiveUpdate { }
(lib.flip map unwrappedModes (m: { (lib.flip map unwrappedModes (m: {