From 3e9863bb6a1f836bcdf6059a242f5b2cabc3662d Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 29 Jun 2022 00:02:00 +0200 Subject: [PATCH] Refactor neovim config into separate modules --- users/modules/neovim/default.nix | 61 +++++++++ users/modules/neovim/go.nix | 17 +++ users/modules/neovim/other_langs.nix | 68 ++++++++++ users/modules/neovim/rust.nix | 23 ++++ users/modules/neovim/web_dev.nix | 41 ++++++ users/modules/podman/containers.nix | 8 +- users/modules/podman/podman.nix | 7 +- users/profiles/mpv/default.nix | 6 +- users/profiles/neovim/default.nix | 187 +-------------------------- users/profiles/podman/default.nix | 2 +- users/profiles/sway/desktop.nix | 4 +- users/profiles/sway/scripts.nix | 4 +- users/profiles/sway/swayidle.nix | 6 +- 13 files changed, 234 insertions(+), 200 deletions(-) create mode 100644 users/modules/neovim/default.nix create mode 100644 users/modules/neovim/go.nix create mode 100644 users/modules/neovim/other_langs.nix create mode 100644 users/modules/neovim/rust.nix create mode 100644 users/modules/neovim/web_dev.nix diff --git a/users/modules/neovim/default.nix b/users/modules/neovim/default.nix new file mode 100644 index 0000000..4bf24db --- /dev/null +++ b/users/modules/neovim/default.nix @@ -0,0 +1,61 @@ +{ lib, pkgs, config, ... }@inputs: +with lib; +let + cfg = config.mae.nvim; +in +{ + imports = [ + ./go.nix + ./rust.nix + ./web_dev.nix + ./other_langs.nix + ]; + options.mae.nvim = { + enable = mkEnableOption "enable neovim"; + }; + config = { + programs.neovim = mkIf cfg.enable { + enable = true; + vimdiffAlias = true; + plugins = with pkgs.vimPlugins; [ + neoformat + undotree + + fzf-vim + { + plugin = iceberg-vim; + config = "colorscheme iceberg"; + } + vim-sleuth + + ]; + extraConfig = '' + set background=dark + set termguicolors + + set ic + set number + set autoindent + + set completeopt=menuone,noinsert,noselect + set shortmess+=c + ''; + coc.pluginConfig = '' + nmap (coc-rename) + + inoremap pumvisible() ? "\" : "\" + inoremap pumvisible() ? "\" : "\" + + " Remap and for scroll float windows/popups. + if has('nvim-0.4.0') || has('patch-8.2.0750') + nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" + endif + ''; + }; + }; +} diff --git a/users/modules/neovim/go.nix b/users/modules/neovim/go.nix new file mode 100644 index 0000000..b794acf --- /dev/null +++ b/users/modules/neovim/go.nix @@ -0,0 +1,17 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.mae.nvim.go; +in +with lib; +{ + options.mae.nvim.go = { + enable = mkEnableOption "Enable go support in nvim"; + }; + config.programs.neovim = mkIf cfg.enable { + coc.enable = true; + plugins = with pkgs.vimPlugins; [ + pkgs.go-fold-if-err-nil + coc-go + ]; + }; +} diff --git a/users/modules/neovim/other_langs.nix b/users/modules/neovim/other_langs.nix new file mode 100644 index 0000000..b1fafa1 --- /dev/null +++ b/users/modules/neovim/other_langs.nix @@ -0,0 +1,68 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.mae.nvim; +in +with lib; +{ + imports = [ + # Lua + ({ ... }: { + options.mae.nvim.lua.enable = mkEnableOption "Enable lua support in nvim"; + config.programs.neovim = mkIf cfg.lua.enable + { + coc.enable = true; + coc.settings.languageserver.lua = mkIf cfg.lua.enable { + command = "${pkgs.sumneko-lua-language-server}/bin/lua-language-server"; + rootPatterns = [ ".git" ]; + filetypes = [ + "lua" + ]; + }; + }; + }) + # Nix + ({ ... }: { + options.mae.nvim.nix.enable = mkEnableOption "Enable nix support in nvim"; + config.programs.neovim = mkIf cfg.nix.enable + { + plugins = with pkgs.vimPlugins; [ + vim-nix + ]; + coc.enable = true; + coc.settings.languageserver.nix = mkIf cfg.nix.enable { + "command" = "${pkgs.rnix-lsp}/bin/rnix-lsp"; + "filetypes" = [ + "nix" + ]; + }; + }; + }) + # Clangd + ({ ... }: { + options.mae.nvim.clangd.enable = mkEnableOption "Enable clangd support in nvim"; + config.programs.neovim = mkIf cfg.clangd.enable + { + plugins = with pkgs.vimPlugins; [ + coc-clangd + ]; + coc.enable = true; + coc.settings = { + "clangd.checkUpdates" = false; + # Use whatever clangd is in path for dependency reasons I think I don't remember at this point + "clangd.path" = "clangd"; + }; + }; + }) + # Python + ({ ... }: { + options.mae.nvim.python.enable = mkEnableOption "Enable python support in nvim"; + config.programs.neovim = mkIf cfg.python.enable + { + coc.enable = true; + plugins = with pkgs.vimPlugins; [ + coc-pyright + ]; + }; + }) + ]; +} diff --git a/users/modules/neovim/rust.nix b/users/modules/neovim/rust.nix new file mode 100644 index 0000000..41d4402 --- /dev/null +++ b/users/modules/neovim/rust.nix @@ -0,0 +1,23 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.mae.nvim.rust; +in +with lib; +{ + options.mae.nvim.rust = { + enable = mkEnableOption "Enable rust support in nvim"; + }; + config.programs.neovim = mkIf cfg.enable { + coc.enable = true; + plugins = with pkgs.vimPlugins; [ + coc-rust-analyzer + ]; + coc.settings = { + "rust-analyzer.server.path" = "${pkgs.rust-analyzer-nightly}/bin/rust-analyzer"; + "rust-analyzer.updates.prompt" = false; + "rust-analyzer.updates.checkOnStartup" = false; + "rust-analyzer.cargo.loadOutDirsFromCheck" = true; + "rust-analyzer.procMacro.enable" = true; + }; + }; +} diff --git a/users/modules/neovim/web_dev.nix b/users/modules/neovim/web_dev.nix new file mode 100644 index 0000000..c7c35a3 --- /dev/null +++ b/users/modules/neovim/web_dev.nix @@ -0,0 +1,41 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.mae.nvim; +in +with lib; +{ + options.mae.nvim.web = { + enable = mkEnableOption "Enable webdev support in nvim"; + }; + options.mae.nvim.js = { + enable = mkEnableOption "Enable js/ts support in nvim"; + }; + + config = mkMerge [ + (mkIf cfg.js.enable { + programs.neovim = { + coc.enable = true; + plugins = with pkgs.vimPlugins; [ + coc-tsserver + { + plugin = vim-jsdoc; + config = '' + let g:jsdoc_formatter = "tsdoc" + let g:typescript_indent_disable = 1 + ''; + } + ]; + }; + }) + (mkIf cfg.web.enable { + mae.nvim.js.enable = true; + programs.neovim = { + coc.enable = true; + plugins = with pkgs.vimPlugins; [ + coc-emmet + coc-html + ]; + }; + }) + ]; +} diff --git a/users/modules/podman/containers.nix b/users/modules/podman/containers.nix index fccc606..35a93cc 100644 --- a/users/modules/podman/containers.nix +++ b/users/modules/podman/containers.nix @@ -57,7 +57,7 @@ in }; insecure = mkOption { - default = []; + default = [ ]; type = types.listOf types.str; description = '' List of insecure repositories. @@ -65,7 +65,7 @@ in }; block = mkOption { - default = []; + default = [ ]; type = types.listOf types.str; description = '' List of blocked repositories. @@ -74,7 +74,7 @@ in }; policy = mkOption { - default = {}; + default = { }; type = types.attrs; example = lib.literalExample '' { @@ -116,7 +116,7 @@ in }; xdg.configFile."containers/policy.json".source = - if cfg.policy != {} then pkgs.writeText "policy.json" (builtins.toJSON cfg.policy) + if cfg.policy != { } then pkgs.writeText "policy.json" (builtins.toJSON cfg.policy) else "${pkgs.skopeo.src}/default-policy.json"; }; diff --git a/users/modules/podman/podman.nix b/users/modules/podman/podman.nix index 7d53f81..ced75de 100644 --- a/users/modules/podman/podman.nix +++ b/users/modules/podman/podman.nix @@ -177,6 +177,7 @@ in }; } (lib.mkIf cfg.dockerSocket.enable { - home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock"; }) - ]); - } + home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock"; + }) + ]); +} diff --git a/users/profiles/mpv/default.nix b/users/profiles/mpv/default.nix index 0d73f63..da20d98 100644 --- a/users/profiles/mpv/default.nix +++ b/users/profiles/mpv/default.nix @@ -1,9 +1,9 @@ -{pkgs, ...}: { +{ pkgs, ... }: { programs.mpv = { enable = true; config = { - slang= "eng"; - alang= "eng"; + slang = "eng"; + alang = "eng"; }; defaultProfiles = [ "gpu-hq" ]; scripts = with pkgs.mpvScripts; [ mpris ]; diff --git a/users/profiles/neovim/default.nix b/users/profiles/neovim/default.nix index 95cdf93..4242a52 100644 --- a/users/profiles/neovim/default.nix +++ b/users/profiles/neovim/default.nix @@ -1,187 +1,10 @@ { pkgs, config, ... }@inputs: { - programs.neovim = { - + mae.nvim = { enable = true; - vimdiffAlias = true; - withNodeJs = true; - - plugins = with pkgs.vimPlugins; [ - { - plugin = coc-nvim; - config = '' - nmap (coc-rename) - - inoremap pumvisible() ? "\" : "\" - inoremap pumvisible() ? "\" : "\" - - " Remap and for scroll float windows/popups. - if has('nvim-0.4.0') || has('patch-8.2.0750') - nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" - endif - ''; - } - fzf-vim - { - plugin = iceberg-vim; - config = "colorscheme iceberg"; - } - { - plugin = nvim-dap; - config = '' - lua < :lua require'dap'.continue() - nnoremap :lua require'dap'.step_over() - nnoremap :lua require'dap'.step_into() - nnoremap :lua require'dap'.step_out() - nnoremap b :lua require'dap'.toggle_breakpoint() - nnoremap B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) - nnoremap lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) - nnoremap dr :lua require'dap'.repl.open() - nnoremap dl :lua require'dap'.run_last() - ''; - } - { - plugin = nvim-dap-ui; - config = "lua require('dapui').setup()"; - } - - vim-sleuth - vim-nix - pkgs.go-fold-if-err-nil - coc-json - coc-emmet - coc-go - coc-html - coc-rust-analyzer - coc-pyright - coc-tsserver - coc-clangd - coc-lua - kotlin-vim - neoformat - undotree - { - plugin = vim-jsdoc; - config = '' - let g:jsdoc_formatter = "tsdoc" - let g:typescript_indent_disable = 1 - ''; - } - ]; - extraConfig = '' - set background=dark - set termguicolors - - set ic - set number - set autoindent - - set completeopt=menuone,noinsert,noselect - set shortmess+=c - ''; - coc.enable = true; - coc.settings = { - "coc.preferences.formatOnSaveFiletypes" = [ - "css" - "markdown" - "javascript" - "typescript" - ]; - "prettier.useTabs" = true; - "rust-analyzer.server.path" = "${pkgs.rust-analyzer-nightly}/bin/rust-analyzer"; - "rust-analyzer.updates.prompt" = false; - "rust-analyzer.updates.checkOnStartup" = false; - "rust-analyzer.cargo.loadOutDirsFromCheck" = true; - "rust-analyzer.procMacro.enable" = true; - "clangd.checkUpdates" = false; - "clangd.path" = "clangd"; - "svelte.plugin.svelte.format.enable" = false; - "languageserver" = { - "nix" = { - "command" = "${pkgs.rnix-lsp}/bin/rnix-lsp"; - "filetypes" = [ - "nix" - ]; - }; - "lua" = { - "command" = "${pkgs.sumneko-lua-language-server}/bin/lua-language-server"; - "rootPatterns" = [ ".git" ]; - "filetypes" = [ - "lua" - ]; - }; - }; - }; + js.enable = true; + nix.enable = true; + rust.enable = true; + clangd.enable = true; }; } diff --git a/users/profiles/podman/default.nix b/users/profiles/podman/default.nix index 8f2599b..24061fa 100644 --- a/users/profiles/podman/default.nix +++ b/users/profiles/podman/default.nix @@ -1,4 +1,4 @@ -{pkgs, ...}: +{ pkgs, ... }: { services.podman.enable = true; services.podman.defaultNetwork.dnsname.enable = true; diff --git a/users/profiles/sway/desktop.nix b/users/profiles/sway/desktop.nix index 33650c1..5e4b618 100644 --- a/users/profiles/sway/desktop.nix +++ b/users/profiles/sway/desktop.nix @@ -1,7 +1,7 @@ { pkgs, lib, ... }@inputs: let rofi = pkgs.rofi.override { plugins = [ pkgs.rofi-emoji ]; }; - scripts = ((import ./scripts.nix) inputs); + scripts = ((import ./scripts.nix) inputs); in { imports = [ ./swayidle.nix ]; @@ -40,7 +40,7 @@ in { command = "dbus-update-activation-environment WAYLAND_DISPLAY"; } ]; keybindings = lib.mkOptionDefault { - "XF86PowerOff" = "exec systemctl hybrid-sleep"; + "XF86PowerOff" = "exec systemctl hybrid-sleep"; }; }; wrapperFeatures.gtk = true; diff --git a/users/profiles/sway/scripts.nix b/users/profiles/sway/scripts.nix index 5e53c0f..4b70ece 100644 --- a/users/profiles/sway/scripts.nix +++ b/users/profiles/sway/scripts.nix @@ -1,5 +1,5 @@ -{ pkgs, ...}: { +{ pkgs, ... }: { lockscreen = pkgs.writeShellScriptBin "lockscreen" '' - ${pkgs.swaylock-effects}/bin/swaylock --screenshot --clock --effect-blur 10x10 + ${pkgs.swaylock-effects}/bin/swaylock --screenshot --clock --effect-blur 10x10 ''; } diff --git a/users/profiles/sway/swayidle.nix b/users/profiles/sway/swayidle.nix index a26fdd9..de26ff9 100644 --- a/users/profiles/sway/swayidle.nix +++ b/users/profiles/sway/swayidle.nix @@ -1,5 +1,5 @@ -{ pkgs, ... }@inputs: - let scripts = ((import ./scripts.nix) inputs); in +{ pkgs, ... }@inputs: +let scripts = ((import ./scripts.nix) inputs); in { services.swayidle = { enable = true; @@ -7,7 +7,7 @@ { event = "before-sleep"; command = "${scripts.lockscreen}/bin/lockscreen"; } ]; timeouts = [ -# { timeout = 300; command = "systemctl suspend"; } + # { timeout = 300; command = "systemctl suspend"; } ]; }; }