feat(nvim): load devShells dynamically
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-22 03:12:45 -05:00
parent b8d9e9ff92
commit 157a74df47
10 changed files with 159 additions and 69 deletions

View file

@ -8,6 +8,7 @@
inherit (pkgs.writers) writeYAML; inherit (pkgs.writers) writeYAML;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" { xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" {
@ -21,8 +22,17 @@ 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', callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['c-lang'] == nil) then
devShells['c-lang'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#c-lang'});
vim.cmd[[LspStart]];
end
end,
}); });
''; '';
@ -40,10 +50,12 @@ in {
lsp.cmake.setup({ lsp.cmake.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
}); });
lsp.clangd.setup({ lsp.clangd.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
handlers = require('lsp-status').extensions.clangd.setup(), handlers = require('lsp-status').extensions.clangd.setup(),

View file

@ -10,19 +10,11 @@ self: {
inherit (lib) mkIf; inherit (lib) mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraLuaConfig =
# lua
''
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'cs' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
'';
plugins = [ plugins = [
{ {
plugin = buildPlugin "roslyn-nvim" vimplugin-roslyn-nvim-src; plugin = buildPlugin "roslyn-nvim" vimplugin-roslyn-nvim-src;
@ -38,6 +30,7 @@ in {
end, end,
}); });
local startRoslyn = function()
require('roslyn').setup({ require('roslyn').setup({
config = { config = {
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = require('cmp_nvim_lsp').default_capabilities(),
@ -66,6 +59,25 @@ in {
exe = 'Microsoft.CodeAnalysis.LanguageServer', exe = 'Microsoft.CodeAnalysis.LanguageServer',
}); });
end;
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'cs' },
callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['csharp'] == nil) then
devShells['csharp'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#csharp'});
startRoslyn();
os.execute('sleep 1')
vim.cmd[[e]]; -- reload to attach on current file
end
end,
});
''; '';
} }
]; ];

View file

@ -30,6 +30,9 @@ in {
mkBefore mkBefore
# lua # lua
'' ''
-- Init object to keep track of loaded devShells
local devShells = {};
-- Add formatting cmd -- Add formatting cmd
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'Format', 'Format',
@ -60,6 +63,7 @@ in {
# lsp plugins # lsp plugins
nvim-lspconfig nvim-lspconfig
lsp-status-nvim lsp-status-nvim
nix-develop-nvim
# completion plugins # completion plugins
cmp-buffer cmp-buffer
cmp-nvim-lsp cmp-nvim-lsp

View file

@ -6,6 +6,7 @@
inherit (lib) mkIf; inherit (lib) mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs = { programs = {
@ -14,13 +15,18 @@ in {
# lua # lua
'' ''
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'yaml', pattern = { 'json', 'yaml' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.api.nvim_create_autocmd('FileType', { callback = function()
pattern = 'json', vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
if (devShells['json'] == nil) then
devShells['json'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#json'});
vim.cmd[[LspStart]];
end
end,
}); });
local lsp = require('lspconfig'); local lsp = require('lspconfig');
@ -28,10 +34,12 @@ in {
lsp.jsonls.setup({ lsp.jsonls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
}); });
lsp.yamlls.setup({ lsp.yamlls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
settings = { settings = {
yaml = { yaml = {

View file

@ -24,7 +24,17 @@ in {
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'lua', pattern = 'lua',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['lua'] == nil) then
devShells['lua'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#lua'});
vim.cmd[[LspStart]];
end
end,
}); });
-- IMPORTANT: make sure to setup neodev BEFORE lspconfig -- IMPORTANT: make sure to setup neodev BEFORE lspconfig
@ -39,6 +49,7 @@ in {
require('lspconfig').lua_ls.setup({ require('lspconfig').lua_ls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
}); });
''; '';
} }

View file

@ -12,6 +12,7 @@ self: {
inherit (lib) concatStringsSep mkIf; inherit (lib) concatStringsSep mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
isServer = osConfig.roles.server.sshd.enable or false; isServer = osConfig.roles.server.sshd.enable or false;
githubCSS = pkgs.fetchurl { githubCSS = pkgs.fetchurl {
@ -25,10 +26,26 @@ in {
extraLuaConfig = extraLuaConfig =
# lua # lua
'' ''
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'markdown', 'tex' },
callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['markdown'] == nil) then
devShells['markdown'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#markdown'});
vim.cmd[[LspStart]];
end
end,
});
local lsp = require('lspconfig'); local lsp = require('lspconfig');
lsp.texlab.setup({ lsp.texlab.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = require('cmp_nvim_lsp').default_capabilities(),
autostart = false,
settings = { settings = {
texlab = { texlab = {
@ -80,12 +97,6 @@ in {
in in
# lua # lua
'' ''
--
vim.api.nvim_create_autocmd('FileType', {
pattern = 'tex',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.g.knap_settings = { vim.g.knap_settings = {
-- HTML -- HTML
htmloutputext = 'html', htmloutputext = 'html',

View file

@ -1,36 +1,37 @@
{ {
config, config,
lib, lib,
pkgs,
... ...
}: let }: let
inherit (lib) attrValues mkIf; inherit (lib) mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs = { programs = {
neovim = { neovim = {
extraPackages = attrValues {
inherit
(pkgs)
cargo
rustc
rust-analyzer
rustfmt
;
};
extraLuaConfig = extraLuaConfig =
# lua # lua
'' ''
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = { 'rust' }, pattern = { 'rust' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['rust'] == nil) then
devShells['rust'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#rust'});
vim.cmd[[LspStart]];
end
end,
}); });
require('lspconfig').rust_analyzer.setup({ require('lspconfig').rust_analyzer.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(), capabilities = require('cmp_nvim_lsp').default_capabilities(),
autostart = false,
}); });
''; '';
}; };

View file

@ -10,6 +10,7 @@ self: {
inherit (lib) mkIf; inherit (lib) mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs = { programs = {
@ -21,12 +22,32 @@ in {
'' ''
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx', 'css', 'scss' }, pattern = { 'javascript', 'javascriptreact', 'javascript.jsx', 'typescript', 'typescriptreact', 'typescript.tsx', 'css', 'scss' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
callback = function()
vim.cmd[[setlocal ts=4 sw=4 sts=0 expandtab]];
if (devShells['web'] == nil) then
devShells['web'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#web'});
vim.cmd[[LspStart]];
end
end,
}); });
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
pattern = 'html', pattern = 'html',
command = 'setlocal ts=4 sw=4 expandtab',
callback = function()
vim.cmd[[setlocal ts=4 sw=4 expandtab]];
if (devShells['web'] == nil) then
devShells['web'] = 1;
require('nix-develop').nix_develop({'${flakeEnv}#web'});
vim.cmd[[LspStart]];
end
end,
}); });
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
@ -40,6 +61,7 @@ in {
tsserver.setup({ tsserver.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
handlers = { handlers = {
-- format error code with better error message -- format error code with better error message
@ -52,6 +74,7 @@ in {
lsp.eslint.setup({ lsp.eslint.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
-- auto-save -- auto-save
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
@ -102,6 +125,7 @@ in {
lsp.cssls.setup({ lsp.cssls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
settings = { settings = {
css = { css = {
@ -118,6 +142,7 @@ in {
lsp.somesass_ls.setup({ lsp.somesass_ls.setup({
capabilities = default_capabilities, capabilities = default_capabilities,
autostart = false,
}); });
lsp.somesass_ls.manager.config.settings = { lsp.somesass_ls.manager.config.settings = {
somesass = { somesass = {
@ -134,6 +159,8 @@ in {
lsp.html.setup({ lsp.html.setup({
capabilities = html_caps, capabilities = html_caps,
autostart = false,
settings = { settings = {
configurationSection = { "html", "css", "javascript" }, configurationSection = { "html", "css", "javascript" },
embeddedLanguages = { embeddedLanguages = {
@ -162,6 +189,7 @@ in {
# lua # lua
'' ''
local packageInfo = require('package-info'); local packageInfo = require('package-info');
packageInfo.setup({ packageInfo.setup({
hide_up_to_date = true, hide_up_to_date = true,
package_manager = 'npm', package_manager = 'npm',
@ -169,6 +197,7 @@ in {
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, { vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
pattern = { 'package.json' }, pattern = { 'package.json' },
callback = function() callback = function()
packageInfo.show({ force = true }); packageInfo.show({ force = true });
end, end,

View file

@ -19,6 +19,15 @@ inputs: rec {
{ {
inherit cudaSupport; inherit cudaSupport;
allowUnfree = true; allowUnfree = true;
# FIXME: Roslyn-ls uses dotnet6 https://github.com/NixOS/nixpkgs/blob/d3c42f187194c26d9f0309a8ecc469d6c878ce33/pkgs/by-name/ro/roslyn-ls/package.nix#L21
permittedInsecurePackages =
[
"dotnet-core-combined"
"dotnet-sdk-6.0.428"
"dotnet-sdk-wrapped-6.0.428"
]
++ (cfg.config.permittedInsecurePackages or []);
} }
// (cfg.config or {}); // (cfg.config or {});
}; };

View file

@ -22,13 +22,6 @@ in {
; ;
}); });
# FIXME: Roslyn-ls uses dotnet6 https://github.com/NixOS/nixpkgs/blob/d3c42f187194c26d9f0309a8ecc469d6c878ce33/pkgs/by-name/ro/roslyn-ls/package.nix#L21
nixpkgs.config.permittedInsecurePackages = [
"dotnet-core-combined"
"dotnet-sdk-6.0.428"
"dotnet-sdk-wrapped-6.0.428"
];
environment.systemPackages = environment.systemPackages =
(optional (cfg.user != "nixos") (self.inputs.nurl.packages.${pkgs.system}.default.overrideAttrs { (optional (cfg.user != "nixos") (self.inputs.nurl.packages.${pkgs.system}.default.overrideAttrs {
postInstall = '' postInstall = ''