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;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in {
config = mkIf cfg.enable {
xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" {
@ -21,8 +22,17 @@ in {
''
vim.api.nvim_create_autocmd('FileType', {
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({
capabilities = default_capabilities,
autostart = false,
});
lsp.clangd.setup({
capabilities = default_capabilities,
autostart = false,
handlers = require('lsp-status').extensions.clangd.setup(),

View file

@ -10,19 +10,11 @@ self: {
inherit (lib) mkIf;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in {
config = mkIf cfg.enable {
programs = {
neovim = {
extraLuaConfig =
# lua
''
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'cs' },
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
'';
plugins = [
{
plugin = buildPlugin "roslyn-nvim" vimplugin-roslyn-nvim-src;
@ -38,6 +30,7 @@ in {
end,
});
local startRoslyn = function()
require('roslyn').setup({
config = {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
@ -66,6 +59,25 @@ in {
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
# lua
''
-- Init object to keep track of loaded devShells
local devShells = {};
-- Add formatting cmd
vim.api.nvim_create_user_command(
'Format',
@ -60,6 +63,7 @@ in {
# lsp plugins
nvim-lspconfig
lsp-status-nvim
nix-develop-nvim
# completion plugins
cmp-buffer
cmp-nvim-lsp

View file

@ -6,6 +6,7 @@
inherit (lib) mkIf;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in {
config = mkIf cfg.enable {
programs = {
@ -14,13 +15,18 @@ in {
# lua
''
vim.api.nvim_create_autocmd('FileType', {
pattern = 'yaml',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
pattern = { 'json', 'yaml' },
vim.api.nvim_create_autocmd('FileType', {
pattern = 'json',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
callback = function()
vim.cmd[[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');
@ -28,10 +34,12 @@ in {
lsp.jsonls.setup({
capabilities = default_capabilities,
autostart = false,
});
lsp.yamlls.setup({
capabilities = default_capabilities,
autostart = false,
settings = {
yaml = {

View file

@ -24,7 +24,17 @@ in {
vim.api.nvim_create_autocmd('FileType', {
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
@ -39,6 +49,7 @@ in {
require('lspconfig').lua_ls.setup({
capabilities = default_capabilities,
autostart = false,
});
'';
}

View file

@ -12,6 +12,7 @@ self: {
inherit (lib) concatStringsSep mkIf;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
isServer = osConfig.roles.server.sshd.enable or false;
githubCSS = pkgs.fetchurl {
@ -25,10 +26,26 @@ in {
extraLuaConfig =
# 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');
lsp.texlab.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
autostart = false,
settings = {
texlab = {
@ -80,12 +97,6 @@ in {
in
# lua
''
--
vim.api.nvim_create_autocmd('FileType', {
pattern = 'tex',
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
vim.g.knap_settings = {
-- HTML
htmloutputext = 'html',

View file

@ -1,36 +1,37 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib) attrValues mkIf;
inherit (lib) mkIf;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in {
config = mkIf cfg.enable {
programs = {
neovim = {
extraPackages = attrValues {
inherit
(pkgs)
cargo
rustc
rust-analyzer
rustfmt
;
};
extraLuaConfig =
# lua
''
vim.api.nvim_create_autocmd('FileType', {
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({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
autostart = false,
});
'';
};

View file

@ -10,6 +10,7 @@ self: {
inherit (lib) mkIf;
cfg = config.programs.neovim;
flakeEnv = config.programs.bash.sessionVariables.FLAKE;
in {
config = mkIf cfg.enable {
programs = {
@ -21,12 +22,32 @@ in {
''
vim.api.nvim_create_autocmd('FileType', {
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', {
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', {
@ -40,6 +61,7 @@ in {
tsserver.setup({
capabilities = default_capabilities,
autostart = false,
handlers = {
-- format error code with better error message
@ -52,6 +74,7 @@ in {
lsp.eslint.setup({
capabilities = default_capabilities,
autostart = false,
-- auto-save
on_attach = function(client, bufnr)
@ -102,6 +125,7 @@ in {
lsp.cssls.setup({
capabilities = default_capabilities,
autostart = false,
settings = {
css = {
@ -118,6 +142,7 @@ in {
lsp.somesass_ls.setup({
capabilities = default_capabilities,
autostart = false,
});
lsp.somesass_ls.manager.config.settings = {
somesass = {
@ -134,6 +159,8 @@ in {
lsp.html.setup({
capabilities = html_caps,
autostart = false,
settings = {
configurationSection = { "html", "css", "javascript" },
embeddedLanguages = {
@ -162,6 +189,7 @@ in {
# lua
''
local packageInfo = require('package-info');
packageInfo.setup({
hide_up_to_date = true,
package_manager = 'npm',
@ -169,6 +197,7 @@ in {
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
pattern = { 'package.json' },
callback = function()
packageInfo.show({ force = true });
end,

View file

@ -19,6 +19,15 @@ inputs: rec {
{
inherit cudaSupport;
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 {});
};

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 =
(optional (cfg.user != "nixos") (self.inputs.nurl.packages.${pkgs.system}.default.overrideAttrs {
postInstall = ''