Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: refactor imports, prefer adding helpers to args rather than importing it #690

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
misc: refactor imports, prefer adding helpers to args rather than i…
…mporting it
GaetanLepage committed Nov 6, 2023
commit 204bf9351d20aa65da12edd3aeca4e3aa118dc07
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 {
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,
...
}:
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 {
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
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
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
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;
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
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 ''
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 =
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";
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
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 =
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 = {
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"
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 = {
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 = {
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 =
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;
};
};

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 = {
Loading