Skip to content

Commit 13b3fc3

Browse files
committed
treeside: use mkIf instead of optionalString for various extraConfigs
1 parent 2bd8f19 commit 13b3fc3

File tree

7 files changed

+75
-69
lines changed

7 files changed

+75
-69
lines changed

lib/neovim-plugin.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ with lib;
111111
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
112112
inherit extraPackages;
113113

114-
${extraConfigNamespace} = optionalString callSetup ''
114+
${extraConfigNamespace} = mkIf callSetup ''
115115
require('${luaName}')${setup}(${optionalString (cfg ? settings) (toLuaObject cfg.settings)})
116116
'';
117117
}

modules/autocmd.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ with lib;
4242
let
4343
inherit (config) autoGroups autoCmd;
4444
in
45-
mkIf (autoGroups != { } || autoCmd != { }) {
45+
mkIf (autoGroups != { } || autoCmd != [ ]) {
4646
# Introduced early October 2023.
4747
# TODO remove in early December 2023.
4848
assertions = [

modules/diagnostics.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ with lib;
1919
};
2020

2121
config = {
22-
extraConfigLuaPre = optionalString (config.diagnostics != { }) ''
22+
extraConfigLuaPre = mkIf (config.diagnostics != { }) ''
2323
vim.diagnostic.config(${helpers.toLuaObject config.diagnostics})
2424
'';
2525
};

modules/highlights.nix

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,50 +35,52 @@ with lib;
3535
};
3636
};
3737

38-
config = {
39-
extraConfigLuaPre =
40-
(optionalString (config.highlight != { })
41-
# lua
42-
''
43-
-- Highlight groups {{
44-
do
45-
local highlights = ${helpers.toLuaObject config.highlight}
38+
config = mkMerge [
39+
{
40+
extraConfigLuaPre =
41+
mkIf (config.highlight != { })
42+
# lua
43+
''
44+
-- Highlight groups {{
45+
do
46+
local highlights = ${helpers.toLuaObject config.highlight}
4647
47-
for k,v in pairs(highlights) do
48-
vim.api.nvim_set_hl(0, k, v)
48+
for k,v in pairs(highlights) do
49+
vim.api.nvim_set_hl(0, k, v)
50+
end
4951
end
50-
end
51-
-- }}
52-
''
53-
)
54-
+ (optionalString (config.match != { })
55-
# lua
56-
''
57-
-- Match groups {{
58-
do
59-
local match = ${helpers.toLuaObject config.match}
52+
-- }}
53+
'';
54+
extraConfigLuaPost =
55+
mkIf (config.highlightOverride != { })
56+
# lua
57+
''
58+
-- Highlight groups {{
59+
do
60+
local highlights = ${helpers.toLuaObject config.highlightOverride}
6061
61-
for k,v in pairs(match) do
62-
vim.fn.matchadd(k, v)
62+
for k,v in pairs(highlights) do
63+
vim.api.nvim_set_hl(0, k, v)
64+
end
6365
end
64-
end
6566
-- }}
66-
''
67-
);
68-
69-
extraConfigLuaPost =
70-
optionalString (config.highlightOverride != { })
71-
# lua
72-
''
73-
-- Highlight groups {{
74-
do
75-
local highlights = ${helpers.toLuaObject config.highlightOverride}
67+
'';
68+
}
69+
{
70+
extraConfigLuaPre =
71+
mkIf (config.match != { })
72+
# lua
73+
''
74+
-- Match groups {{
75+
do
76+
local match = ${helpers.toLuaObject config.match}
7677
77-
for k,v in pairs(highlights) do
78-
vim.api.nvim_set_hl(0, k, v)
78+
for k,v in pairs(match) do
79+
vim.fn.matchadd(k, v)
80+
end
7981
end
80-
end
81-
-- }}
82-
'';
83-
};
82+
-- }}
83+
'';
84+
}
85+
];
8486
}

modules/keymaps.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ with lib;
9090
${concatStringsSep "\n" luaDefs}
9191
'';
9292

93-
extraConfigLua = optionalString (config.keymaps != [ ]) ''
93+
extraConfigLua = mkIf (config.keymaps != [ ]) ''
9494
-- Set up keybinds {{{
9595
do
9696
local __nixvim_binds = ${helpers.toLuaObject (map normalizeMapping config.keymaps)}

modules/opts.nix

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,35 @@ in
5555
};
5656

5757
config = {
58-
extraConfigLuaPre = concatLines (
59-
mapAttrsToList (
60-
optionName:
61-
{
62-
prettyName,
63-
luaVariableName,
64-
luaApi,
65-
...
66-
}:
67-
let
68-
varName = "nixvim_${luaVariableName}";
69-
optionDefinitions = config.${optionName};
70-
in
71-
optionalString (optionDefinitions != { }) ''
72-
-- Set up ${prettyName} {{{
73-
do
74-
local ${varName} = ${helpers.toLuaObject optionDefinitions}
58+
extraConfigLuaPre =
59+
let
60+
content = helpers.concatNonEmptyStringsNewline (
61+
mapAttrsToList (
62+
optionName:
63+
{
64+
prettyName,
65+
luaVariableName,
66+
luaApi,
67+
...
68+
}:
69+
let
70+
varName = "nixvim_${luaVariableName}";
71+
optionDefinitions = config.${optionName};
72+
in
73+
optionalString (optionDefinitions != { }) ''
74+
-- Set up ${prettyName} {{{
75+
do
76+
local ${varName} = ${helpers.toLuaObject optionDefinitions}
7577
76-
for k,v in pairs(${varName}) do
77-
vim.${luaApi}[k] = v
78-
end
79-
end
80-
-- }}}
81-
''
82-
) optionsAttrs
83-
);
78+
for k,v in pairs(${varName}) do
79+
vim.${luaApi}[k] = v
80+
end
81+
end
82+
-- }}}
83+
''
84+
) optionsAttrs
85+
);
86+
in
87+
mkIf (content != "") content;
8488
};
8589
}

modules/top-level/output.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ with lib;
140140
'';
141141
};
142142

143-
extraConfigLuaPre = lib.optionalString config.wrapRc ''
143+
extraConfigLuaPre = lib.mkIf config.wrapRc ''
144144
-- Ignore the user lua configuration
145145
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- ~/.config/nvim
146146
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after

0 commit comments

Comments
 (0)