Skip to content

Commit

Permalink
misc: refactor imports, prefer adding helpers to args rather than i…
Browse files Browse the repository at this point in the history
…mporting it
  • Loading branch information
GaetanLepage committed Nov 6, 2023
1 parent 541b694 commit b672470
Show file tree
Hide file tree
Showing 160 changed files with 682 additions and 721 deletions.
5 changes: 2 additions & 3 deletions modules/autocmd.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
config,
lib,
helpers,
config,
...
}:
with lib; let
helpers = import ../lib/helpers.nix {inherit lib;};

autoGroupOption = types.submodule {
options = {
clear = mkOption {
Expand Down
2 changes: 1 addition & 1 deletion modules/clipboard.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
config,
lib,
config,
pkgs,
...
}:
Expand Down
4 changes: 2 additions & 2 deletions modules/commands.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
config,
lib,
helpers,
config,
...
}:
with lib; let
helpers = import ../lib/helpers.nix {inherit lib;};
commandAttributes = types.submodule {
options = {
command = mkOption {
Expand Down
6 changes: 3 additions & 3 deletions modules/filetype.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
config,
lib,
helpers,
config,
...
} @ args:
}:
with lib; let
helpers = import ../lib/helpers.nix args;
filetypeDefinition = helpers.mkNullOrOption (types.attrsOf (
types.oneOf [
# Raw filetype
Expand Down
93 changes: 46 additions & 47 deletions modules/highlights.nix
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
{
config,
lib,
helpers,
config,
...
}: let
helpers = import ../lib/helpers.nix {inherit lib;};
in
with lib; {
options = {
highlight = mkOption {
type = types.attrsOf helpers.highlightType;
default = {};
description = "Define highlight groups";
example = ''
highlight = {
Comment.fg = '#ff0000';
};
'';
};
}:
with lib; {
options = {
highlight = mkOption {
type = types.attrsOf helpers.highlightType;
default = {};
description = "Define highlight groups";
example = ''
highlight = {
Comment.fg = '#ff0000';
};
'';
};

match = mkOption {
type = types.attrsOf types.str;
default = {};
description = "Define match groups";
example = ''
match = {
ExtraWhitespace = '\\s\\+$';
};
'';
};
match = mkOption {
type = types.attrsOf types.str;
default = {};
description = "Define match groups";
example = ''
match = {
ExtraWhitespace = '\\s\\+$';
};
'';
};
};

config = mkIf (config.highlight != {} || config.match != {}) {
extraConfigLuaPost =
(optionalString (config.highlight != {}) ''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
config = mkIf (config.highlight != {} || config.match != {}) {
extraConfigLuaPost =
(optionalString (config.highlight != {}) ''
-- Highlight groups {{
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
-- }}
'')
+ (optionalString (config.match != {}) ''
-- Match groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
local match = ${helpers.toLuaObject config.match}
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
for k,v in pairs(match) do
vim.fn.matchadd(k, v)
end
end
-- }}
'')
+ (optionalString (config.match != {}) ''
-- Match groups {{
do
local match = ${helpers.toLuaObject config.match}
for k,v in pairs(match) do
vim.fn.matchadd(k, v)
end
end
-- }}
'');
};
}
'');
};
}
7 changes: 3 additions & 4 deletions modules/keymaps.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
config,
lib,
helpers,
config,
...
}:
with lib; let
helpers = import ../lib/helpers.nix {inherit lib;};
in {
with lib; {
options = {
maps =
mapAttrs
Expand Down
2 changes: 1 addition & 1 deletion modules/lua-loader.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
config,
lib,
config,
...
}:
with lib; let
Expand Down
7 changes: 3 additions & 4 deletions modules/options.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
config,
lib,
helpers,
config,
...
}:
with lib; let
helpers = import ../lib/helpers.nix {inherit lib;};
in {
with lib; {
options = {
options = mkOption {
type = types.attrsOf types.anything;
Expand Down
3 changes: 1 addition & 2 deletions modules/output.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
pkgs,
config,
lib,
config,
...
}:
with lib; let
Expand Down
4 changes: 2 additions & 2 deletions plugins/bufferlines/barbar.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
lib,
pkgs,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.plugins.barbar;
helpers = import ../helpers.nix {inherit lib;};

bufferOptions = {
bufferIndex = helpers.mkNullOrOption types.bool ''
Expand Down
4 changes: 2 additions & 2 deletions plugins/bufferlines/barbecue.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
lib,
pkgs,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.plugins.barbecue;
helpers = import ../helpers.nix {inherit lib;};
mkListStr = helpers.defaultNullOpts.mkNullable (types.listOf types.str);
in {
options.plugins.barbecue =
Expand Down
6 changes: 3 additions & 3 deletions plugins/bufferlines/bufferline.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
lib,
helpers,
config,
pkgs,
lib,
...
} @ args:
}:
with lib; let
cfg = config.plugins.bufferline;
helpers = import ../helpers.nix args;

highlightOption = {
fg = helpers.mkNullOrOption types.str "foreground color";
Expand Down
5 changes: 2 additions & 3 deletions plugins/bufferlines/navic.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
lib,
pkgs,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.plugins.navic;
helpers = import ../helpers.nix {inherit lib;};
mkListStr = helpers.defaultNullOpts.mkNullable (types.listOf types.str);
in {
options.plugins.navic =
helpers.extraOptionsOptions
Expand Down
8 changes: 4 additions & 4 deletions plugins/colorschemes/ayu.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
} @ args:
}:
with lib; let
cfg = config.colorschemes.ayu;
helpers = import ../helpers.nix args;
in {
options = {
colorschemes.ayu =
Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/base16.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.colorschemes.base16;
helpers = import ../helpers.nix {inherit lib;};
themes = import ./base16-list.nix;
in {
options = {
Expand Down
8 changes: 4 additions & 4 deletions plugins/colorschemes/catppuccin.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
} @ args:
}:
with lib; let
cfg = config.colorschemes.catppuccin;
helpers = import ../helpers.nix args;

flavours = [
"latte"
Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/dracula.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.colorschemes.dracula;
helpers = import ../helpers.nix {inherit lib;};
in {
options = {
colorschemes.dracula = {
Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/gruvbox.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.colorschemes.gruvbox;
helpers = import ../helpers.nix {inherit lib;};
colors = types.enum ["bg" "red" "green" "yellow" "blue" "purple" "aqua" "gray" "fg" "bg0_h" "bg0" "bg1" "bg2" "bg3" "bg4" "gray" "orange" "bg0_s" "fg0" "fg1" "fg2" "fg3" "fg4"];
in {
options = {
Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/kanagawa.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
lib,
helpers,
pkgs,
config,
lib,
...
} @ args:
}:
with lib; let
cfg = config.colorschemes.kanagawa;
helpers = import ../helpers.nix args;
in {
options = {
colorschemes.kanagawa =
Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/melange.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
pkgs,
lib,
helpers,
pkgs,
config,
...
}: let
inherit (lib) mkEnableOption mkDefault mkIf;
inherit (import ../helpers.nix {inherit lib;}) mkPackageOption;
cfg = config.colorschemes.melange;
in {
options = {
colorschemes.melange = {
enable = mkEnableOption "Melange colorscheme";
package = mkPackageOption "melange.nvim" pkgs.vimPlugins.melange-nvim;
package = helpers.mkPackageOption "melange.nvim" pkgs.vimPlugins.melange-nvim;
};
};

Expand Down
6 changes: 3 additions & 3 deletions plugins/colorschemes/nord.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
pkgs,
config,
lib,
helpers,
config,
pkgs,
...
}:
with lib; let
cfg = config.colorschemes.nord;
helpers = import ../helpers.nix {inherit lib;};
in {
options = {
colorschemes.nord = {
Expand Down
Loading

0 comments on commit b672470

Please sign in to comment.