refactor(nvim): add _file and config attrs to all submodules
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-21 23:34:10 -05:00
parent e1d77a4f3b
commit 0f627107ce
23 changed files with 243 additions and 209 deletions

View file

@ -87,7 +87,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -84,7 +84,6 @@ in {
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -70,7 +70,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -43,7 +43,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -70,7 +70,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -84,7 +84,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -106,7 +106,6 @@
neovim = { neovim = {
enable = true; enable = true;
enableIde = true;
user = mainUser; user = mainUser;
}; };
}; };

View file

@ -4,7 +4,9 @@ self: {
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkOption types; inherit (lib) mkIf mkOption types;
cfg = config.programs.neovim;
in { in {
imports = [ imports = [
./git ./git
@ -17,94 +19,92 @@ in {
user = mkOption { user = mkOption {
type = types.str; type = types.str;
}; };
enableIde = mkOption {
type = types.bool;
default = false;
};
}; };
config.programs.neovim = { config = mkIf cfg.enable {
extraLuaConfig = programs.neovim = {
# lua extraLuaConfig =
'' # lua
-- by default, the indent is 2 spaces. ''
vim.opt.smartindent = true; -- by default, the indent is 2 spaces.
vim.opt.expandtab = true; vim.opt.smartindent = true;
vim.opt.shiftwidth = 2; vim.opt.expandtab = true;
vim.opt.softtabstop = 2; vim.opt.shiftwidth = 2;
vim.opt.tabstop = 2; vim.opt.softtabstop = 2;
vim.opt.tabstop = 2;
vim.opt.number = true; vim.opt.number = true;
vim.opt.relativenumber = true; vim.opt.relativenumber = true;
vim.opt.undofile = true; vim.opt.undofile = true;
vim.opt.undodir = '${config.xdg.cacheHome}/nvim/'; vim.opt.undodir = '${config.xdg.cacheHome}/nvim/';
-- Always show the signcolumn, otherwise it would shift -- Always show the signcolumn, otherwise it would shift
-- the text each time diagnostics appear/become resolved -- the text each time diagnostics appear/become resolved
vim.opt.signcolumn = 'yes'; vim.opt.signcolumn = 'yes';
-- remove highlight on words -- remove highlight on words
vim.keymap.set('n', '<esc>', ':noh<cr><esc>', { vim.keymap.set('n', '<esc>', ':noh<cr><esc>', {
noremap = true, noremap = true,
silent = true, silent = true,
}); });
-- https://github.com/seblj/roslyn.nvim/issues/121#issuecomment-2544076963 -- https://github.com/seblj/roslyn.nvim/issues/121#issuecomment-2544076963
vim.opt.cmdheight = 2; vim.opt.cmdheight = 2;
''; '';
plugins = [ plugins = [
pkgs.vimPlugins.fzfWrapper pkgs.vimPlugins.fzfWrapper
pkgs.vimPlugins.fzf-vim pkgs.vimPlugins.fzf-vim
{ {
plugin = pkgs.vimPlugins.todo-comments-nvim; plugin = pkgs.vimPlugins.todo-comments-nvim;
type = "lua"; type = "lua";
config = config =
# lua # lua
'' ''
require('todo-comments').setup(); require('todo-comments').setup();
''; '';
} }
{ {
plugin = pkgs.vimPlugins.mini-nvim; plugin = pkgs.vimPlugins.mini-nvim;
type = "lua"; type = "lua";
config = config =
# lua # lua
'' ''
-- TODO: see how this works -- TODO: see how this works
local ts_input = require('mini.surround').gen_spec.input.treesitter; local ts_input = require('mini.surround').gen_spec.input.treesitter;
require('mini.surround').setup({ require('mini.surround').setup({
custom_surroundings = { custom_surroundings = {
-- Use tree-sitter to search for function call -- Use tree-sitter to search for function call
f = { f = {
input = ts_input({ input = ts_input({
outer = '@call.outer', outer = '@call.outer',
inner = '@call.inner', inner = '@call.inner',
}); });
}, },
}, },
}); });
''; '';
} }
{ {
plugin = pkgs.vimPlugins.nvim-config-local; plugin = pkgs.vimPlugins.nvim-config-local;
type = "lua"; type = "lua";
config = config =
# lua # lua
'' ''
require('config-local').setup({ require('config-local').setup({
config_files = { '.nvim.lua', '.nvimrc', '.exrc' }, config_files = { '.nvim.lua', '.nvimrc', '.exrc' },
-- Where the plugin keeps files data -- Where the plugin keeps files data
hashfile = '${config.xdg.cacheHome}/nvim/config-local', hashfile = '${config.xdg.cacheHome}/nvim/config-local',
}); });
''; '';
} }
]; ];
};
}; };
# For accurate stack trace # For accurate stack trace

View file

@ -8,51 +8,55 @@
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
programs = mkIf cfg.enable { config = mkIf cfg.enable {
# I love doing typos programs = {
bash.shellAliases = { # I love doing typos
nivm = "nvim"; bash.shellAliases = {
nivim = "nvim"; nivm = "nvim";
}; nivim = "nvim";
};
neovim = { neovim = {
defaultEditor = true; defaultEditor = true;
viAlias = true; viAlias = true;
vimAlias = true; vimAlias = true;
extraPackages = mkIf cfg.enableIde (attrValues { extraPackages = attrValues {
inherit inherit
(pkgs.nodePackages) (pkgs.nodePackages)
bash-language-server bash-language-server
; ;
inherit inherit
(pkgs) (pkgs)
shellcheck shellcheck
; ;
}); };
extraLuaConfig = extraLuaConfig =
mkIf cfg.enableIde # lua
# lua ''
'' vim.api.nvim_create_autocmd('FileType', {
vim.api.nvim_create_autocmd('FileType', { pattern = 'sh',
pattern = 'sh', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
command = 'setlocal ts=4 sw=4 sts=0 expandtab', });
});
local default_capabilities = require('cmp_nvim_lsp').default_capabilities(); local default_capabilities = require('cmp_nvim_lsp').default_capabilities();
require('lspconfig').bashls.setup({ require('lspconfig').bashls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
settings = { settings = {
bashIde = { bashIde = {
shellcheckPath = '${getExe pkgs.shellcheck}', shellcheckPath = '${getExe pkgs.shellcheck}',
}, },
}, },
}); });
''; '';
};
}; };
}; };
# For accurate stack trace
_file = ./default.nix;
} }

View file

@ -9,7 +9,7 @@
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enable {
xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" { xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" {
CompileFlags.Add = ["-D__cpp_concepts=202002L"]; CompileFlags.Add = ["-D__cpp_concepts=202002L"];
}; };
@ -21,6 +21,7 @@ in {
'' ''
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = { 'cpp', 'c' }, pattern = { 'cpp', 'c' },
-- FIXME: load direnv here https://github.com/actionshrimp/direnv.nvim?tab=readme-ov-file#using-nvim-lspconfig
command = 'setlocal ts=4 sw=4 sts=0 expandtab', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
}); });
''; '';
@ -57,4 +58,7 @@ in {
}; };
}; };
}; };
# For accurate stack trace
_file = ./default.nix;
} }

View file

@ -10,7 +10,7 @@ self: {
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues { extraPackages = attrValues {
@ -73,5 +73,5 @@ in {
}; };
# For accurate stack trace # For accurate stack trace
_file = ./csharp.nix; _file = ./default.nix;
} }

View file

@ -1,9 +1,12 @@
self: { self: {
config,
lib, lib,
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) fileContents mkBefore; inherit (lib) fileContents mkBefore mkIf;
cfg = config.programs.neovim;
in { in {
imports = [ imports = [
./bash ./bash
@ -21,8 +24,8 @@ in {
(import ./web self) (import ./web self)
]; ];
config.programs = { config = mkIf cfg.enable {
neovim = { programs.neovim = {
extraLuaConfig = extraLuaConfig =
mkBefore mkBefore
# lua # lua

View file

@ -6,8 +6,8 @@
inherit (lib) mkIf; inherit (lib) mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in {
mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraLuaConfig = extraLuaConfig =
@ -24,4 +24,8 @@ in
''; '';
}; };
}; };
} };
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -10,8 +10,8 @@
javaSdk = pkgs.temurin-bin-17; javaSdk = pkgs.temurin-bin-17;
javaPkgs = attrValues {inherit (pkgs) gradle maven;}; javaPkgs = attrValues {inherit (pkgs) gradle maven;};
in in {
mkIf cfg.enableIde { config = mkIf cfg.enable {
home.packages = javaPkgs; home.packages = javaPkgs;
xdg.dataFile.".gradle/gradle.properties".text = '' xdg.dataFile.".gradle/gradle.properties".text = ''
@ -81,4 +81,8 @@ in
]; ];
}; };
}; };
} };
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -7,8 +7,8 @@
inherit (lib) attrValues mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in {
mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues { extraPackages = attrValues {
@ -26,6 +26,7 @@ in
pattern = 'yaml', pattern = 'yaml',
command = 'setlocal ts=4 sw=4 sts=0 expandtab', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
}); });
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'json', pattern = 'json',
command = 'setlocal ts=4 sw=4 sts=0 expandtab', command = 'setlocal ts=4 sw=4 sts=0 expandtab',
@ -54,4 +55,8 @@ in
''; '';
}; };
}; };
} };
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -9,8 +9,8 @@
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE; flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in in {
mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues { extraPackages = attrValues {
@ -38,8 +38,8 @@ in
require("neodev").setup({ require("neodev").setup({
override = function(root_dir, library) override = function(root_dir, library)
if root_dir:find('${flakeEnv}', 1, true) == 1 then if root_dir:find('${flakeEnv}', 1, true) == 1 then
library.enabled = true library.enabled = true;
library.plugins = true library.plugins = true;
end end
end, end,
}); });
@ -52,4 +52,8 @@ in
]; ];
}; };
}; };
} };
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -19,9 +19,7 @@ self: {
hash = "sha256-deQvQOOyK6iP7kjVrgEdFTyOP80RWXMrETs6gi7DTmo="; hash = "sha256-deQvQOOyK6iP7kjVrgEdFTyOP80RWXMrETs6gi7DTmo=";
}; };
in { in {
# live-server --quiet --browser=firefox --open=%outputfile% --watch=%outputfile% --wait=800 config = mkIf cfg.enable {
config = mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues { extraPackages = attrValues {
@ -165,5 +163,5 @@ in {
}; };
# For accurate stack trace # For accurate stack trace
_file = ./markdown.nix; _file = ./default.nix;
} }

View file

@ -18,13 +18,10 @@ self: {
flakeEnv = config.programs.bash.sessionVariables.FLAKE; flakeEnv = config.programs.bash.sessionVariables.FLAKE;
flakeDir = "${removePrefix "/home/${cfg.user}/" flakeEnv}"; flakeDir = "${removePrefix "/home/${cfg.user}/" flakeEnv}";
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = assertion = hasPrefix "/home/${cfg.user}/" flakeEnv;
cfg.enableIde
&& hasPrefix "/home/${cfg.user}/" flakeEnv
|| !cfg.enableIde;
message = '' message = ''
Your $FLAKE environment variable needs to point to a directory in Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the neovim module. the main users' home to use the neovim module.
@ -79,5 +76,5 @@ in {
}; };
# For accurate stack trace # For accurate stack trace
_file = ./nix.nix; _file = ./default.nix;
} }

View file

@ -7,23 +7,20 @@
inherit (lib) attrValues mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
pythonPkgs = py:
(attrValues {
inherit (py) python-lsp-server;
})
++ py.python-lsp-server.optional-dependencies.all;
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
withPython3 = true; withPython3 = true;
extraPython3Packages = py: extraPython3Packages = pythonPkgs;
(attrValues { extraPackages = pythonPkgs pkgs.python3Packages;
inherit (py) python-lsp-server;
})
++ py.python-lsp-server.optional-dependencies.all;
extraPackages =
(attrValues {
inherit (pkgs.python3Packages) python-lsp-server;
})
++ pkgs.python3Packages.python-lsp-server.optional-dependencies.all;
extraLuaConfig = extraLuaConfig =
# lua # lua
@ -45,4 +42,7 @@ in {
}; };
}; };
}; };
# For accurate stack trace
_file = ./default.nix;
} }

View file

@ -7,8 +7,8 @@
inherit (lib) attrValues mkIf; inherit (lib) attrValues mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in in {
mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues { extraPackages = attrValues {
@ -35,4 +35,8 @@ in
''; '';
}; };
}; };
} };
# For accurate stack trace
_file = ./default.nix;
}

View file

@ -11,7 +11,7 @@ self: {
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
config = mkIf cfg.enableIde { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
withNodeJs = true; withNodeJs = true;
@ -200,5 +200,5 @@ in {
}; };
# For accurate stack trace # For accurate stack trace
_file = ./web.nix; _file = ./default.nix;
} }

View file

@ -5,19 +5,19 @@ self: {
... ...
}: let }: let
inherit (self.inputs) nvim-theme-src; inherit (self.inputs) nvim-theme-src;
inherit (lib) attrValues fileContents optionals; inherit (lib) attrValues fileContents mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
in { in {
imports = [./treesitter.nix]; imports = [./treesitter.nix];
config.programs.neovim = { config = mkIf cfg.enable {
extraPackages = attrValues { programs.neovim = {
inherit (pkgs) bat; extraPackages = attrValues {
}; inherit (pkgs) bat;
};
plugins = plugins = [
[
{ {
plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs { plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs {
src = nvim-theme-src; src = nvim-theme-src;
@ -100,8 +100,7 @@ in {
type = "lua"; type = "lua";
config = fileContents ./config/heirline.lua; config = fileContents ./config/heirline.lua;
} }
]
++ optionals cfg.enableIde [
{ {
plugin = pkgs.vimPlugins.neo-tree-nvim; plugin = pkgs.vimPlugins.neo-tree-nvim;
type = "lua"; type = "lua";
@ -176,8 +175,9 @@ in {
''; '';
} }
]; ];
};
}; };
# For accurate stack trace # For accurate stack trace
_file = ./theme.nix; _file = ./default.nix;
} }

View file

@ -1,34 +1,48 @@
{pkgs, ...}: { {
programs.neovim.plugins = [ config,
{ lib,
plugin = pkgs.vimPlugins.nvim-treesitter-context; pkgs,
type = "lua"; ...
config = }: let
# lua inherit (lib) mkIf;
''
require('treesitter-context').setup({
enable = true,
max_lines = 3,
min_window_height = 20,
});
vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey'); cfg = config.programs.neovim;
''; in {
} config = mkIf cfg.enable {
programs.neovim.plugins = [
{
plugin = pkgs.vimPlugins.nvim-treesitter-context;
type = "lua";
config =
# lua
''
require('treesitter-context').setup({
enable = true,
max_lines = 3,
min_window_height = 20,
});
pkgs.vimPlugins.nvim-treesitter-textobjects vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey');
'';
}
{ pkgs.vimPlugins.nvim-treesitter-textobjects
plugin = pkgs.vimPlugins.nvim-treesitter.withAllGrammars;
type = "lua"; {
config = plugin = pkgs.vimPlugins.nvim-treesitter.withAllGrammars;
# lua type = "lua";
'' config =
require('nvim-treesitter.configs').setup({ # lua
highlight = { enable = true }, ''
indent = { enable = true }, require('nvim-treesitter.configs').setup({
}); highlight = { enable = true },
''; indent = { enable = true },
} });
]; '';
}
];
};
# For accurate stack trace
_file = ./treesitter.nix;
} }