diff --git a/home/common.nix b/home/common.nix index a8d6035..fcfc69d 100644 --- a/home/common.nix +++ b/home/common.nix @@ -2,7 +2,7 @@ { imports = [ - ./kakoune/kak.nix + ./kakoune.nix ./fish/fish.nix ./modules/programs/my-broot.nix ./modules/programs/my-waybar.nix diff --git a/home/kakoune.nix b/home/kakoune.nix new file mode 100644 index 0000000..09898c3 --- /dev/null +++ b/home/kakoune.nix @@ -0,0 +1,142 @@ +{ pkgs, lib, ... }: +let + +in +{ + imports = [ ./modules/programs/my-kakoune ]; + + home.packages = with pkgs; [ + # ctags for peneira + universal-ctags + # tree-sitter for kak + kak-tree-sitter + ]; + + # xdg.configFile."kak-tree-sitter/config.toml".source = ./kak-tree-sitter.toml; + + # Enable the kakoune package. + programs.my-kakoune.enable = true; + programs.my-kakoune.enable-fish-session = true; + programs.my-kakoune.tree-sitter.extraAliases = { + # Scala stuff + method = "function"; + module = "namespace"; + function_call = "function"; + method_call = "method"; + + boolean = "constant_builtin_boolean"; + number = "constant_numeric"; + float = "constant_numeric_float"; + + type_qualifier = "keyword_special"; + storageclass = "keyword_storage_modifier"; + conditional = "keyword_conditional"; + include = "keyword_control_import"; + }; + programs.my-kakoune.tree-sitter.languages = + let + tree-sitter-go = pkgs.fetchFromGitHub { + owner = "tree-sitter"; + repo = "tree-sitter-go"; + rev = "v0.20.0"; + hash = "sha256-G7d8CHCyKDAb9j6ijRfHk/HlgPqSI+uvkuRIRRvjkHI="; + }; + in + { + scala = + let + src = pkgs.fetchFromGitHub { + owner = "tree-sitter"; + repo = "tree-sitter-scala"; + rev = "70afdd5632d57dd63a960972ab25945e353a52f6"; + hash = "sha256-bi0Lqo/Zs2Uaz1efuKAARpEDg5Hm59oUe7eSXgL1Wow="; + }; + in + { + grammar.src = src; + queries.src = src; + queries.path = "queries/scala"; + }; + haskell = + let + src = pkgs.fetchFromGitHub { + owner = "tree-sitter"; + repo = "tree-sitter-haskell"; + rev = "ba0bfb0e5d8e9e31c160d287878c6f26add3ec08"; + hash = "sha256-ZSOF0CLOn82GwU3xgvFefmh/AD2j5zz8I0t5YPwfan0="; + }; + in + { + grammar.src = src; + grammar.compile.args = [ "-c" "-fpic" "../parser.c" "../scanner.c" "../unicode.h" "-I" ".." ]; + queries.src = src; + queries.path = "queries"; + }; + yaml = { + grammar.src = pkgs.fetchFromGitHub { + owner = "ikatyang"; + repo = "tree-sitter-yaml"; + rev = "0e36bed171768908f331ff7dff9d956bae016efb"; + hash = "sha256-bpiT3FraOZhJaoiFWAoVJX1O+plnIi8aXOW2LwyU23M="; + }; + grammar.compile.args = [ "-c" "-fpic" "../scanner.cc" "../parser.c" "-I" ".." ]; + grammar.link.args = [ "-shared" "-fpic" "scanner.o" "parser.o" ]; + grammar.link.flags = [ "-O3" "-lstdc++" ]; + + queries.src = pkgs.fetchFromGitHub { + owner = "helix-editor"; + repo = "helix"; + rev = "dbd248fdfa680373d94fbc10094a160aafa0f7a7"; + hash = "sha256-wk8qVUDFXhAOi1Ibc6iBMzDCXb6t+YiWZcTd0IJybqc="; + }; + queries.path = "runtime/queries/yaml"; + }; + + templ = + let + src = pkgs.fetchFromGitHub { + owner = "vrischmann"; + repo = "tree-sitter-templ"; + rev = "4519e3ec9ca92754ca25659bb1fd410d5e0f8d88"; + hash = "sha256-ic5SlqDEZoYakrJFe0H9GdzravqovlL5sTaHjyhe74M="; + }; + in + { + grammar.src = src; + queries.src = pkgs.runCommandLocal "templ-tree-sitter-queries" { } '' + mkdir -p $out/queries + # copy most stuff from tree-sitter-templ + install -m644 ${src}/queries/templ/* $out/queries + # override inherited files + cat ${tree-sitter-go}/queries/highlights.scm ${src}/queries/templ/highlights.scm > $out/queries/highlights.scm + ''; + queries.path = "queries"; + }; + + go = { + grammar.src = tree-sitter-go; + grammar.compile.args = [ "-c" "-fpic" "../parser.c" "-I" ".." ]; + grammar.link.args = [ "-shared" "-fpic" "parser.o" ]; + queries.src = tree-sitter-go; + queries.path = "queries"; + }; + + hylo = + let + src = pkgs.fetchFromGitHub { + owner = "natsukagami"; + repo = "tree-sitter-hylo"; + rev = "494cbdff0d13cbc67348316af2efa0286dbddf6f"; + hash = "sha256-R5UeoglCTl0do3VDJ/liCTeqbxU9slvmVKNRA/el2VY="; + }; + in + { + grammar.src = src; + grammar.compile.args = [ "-c" "-fpic" "../parser.c" "-I" ".." ]; + grammar.link.args = [ "-shared" "-fpic" "parser.o" ]; + queries.src = src; + queries.path = "queries"; + }; + }; +} + diff --git a/home/kakoune/kak.nix b/home/kakoune/kak.nix deleted file mode 100644 index ef7963e..0000000 --- a/home/kakoune/kak.nix +++ /dev/null @@ -1,516 +0,0 @@ -{ pkgs, lib, ... }: - -let - kak-lsp-frontend = { pkgs, lib, ... }: - let - langserver = name: { - name = "vscode-${name}-language-server"; - value = { - args = [ "--stdio" ]; - command = "vscode-${name}-language-server"; - filetypes = [ name ]; - roots = [ "package.json" ".git" ]; - }; - package = pkgs.nodePackages.vscode-langservers-extracted; - }; - - tailwind = { - command = "tailwindcss-language-server"; - args = [ "--stdio" ]; - filetypes = [ "html" "css" "javascript" "typescript" "templ" ]; - roots = [ "tailwind.config.{js,cjs,mjs,ts}" "package.json" ".git" ]; - settings_section = "tailwindCSS"; - settings.tailwindCSS = { - validate = "warning"; - userLanguages.templ = "html"; - }; - package = pkgs.tailwindcss-language-server; - }; - - templModule = { pkgs, lib, ... }: { - programs.kak-lsp.languageServers."vscode-html-language-server".filetypes = [ "templ" ]; - programs.kak-lsp.languageServers."tailwindcss-language-server".filetypes = [ "templ" ]; - programs.kak-lsp.languageServers.templ = { - command = "templ"; - args = [ "lsp" ]; - filetypes = [ "templ" ]; - roots = [ "go.mod" ".git" ]; - package = pkgs.unstable.templ; - }; - - }; - - in - { - imports = [ templModule ]; - - programs.kak-lsp.languageServers = (builtins.listToAttrs (map langserver [ "html" "css" "json" ])) // { - tailwindcss-language-server = tailwind; - }; - }; - - ltexLsp = { pkgs, lib, ... }: { - programs.kak-lsp.languageServers.ltex-ls = { - command = "ltex-ls"; - args = [ "--log-file=/tmp" ]; - filetypes = [ "latex" "typst" ]; - roots = [ "main.tex" "main.typ" ".git" ]; - package = pkgs.ltex-ls; - }; - }; - -in -{ - imports = [ ../modules/programs/my-kakoune ./kaktex.nix kak-lsp-frontend ltexLsp ]; - - home.packages = with pkgs; [ - # ctags for peneira - universal-ctags - # tree-sitter for kak - kak-tree-sitter - ]; - - # xdg.configFile."kak-tree-sitter/config.toml".source = ./kak-tree-sitter.toml; - - # Enable the kakoune package. - programs.my-kakoune.enable = true; - programs.my-kakoune.enable-fish-session = true; - programs.kak-lsp.enable = true; - programs.kak-lsp.semanticTokens.additionalFaces = [ - # Typst - { face = "header"; token = "heading"; } - { face = "ts_markup_link_url"; token = "link"; } - { face = "ts_markup_link_uri"; token = "ref"; } - { face = "ts_markup_link_label"; token = "label"; } - { face = "ts_property"; token = "pol"; } - { face = "ts_markup_list_checked"; token = "marker"; } - { face = "ts_constant_builtin_boolean"; token = "bool"; } - { face = "ts_keyword_control"; token = "delim"; } - { face = "ts_number"; token = "text"; modifiers = [ "math" ]; } - { face = "ts_markup_bold"; token = "text"; modifiers = [ "strong" ]; } - { face = "ts_markup_italic"; token = "text"; modifiers = [ "emph" ]; } - ]; - - programs.kak-lsp.languageServers.elixir-ls = { - args = [ ]; - command = "elixir-ls"; - filetypes = [ "elixir" ]; - roots = [ "mix.exs" ]; - }; - programs.kak-lsp.languageServers.typescript-language-server = { - args = [ "--stdio" ]; - command = "typescript-language-server"; - filetypes = [ "typescript" "javascript" ]; - roots = [ "package.json" ]; - package = pkgs.nodePackages.typescript-language-server; - }; - programs.kak-lsp.languageServers.fsautocomplete = { - args = [ "--adaptive-lsp-server-enabled" "--project-graph-enabled" "--source-text-factory" "RoslynSourceText" ]; - command = "fsautocomplete"; - filetypes = [ "fsharp" ]; - roots = [ "*.fsproj" ]; - settings_section = "FSharp"; - settings.FSharp = { - AutomaticWorkspaceInit = true; - }; - }; - programs.kak-lsp.languageServers.metals = { - command = "metals"; - filetypes = [ "scala" ]; - roots = [ "build.sbt" "build.sc" "build.mill" ]; - settings_section = "metals"; - settings.metals = { - enableSemanticHighlighting = true; - showInferredType = true; - decorationProvider = true; - inlineDecorationProvider = true; - # From kakoune-lsp's own options - icons = "unicode"; - isHttpEnabled = true; - statusBarProvider = "log-message"; - compilerOptions = { overrideDefFormat = "unicode"; }; - }; - package = pkgs.metals; - }; - programs.kak-lsp.languageServers.texlab = { - command = "texlab"; - filetypes = [ "latex" ]; - roots = [ "main.tex" "all.tex" ".git" ]; - settings_section = "texlab"; - settings.texlab = { - build.executable = "latexmk"; - build.args = [ "-pdf" "-shell-escape" "-interaction=nonstopmode" "-synctex=1" "%f" ]; - - build.forwardSearchAfter = true; - build.onSave = true; - - forwardSearch = - (if pkgs.stdenv.isDarwin then { - executable = "/Applications/Skim.app/Contents/SharedSupport/displayline"; - args = [ "-r" "-g" "%l" "%p" "%f" ]; - } else - { - executable = "${pkgs.zathura}/bin/zathura"; - args = [ "--synctex-forward" "%l:1:%f" "%p" "-x" "${./kaktex} jump %%{input} %%{line} %%{column}" ]; - }); - }; - package = pkgs.texlab; - }; - programs.kak-lsp.languageServers.tinymist = { - command = "tinymist"; - filetypes = [ "typst" ]; - roots = [ "main.typ" ".git" ]; - settings_section = "tinymist"; - settings.tinymist = { - exportPdf = "onSave"; - formatterMode = "typstfmt"; - }; - }; - programs.kak-lsp.languageServers.marksman = { - command = "marksman"; - filetypes = [ "markdown" ]; - roots = [ ".marksman.toml" ".git" ]; - package = pkgs.marksman; - }; - programs.kak-lsp.languageServers.rust-analyzer = { - args = [ ]; - command = "rust-analyzer"; - filetypes = [ "rust" ]; - roots = [ "Cargo.toml" ]; - package = pkgs.rust-analyzer; - }; - - programs.my-kakoune.tree-sitter.extraAliases = { - # Scala stuff - method = "function"; - module = "namespace"; - function_call = "function"; - method_call = "method"; - - boolean = "constant_builtin_boolean"; - number = "constant_numeric"; - float = "constant_numeric_float"; - - type_qualifier = "keyword_special"; - storageclass = "keyword_storage_modifier"; - conditional = "keyword_conditional"; - include = "keyword_control_import"; - }; - programs.my-kakoune.tree-sitter.languages = - let - tree-sitter-go = pkgs.fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-go"; - rev = "v0.20.0"; - hash = "sha256-G7d8CHCyKDAb9j6ijRfHk/HlgPqSI+uvkuRIRRvjkHI="; - }; - in - { - scala = - let - src = pkgs.fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-scala"; - rev = "70afdd5632d57dd63a960972ab25945e353a52f6"; - hash = "sha256-bi0Lqo/Zs2Uaz1efuKAARpEDg5Hm59oUe7eSXgL1Wow="; - }; - in - { - grammar.src = src; - queries.src = src; - queries.path = "queries/scala"; - }; - haskell = - let - src = pkgs.fetchFromGitHub { - owner = "tree-sitter"; - repo = "tree-sitter-haskell"; - rev = "ba0bfb0e5d8e9e31c160d287878c6f26add3ec08"; - hash = "sha256-ZSOF0CLOn82GwU3xgvFefmh/AD2j5zz8I0t5YPwfan0="; - }; - in - { - grammar.src = src; - grammar.compile.args = [ "-c" "-fpic" "../parser.c" "../scanner.c" "../unicode.h" "-I" ".." ]; - queries.src = src; - queries.path = "queries"; - }; - yaml = { - grammar.src = pkgs.fetchFromGitHub { - owner = "ikatyang"; - repo = "tree-sitter-yaml"; - rev = "0e36bed171768908f331ff7dff9d956bae016efb"; - hash = "sha256-bpiT3FraOZhJaoiFWAoVJX1O+plnIi8aXOW2LwyU23M="; - }; - grammar.compile.args = [ "-c" "-fpic" "../scanner.cc" "../parser.c" "-I" ".." ]; - grammar.link.args = [ "-shared" "-fpic" "scanner.o" "parser.o" ]; - grammar.link.flags = [ "-O3" "-lstdc++" ]; - - queries.src = pkgs.fetchFromGitHub { - owner = "helix-editor"; - repo = "helix"; - rev = "dbd248fdfa680373d94fbc10094a160aafa0f7a7"; - hash = "sha256-wk8qVUDFXhAOi1Ibc6iBMzDCXb6t+YiWZcTd0IJybqc="; - }; - queries.path = "runtime/queries/yaml"; - }; - - templ = - let - src = pkgs.fetchFromGitHub { - owner = "vrischmann"; - repo = "tree-sitter-templ"; - rev = "044ad200092170727650fa6d368df66a8da98f9d"; - hash = "sha256-hJuB3h5pp+LLfP0/7bAYH0uLVo+OQk5jpzJb3J9BNkY="; - }; - in - { - grammar.src = src; - queries.src = pkgs.runCommandLocal "templ-tree-sitter-queries" { } '' - mkdir -p $out/queries - # copy most stuff from tree-sitter-templ - install -m644 ${src}/queries/templ/* $out/queries - # override inherited files - cat ${tree-sitter-go}/queries/highlights.scm ${src}/queries/templ/highlights.scm > $out/queries/highlights.scm - ''; - queries.path = "queries"; - }; - - go = { - grammar.src = tree-sitter-go; - grammar.compile.args = [ "-c" "-fpic" "../parser.c" "-I" ".." ]; - grammar.link.args = [ "-shared" "-fpic" "parser.o" ]; - queries.src = tree-sitter-go; - queries.path = "queries"; - }; - - hylo = - let - src = pkgs.fetchFromGitHub { - owner = "natsukagami"; - repo = "tree-sitter-hylo"; - rev = "494cbdff0d13cbc67348316af2efa0286dbddf6f"; - hash = "sha256-R5UeoglCTl0do3VDJ/liCTeqbxU9slvmVKNRA/el2VY="; - }; - in - { - grammar.src = src; - grammar.compile.args = [ "-c" "-fpic" "../parser.c" "-I" ".." ]; - grammar.link.args = [ "-shared" "-fpic" "parser.o" ]; - queries.src = src; - queries.path = "queries"; - }; - }; - - programs.my-kakoune.package = pkgs.kakoune; - programs.my-kakoune.rc = - builtins.readFile ./kakrc + '' - - # Source any settings in the current working directory, - # recursive upwards - evaluate-commands %sh{ - ${pkgs.writeScript "source-pwd" (builtins.readFile ./source-pwd)} - } - ''; - - programs.my-kakoune.extraFaces = { - Default = "%opt{text},%opt{base}"; - BufferPadding = "%opt{base},%opt{base}"; - MenuForeground = "%opt{blue},white+bF"; - MenuBackground = "%opt{sky},white+F"; - Information = "%opt{sky},white"; - # Markdown help color scheme - InfoDefault = "Information"; - InfoBlock = "@block"; - InfoBlockQuote = "+i@block"; - InfoBullet = "@bullet"; - InfoHeader = "@header"; - InfoLink = "@link"; - InfoLinkMono = "+b@mono"; - InfoMono = "@mono"; - InfoRule = "+b@Information"; - InfoDiagnosticError = "@DiagnosticError"; - InfoDiagnosticHint = "@DiagnosticHint"; - InfoDiagnosticInformation = "@Information"; - InfoDiagnosticWarning = "@DiagnosticWarning"; - # Extra faces - macro = "+u@function"; - method = "@function"; - format_specifier = "+i@string"; - mutable_variable = "+i@variable"; - class = "+b@variable"; - }; - programs.my-kakoune.autoload = [ - # My own scripts - { - name = "latex.kak"; - src = ./autoload/latex.kak; - } - { - name = "markdown.kak"; - src = ./autoload/markdown.kak; - } - - # Plugins - { - name = "luar"; - src = pkgs.fetchFromGitHub { - owner = "gustavo-hms"; - repo = "luar"; - rev = "2f430316f8fc4d35db6c93165e2e77dc9f3d0450"; - sha256 = "sha256-vHn/V3sfzaxaxF8OpA5jPEuPstOVwOiQrogdSGtT6X4="; - }; - activationScript = '' - # Enable luar - require-module luar - # Use luajit - set-option global luar_interpreter ${pkgs.luajit}/bin/luajit - ''; - } - { - name = "peneira"; - src = pkgs.fetchFromGitHub { - owner = "natsukagami"; - repo = "peneira"; - rev = "743b9971472853a752475e7c070ce99089c6840c"; - sha256 = "sha256-E4ndbF9YC1p0KrvSuGgwmG1Y2IGTuGKJo/AuMixhzlM="; - }; - activationScript = '' - require-module peneira - - # Change selection color - set-face global PeneiraSelected @PrimarySelection - - # Buffers list - define-command -hidden peneira-buffers %{ - peneira 'buffers: ' %{ printf '%s\n' $kak_quoted_buflist } %{ - buffer %arg{1} - } - } - - # Grep in the current location - define-command peneira-grep %{ - peneira 'line: ' "rg -n ." %{ - lua %arg{1} %{ - local file, line = arg[1]:match("([^:]+):(%d+):") - kak.edit(file, line) - } - } - } - - # A peneira menu - declare-user-mode fuzzy-match-menu - - map -docstring "Switch to buffer" global fuzzy-match-menu b ": peneira-buffers" - map -docstring "Symbols" global fuzzy-match-menu s ": peneira-symbols" - map -docstring "Lines" global fuzzy-match-menu l ": peneira-lines" - map -docstring "Lines in the current directory" global fuzzy-match-menu g ": peneira-grep" - map -docstring "Files in project" global fuzzy-match-menu f ": peneira-files" - map -docstring "Files in currently opening file's directory" global fuzzy-match-menu F ": peneira-local-files" - - # Bind menu to user mode - map -docstring "Fuzzy matching" global user f ": enter-user-mode fuzzy-match-menu" - ''; - } - { - name = "kakoune-focus"; - src = pkgs.fetchFromGitHub { - owner = "caksoylar"; - repo = "kakoune-focus"; - rev = "949c0557cd4c476822acfa026ca3c50f3d38a3c0"; - sha256 = "sha256-ZV7jlLJQyL420YG++iC9rq1SMjo3WO5hR9KVvJNUiCs="; - }; - activationScript = '' - map global user ': focus-toggle' -docstring "toggle selections focus" - ''; - } - { - name = "kakoune-inc-dec"; - src = pkgs.fetchFromGitLab { - owner = "Screwtapello"; - repo = "kakoune-inc-dec"; - rev = "7bfe9c51"; - sha256 = "0f33wqxqbfygxypf348jf1fiscac161wf2xvnh8zwdd3rq5yybl0"; - }; - } - { - name = "racket.kak"; - src = (builtins.fetchTree { - type = "git"; - url = "https://bitbucket.org/KJ_Duncan/kakoune-racket.kak.git"; - rev = "e397042009b46916ff089d79166ec0e8ca813a18"; - narHash = "sha256-IcxFmvG0jqpMCG/dT9crVRgPgMGKkic6xwrnW5z4+bc="; - }) + "/rc"; - } - # { - # name = "kakoune-discord"; - # src = (builtins.getFlake "github:natsukagami/kakoune-discord/03f95e40d6efd8fd3de7bca31653d43de2dcfc5f").packages.${pkgs.system}.kakoune-discord-rc + "/rc"; - # } - rec { - name = "kakoune-mirror"; - src = pkgs.fetchFromGitHub - { - owner = "Delapouite"; - repo = "kakoune-mirror"; - rev = "5710635f440bcca914d55ff2ec1bfcba9efe0f15"; - sha256 = "sha256-uslx4zZhvjUylrPWvTOugsKYKKpF0EEz1drc1Ckrpjk="; - } + "/mirror.kak"; - wrapAsModule = true; - activationScript = '' - require-module ${name} - - # Bind to ${name} - map global normal ': enter-user-mode -lock mirror' - ''; - } - { - name = "unicode-math"; - src = pkgs.fetchFromGitHub { - owner = "natsukagami"; - repo = "kakoune-unicode-math"; - rev = "08dff25da2b86ee0b0777091992bc7fb28c3cb1d"; - # sha256 = lib.fakeSha256; - sha256 = "sha256-j0L1ARex1i2ma8sGLYwgkfAbh0jWKh/6QGHFaxPXIKc="; - fetchSubmodules = true; - }; - activationScript = '' - require-module unicode-math - - # Bind to the menu - map global insert ': insert-unicode ' - ''; - } - { - name = "kakoune-buffers"; - src = pkgs.fetchFromGitHub { - owner = "Delapouite"; - repo = "kakoune-buffers"; - rev = "6b2081f5b7d58c72de319a5cba7bf628b6802881"; - sha256 = "sha256-jOSrzGcLJjLK1GiTSsl2jLmQMPbPxjycR0pwF5t/eV0="; - }; - activationScript = '' - # Suggested hook - - hook global WinDisplay .* info-buffers - - # Suggested mappings - - map global user b ':enter-buffers-mode' -docstring 'buffers…' - map global normal ^ ':enter-buffers-mode' -docstring 'buffers…' - map global user B ':enter-user-mode -lock buffers' -docstring 'buffers (lock)…' - - # Suggested aliases - - alias global bd delete-buffer - alias global bf buffer-first - alias global bl buffer-last - alias global bo buffer-only - alias global bo! buffer-only-force - ''; - } - ]; - programs.my-kakoune.themes = { - catppuccin-latte = ./catppuccin-latte.kak; - }; -} - diff --git a/home/kakoune/kaktex.nix b/home/kakoune/kaktex.nix deleted file mode 100644 index 1256c79..0000000 --- a/home/kakoune/kaktex.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - # Source kaktex whenever we have a tex file - programs.my-kakoune.rc = '' - hook global WinSetOption filetype=(tex|latex) %{ - hook window WinDisplay '.*' %{ - eval %sh{ - ${./kaktex} set $kak_client $kak_session - } - } - } - ''; -} diff --git a/home/modules/programs/my-kakoune/default.nix b/home/modules/programs/my-kakoune/default.nix index 125484a..62a9cb1 100644 --- a/home/modules/programs/my-kakoune/default.nix +++ b/home/modules/programs/my-kakoune/default.nix @@ -1,40 +1,17 @@ -{ config, pkgs, lib, ... }: +{ config, options, pkgs, lib, ... }: with lib; let cfg = config.programs.my-kakoune; - - autoloadModule = types.submodule { - options = { - name = mkOption { - type = types.str; - description = "Name of the autoload script/folder. It might affect kakoune's load order."; - }; - src = mkOption { - type = types.path; - description = "Path to the autoload script/folder."; - }; - wrapAsModule = mkOption { - type = types.bool; - default = false; - description = "Wrap the given source file in a `provide-module` command. Fails if the `src` is not a single file."; - }; - activationScript = mkOption { - type = types.nullOr types.lines; - default = null; - description = "Add an activation script to the module. It will be wrapped in a `hook global KakBegin .*` wrapper."; - }; - }; - }; in { - imports = [ ./kak-lsp.nix ./fish-session.nix ./tree-sitter.nix ]; + imports = [ ./fish-session.nix ./tree-sitter.nix ]; options.programs.my-kakoune = { enable = mkEnableOption "My version of the kakoune configuration"; package = mkOption { type = types.package; - default = pkgs.kakoune; + default = pkgs.nki-kakoune; description = "The kakoune package to be installed"; }; rc = mkOption { @@ -42,22 +19,16 @@ in default = ""; description = "Content of the kakrc file. A line-concatenated string"; }; - autoload = mkOption { - type = types.listOf autoloadModule; - default = [ ]; - description = "Sources to autoload"; - }; - themes = mkOption { - type = types.attrsOf types.path; - default = { }; - description = "Themes to load"; - }; - extraFaces = mkOption { type = types.attrsOf types.str; default = { }; description = "Extra faces to include"; }; + autoloadFile = mkOption { + type = options.xdg.configFile.type; + default = { }; + description = "Extra autoload files"; + }; }; config = mkIf cfg.enable { @@ -65,37 +36,6 @@ in xdg.configFile = let - kakouneAutoload = { name, src, wrapAsModule ? false, activationScript ? null }: - [ - (if !wrapAsModule then { - name = "kak/autoload/${name}"; - value.source = src; - } else { - name = "kak/autoload/${name}/module.kak"; - value.text = '' - provide-module ${name} %◍ - ${readFile src} - ◍ - ''; - }) - ] ++ (if activationScript == null then [ ] else [{ - name = "kak/autoload/on-load/${name}.kak"; - value.text = '' - hook global KakBegin .* %{ - ${activationScript} - } - ''; - }]); - - kakouneThemes = builtins.listToAttrs (builtins.attrValues ( - builtins.mapAttrs - (name: src: { - name = "kak/colors/${name}.kak"; - value.source = src; - }) - cfg.themes - )); - kakouneFaces = let txt = strings.concatStringsSep "\n" (builtins.attrValues (builtins.mapAttrs (name: face: "face global ${name} \"${face}\"") cfg.extraFaces)); @@ -103,6 +43,7 @@ in pkgs.writeText "faces.kak" txt; in { + "kak/autoload/builtin".source = "${cfg.package}/share/kak/autoload"; # kakrc "kak/kakrc".text = '' ${cfg.rc} @@ -110,15 +51,14 @@ in # Load faces source ${kakouneFaces} ''; - } // - (builtins.listToAttrs (lib.lists.flatten (map kakouneAutoload ([ - # include the original autoload files - { - name = "rc"; - src = "${cfg.package}/share/kak/autoload/rc"; - } - ] ++ cfg.autoload)))) - // kakouneThemes; + } // lib.mapAttrs' + (name: attrs: { + name = "kak/autoload/${name}"; + value = attrs // { + target = "kak/autoload/${name}"; + }; + }) + cfg.autoloadFile; }; } diff --git a/home/modules/programs/my-kakoune/kak-lsp.nix b/home/modules/programs/my-kakoune/kak-lsp.nix deleted file mode 100644 index eaf3b6b..0000000 --- a/home/modules/programs/my-kakoune/kak-lsp.nix +++ /dev/null @@ -1,213 +0,0 @@ -{ config, pkgs, lib, ... }: - -with lib; -let - lspConfig = - { - language_ids = { - c = "c_cpp"; - cpp = "c_cpp"; - javascript = "javascriptreact"; - typescript = "typescriptreact"; - protobuf = "proto"; - sh = "shellscript"; - }; - - language_servers = { - ccls = { - args = [ "-v=2" "-log-file=/tmp/ccls.log" ]; - command = "ccls"; - filetypes = [ "c" "cpp" ]; - roots = [ "compile_commands.json" ".cquery" ".git" ]; - }; - gopls = { - command = "gopls"; - filetypes = [ "go" ]; - offset_encoding = "utf-8"; - roots = [ "Gopkg.toml" "go.mod" ".git" ".hg" ]; - settings = { gopls = { hoverKind = "SynopsisDocumentation"; semanticTokens = true; }; }; - settings_section = "gopls"; - }; - haskell-language-server = { - args = [ "--lsp" ]; - command = "haskell-language-server-wrapper"; - filetypes = [ "haskell" ]; - roots = [ "Setup.hs" "stack.yaml" "*.cabal" "package.yaml" ]; - settings_section = "haskell"; - }; - nil = { - command = "${pkgs.nil}/bin/nil"; - filetypes = [ "nix" ]; - roots = [ "flake.nix" "shell.nix" ".git" ]; - settings.nil = { - formatting.command = [ "${getExe pkgs.nixpkgs-fmt}" ]; - }; - }; - pyls = { - command = "pyls"; - filetypes = [ "python" ]; - offset_encoding = "utf-8"; - roots = [ "requirements.txt" "setup.py" ".git" ".hg" ]; - }; - }; - semantic_tokens.faces = [ - ## Items - # (Rust) Macros - { face = "attribute"; token = "attribute"; } - { face = "attribute"; token = "derive"; } - { face = "macro"; token = "macro"; } # Function-like Macro - # Keyword and Fixed Tokens - { face = "keyword"; token = "keyword"; } - { face = "operator"; token = "operator"; } - # Functions and Methods - { face = "function"; token = "function"; } - { face = "method"; token = "method"; } - # Constants - { face = "string"; token = "string"; } - { face = "format_specifier"; token = "formatSpecifier"; } - # Variables - { face = "variable"; token = "variable"; modifiers = [ "readonly" ]; } - { face = "mutable_variable"; token = "variable"; } - { face = "module"; token = "namespace"; } - { face = "variable"; token = "type_parameter"; } - { face = "class"; token = "enum"; } - { face = "class"; token = "struct"; } - { face = "class"; token = "trait"; } - { face = "class"; token = "union"; } - { face = "class"; token = "class"; } - - ## Comments - { face = "documentation"; token = "comment"; modifiers = [ "documentation" ]; } - { face = "comment"; token = "comment"; } - ]; - server = { timeout = 1800; }; - snippet_support = false; - verbosity = 255; - }; - - languageServerOption = types.submodule { - options = { - filetypes = mkOption { - type = types.listOf types.str; - description = "The list of filetypes to assign the language to"; - }; - roots = mkOption { - type = types.listOf types.str; - description = "The list of root filenames that are used to determine the project root"; - }; - command = mkOption { - type = types.str; - description = "The LSP server command to be called."; - }; - args = mkOption { - type = types.listOf types.str; - default = [ ]; - description = "The arguments passed onto the LSP server."; - }; - offset_encoding = mkOption { - type = types.nullOr (types.enum [ "utf-8" ]); - default = null; - description = "The offset encoding used by the LSP server."; - }; - settings_section = mkOption { - type = types.nullOr types.str; - default = null; - description = "The settings section to be sent to LSP server."; - }; - settings = mkOption { - type = types.nullOr (types.attrsOf types.anything); - default = null; - description = "Additional settings to be passed to the LSP server."; - }; - package = mkOption { - type = types.nullOr types.package; - default = null; - description = "The default package of the language server. Will be appended as the ending segments of the PATH to kak-lsp"; - }; - }; - }; - - cfg = config.programs.kak-lsp; - - serverPackages = - filter (v: v != null) - (lib.mapAttrsToList (_: serv: serv.package) cfg.languageServers); - - wrappedPackage = pkgs.symlinkJoin { - name = "kak-lsp-wrapped"; - nativeBuildInputs = [ pkgs.makeWrapper ]; - paths = [ cfg.package ]; - postBuild = '' - wrapProgram $out/bin/kak-lsp --suffix PATH ":" ${lib.makeBinPath serverPackages} - ''; - }; -in -{ - options.programs.kak-lsp = { - enable = mkEnableOption "Enable kak-lsp support"; - - package = mkOption { - type = types.package; - default = pkgs.kak-lsp; - }; - - enableSnippets = mkOption { - type = types.bool; - default = false; - description = "Enable snippet support"; - }; - - semanticTokens.faces = mkOption { - type = types.listOf types.anything; - default = lspConfig.semantic_tokens.faces; - description = "The semantic tokens faces mapping given to kak"; - }; - semanticTokens.additionalFaces = mkOption { - type = types.listOf types.anything; - default = [ ]; - description = "The semantic tokens faces mapping given to kak"; - }; - - serverTimeout = mkOption { - type = types.int; - default = 1000; - description = "Server timeout"; - }; - - languageServers = mkOption { - type = types.attrsOf languageServerOption; - default = { }; - description = "The language options"; - }; - - languageIds = mkOption { - type = types.attrsOf types.str; - default = { }; - description = "Language IDs to be sent to the LSP"; - }; - }; - - config = mkIf cfg.enable - { - home.packages = [ wrappedPackage ]; - - # Configurations - xdg.configFile."kak-lsp/kak-lsp.toml" = - let - toml = pkgs.formats.toml { }; - toLspConfig = lib.filterAttrsRecursive (n: v: n != "package" && v != null); - in - { - source = toml.generate "config.toml" - { - semantic_tokens.faces = cfg.semanticTokens.faces ++ cfg.semanticTokens.additionalFaces; - server.timeout = cfg.serverTimeout; - snippet_support = cfg.enableSnippets; - verbosity = 255; - language_server = toLspConfig (lspConfig.language_servers // cfg.languageServers); - language_ids = lspConfig.language_ids // cfg.languageIds; - }; - }; - }; -} - diff --git a/home/modules/programs/my-kakoune/tree-sitter.nix b/home/modules/programs/my-kakoune/tree-sitter.nix index 4304ca5..07f12cf 100644 --- a/home/modules/programs/my-kakoune/tree-sitter.nix +++ b/home/modules/programs/my-kakoune/tree-sitter.nix @@ -33,6 +33,27 @@ let }; }; }; + mkGrammarPackage = + { name + , src + , grammarPath ? "src" + , grammarCompileArgs ? [ "-O3" "-c" "-fpic" "../parser.c" "../scanner.c" "-I" ".." ] + , grammarLinkArgs ? [ "-shared" "-fpic" "parser.o" "scanner.o" ] + }: pkgs.stdenv.mkDerivation { + inherit src; + name = "kak-tree-sitter-grammar-${name}.so"; + version = "latest"; + buildPhase = '' + mkdir ${grammarPath}/build + cd ${grammarPath}/build + $CC ${lib.concatStringsSep " " grammarCompileArgs} + $CC ${lib.concatStringsSep " " grammarLinkArgs} -o ${name}.so + ''; + installPhase = '' + cp ${name}.so $out + ''; + }; + in { options.programs.my-kakoune.tree-sitter = { @@ -200,24 +221,15 @@ in toml = pkgs.formats.toml { }; - srcName = src: lib.removePrefix "/nix/store/" src.outPath; - mkGitRepo = src: pkgs.runCommandLocal "${src.name}-git" { } '' - cp -r --no-preserve=all ${src} $out - cd $out - if ! test -d $out/.git; then - ${lib.getExe pkgs.git} init -b ${srcName src} - ${lib.getExe pkgs.git} config user.email "a@b.com" - ${lib.getExe pkgs.git} config user.name "a" - ${lib.getExe pkgs.git} add . - ${lib.getExe pkgs.git} commit -m "Just making a git commit" - fi - ''; - toLanguageConf = name: lang: with lang; { grammar = { - inherit (grammar) path; - source.git.url = "${mkGitRepo grammar.src}"; - source.git.pin = "${srcName grammar.src}"; + source.local.path = mkGrammarPackage { + inherit name; + src = grammar.src; + grammarPath = grammar.path; + grammarCompileArgs = grammar.compile.flags ++ grammar.compile.args; + grammarLinkArgs = grammar.link.flags ++ grammar.link.args; + }; compile = grammar.compile.command; compile_args = grammar.compile.args; compile_flags = grammar.compile.flags; @@ -225,10 +237,9 @@ in link_args = grammar.link.args ++ [ "-o" "${name}.so" ]; link_flags = grammar.link.flags; }; - queries = { - source.git.url = "${mkGitRepo queries.src}"; - source.git.pin = "${srcName queries.src}"; + queries = rec { path = if queries.path == null then "runtime/queries/${name}" else queries.path; + source.local.path = "${queries.src}/${path}"; }; }; in @@ -249,14 +260,14 @@ in features = cfg.features; language = builtins.mapAttrs toLanguageConf cfg.languages; }; - - onChange = '' - export PATH=$PATH:${lib.getBin pkgs.gcc} - ${cfg.package}/bin/ktsctl sync -a - ''; }; programs.my-kakoune.extraFaces = faces; + programs.my-kakoune.autoloadFile."kak-tree-sitter.kak".text = '' + # Enable kak-tree-sitter + eval %sh{kak-tree-sitter --kakoune -d --server --init $kak_session} + map global normal ": enter-user-mode tree-sitter" + ''; }; } diff --git a/modules/common/linux/default.nix b/modules/common/linux/default.nix index 36bef19..72413f4 100644 --- a/modules/common/linux/default.nix +++ b/modules/common/linux/default.nix @@ -76,6 +76,7 @@ let virtualisation = { pkgs, ... }: mkIf cfg.enable { virtualisation.podman = { enable = true; + extraPackages = [ pkgs.slirp4netns ]; dockerCompat = true; defaultNetwork.settings.dns_enabled = true; }; diff --git a/overlay.nix b/overlay.nix index 1e60c41..a3d5f70 100644 --- a/overlay.nix +++ b/overlay.nix @@ -90,7 +90,7 @@ let }; overlay-packages = final: prev: { - kak-tree-sitter = final.callPackage ./packages/common/kak-tree-sitter.nix { rustPlatform = final.unstable.rustPlatform; }; + kak-tree-sitter = final.callPackage ./packages/common/kak-tree-sitter { rustPlatform = final.unstable.rustPlatform; }; kak-lsp = let @@ -102,6 +102,8 @@ let buildInputs = (with final; lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Security SystemConfiguration CoreServices ]) ) ++ (with final; [ libiconv ]); + + meta.mainProgram = "kak-lsp"; }; zen-browser-bin = final.callPackage inputs.zen-browser.packages.${final.stdenv.system}.zen-browser.override { diff --git a/packages/common/default.nix b/packages/common/default.nix index be4ba2a..fadb679 100644 --- a/packages/common/default.nix +++ b/packages/common/default.nix @@ -2,4 +2,5 @@ final: prev: { epfl-cups-drivers = final.callPackage ./epfl-cups-drivers { }; ttaenc = final.callPackage ./ttaenc.nix { }; suwako-cursors = final.callPackage ./suwako-cursors { }; + nki-kakoune = final.callPackage ./nki-kakoune { }; } diff --git a/packages/common/kak-tree-sitter.nix b/packages/common/kak-tree-sitter/default.nix similarity index 96% rename from packages/common/kak-tree-sitter.nix rename to packages/common/kak-tree-sitter/default.nix index 3e0c6a9..9819e3a 100644 --- a/packages/common/kak-tree-sitter.nix +++ b/packages/common/kak-tree-sitter/default.nix @@ -35,6 +35,8 @@ let self.runtime_dir.join("sources").join(url_dir) '') ]; + + meta.mainProgram = "kak-tree-sitter"; }; in kak-tree-sitter diff --git a/home/kakoune/autoload/latex.kak b/packages/common/nki-kakoune/autoload/latex.kak similarity index 100% rename from home/kakoune/autoload/latex.kak rename to packages/common/nki-kakoune/autoload/latex.kak diff --git a/home/kakoune/autoload/markdown.kak b/packages/common/nki-kakoune/autoload/markdown.kak similarity index 100% rename from home/kakoune/autoload/markdown.kak rename to packages/common/nki-kakoune/autoload/markdown.kak diff --git a/packages/common/nki-kakoune/default.nix b/packages/common/nki-kakoune/default.nix new file mode 100644 index 0000000..f4851af --- /dev/null +++ b/packages/common/nki-kakoune/default.nix @@ -0,0 +1,25 @@ +{ callPackage, kakoune, kakoune-unwrapped, ... }: +let + lsp = callPackage ./lsp.nix { }; + rc = (callPackage ./rc.nix { }); +in +(kakoune.override { + plugins = callPackage ./plugins.nix { } + ++ callPackage ./themes.nix { } + ++ [ + (callPackage ./kaktex { }) + (callPackage ./faces.nix { }) + rc + lsp.plugin + ]; +}).overrideAttrs (attrs: { + buildCommand = '' + ${attrs.buildCommand or ""} + # location of kak binary is used to find ../share/kak/autoload, + # unless explicitly overriden with KAKOUNE_RUNTIME + rm "$out/bin/kak" + makeWrapper "${kakoune-unwrapped}/bin/kak" "$out/bin/kak" \ + --set KAKOUNE_RUNTIME "$out/share/kak" \ + --suffix PATH ":" "${lsp.extraPaths}" + ''; +}) diff --git a/packages/common/nki-kakoune/faces.nix b/packages/common/nki-kakoune/faces.nix new file mode 100644 index 0000000..367472c --- /dev/null +++ b/packages/common/nki-kakoune/faces.nix @@ -0,0 +1,31 @@ +{ callPackage, ... } : +let +utils = callPackage ./utils.nix { }; +faces = { + Default = "%opt{text},%opt{base}"; + BufferPadding = "%opt{base},%opt{base}"; + MenuForeground = "%opt{blue},white+bF"; + MenuBackground = "%opt{sky},white+F"; + Information = "%opt{sky},white"; + # Markdown help color scheme + InfoDefault = "Information"; + InfoBlock = "@block"; + InfoBlockQuote = "+i@block"; + InfoBullet = "@bullet"; + InfoHeader = "@header"; + InfoLink = "@link"; + InfoLinkMono = "+b@mono"; + InfoMono = "@mono"; + InfoRule = "+b@Information"; + InfoDiagnosticError = "@DiagnosticError"; + InfoDiagnosticHint = "@DiagnosticHint"; + InfoDiagnosticInformation = "@Information"; + InfoDiagnosticWarning = "@DiagnosticWarning"; + # Extra faces + macro = "+u@function"; + method = "@function"; + format_specifier = "+i@string"; + mutable_variable = "+i@variable"; + class = "+b@variable"; +}; +in utils.mkFacesScript "default-faces" faces diff --git a/home/kakoune/kakrc b/packages/common/nki-kakoune/kakrc similarity index 69% rename from home/kakoune/kakrc rename to packages/common/nki-kakoune/kakrc index 7502c2a..878869c 100644 --- a/home/kakoune/kakrc +++ b/packages/common/nki-kakoune/kakrc @@ -1,6 +1,3 @@ -# Enable kak-tree-sitter -eval %sh{test -z "$WE_STARTED_KAK" && kak-tree-sitter --kakoune -d --server --init $kak_session} -map global normal ": enter-user-mode tree-sitter" # ## Set some color overrides # set global kts_yellow "rgb:e2b75e" # set global kts_teal "rgb:008080" @@ -8,6 +5,7 @@ map global normal ": enter-user-mode tree-sitter" # set global kts_sky "rgb:6aa622" # Color scheme colorscheme catppuccin-latte +set-face global module "%opt{sapphire}" set global base "default" # Set indentation guides @@ -90,47 +88,6 @@ hook global InsertCompletionHide .* %{ unmap window insert } -# Enable LSP -try %{ - eval %sh{test -z "$WE_STARTED_KAK" && kak-lsp --kakoune -s $kak_session} - set-option global lsp_cmd "kak-lsp -s %val{session}" -} -hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|fsharp|ocaml|haskell|nix|scala|typst|html|css|json|markdown|templ|elixir) %{ - lsp-enable-window - map window lsp N -docstring "Display the next message request" ": lsp-show-message-request-next" - map window normal ": enter-user-mode lsp" - map window normal ": lsp-hover" - map window normal ": lsp-hover-buffer" - # lsp-auto-hover-insert-mode-enable - set window lsp_hover_anchor true - map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' - map global object a 'lsp-object' -docstring 'LSP any symbol' - map global object 'lsp-object' -docstring 'LSP any symbol' - map global object f 'lsp-object Function Method' -docstring 'LSP function or method' - map global object t 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' - map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' - map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' -} - -hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|haskell|nix|fsharp|templ) %{ - # Format the document if possible - hook window BufWritePre .* %{ lsp-formatting-sync } -} - -hook global WinSetOption filetype=(rust|scala|fsharp) %{ - # Enable inlay hints - lsp-inlay-hints-enable window -} - -hook global WinSetOption filetype=(rust|go|fsharp|typst|scala) %{ - hook window -group semantic-tokens BufReload .* lsp-semantic-tokens - hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens - hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens - hook -once -always window WinSetOption filetype=.* %{ - remove-hooks window semantic-tokens - } -} - # in Insert mode moves to end of line. map global insert 'A' @@ -174,7 +131,6 @@ hook global WinSetOption filetype=(typst) %{ hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ } } - define-command -params 0 -docstring "Set up build" scala-build-connect %{ lsp-execute-command 'build-connect' '"[]"' } diff --git a/packages/common/nki-kakoune/kaktex/default.nix b/packages/common/nki-kakoune/kaktex/default.nix new file mode 100644 index 0000000..a8005d5 --- /dev/null +++ b/packages/common/nki-kakoune/kaktex/default.nix @@ -0,0 +1,22 @@ +{ fish, lib, writeScript, writeTextDir, kakouneUtils, ... }: +let + kaktex-script = writeScript "kaktex" '' + #!/usr/bin/env ${lib.getExe fish} + + ${builtins.readFile ./kaktex.fish} + ''; + kaktex = writeTextDir "kaktex.kak" '' + hook global WinSetOption filetype=(tex|latex) %{ + hook window WinDisplay '.*' %{ + eval %sh{ + ${kaktex-script} set $kak_client $kak_session + } + } + } + ''; +in +kakouneUtils.buildKakounePluginFrom2Nix { + pname = "kaktex"; + version = "latest"; + src = kaktex; +} diff --git a/home/kakoune/kaktex b/packages/common/nki-kakoune/kaktex/kaktex.fish similarity index 96% rename from home/kakoune/kaktex rename to packages/common/nki-kakoune/kaktex/kaktex.fish index bdcf722..bb6690b 100755 --- a/home/kakoune/kaktex +++ b/packages/common/nki-kakoune/kaktex/kaktex.fish @@ -1,5 +1,3 @@ -#!/usr/bin/env fish - function usage echo "Usage: " echo " kaktex set [client] [session]" diff --git a/packages/common/nki-kakoune/lsp.nix b/packages/common/nki-kakoune/lsp.nix new file mode 100644 index 0000000..707ce7b --- /dev/null +++ b/packages/common/nki-kakoune/lsp.nix @@ -0,0 +1,309 @@ +{ lib +, writeTextDir +, formats +, kak-lsp +, # LSP packages + ccls +, gopls +, nil +, nixpkgs-fmt +, python311Packages +, ltex-ls +, nodePackages +, tailwindcss-language-server +, fsautocomplete +, metals +, tinymist +, marksman +, rust-analyzer +, ... +}: +let + # Configuration for kak-lsp + config = { + languageIDs = { + c = "c_cpp"; + cpp = "c_cpp"; + javascript = "javascriptreact"; + typescript = "typescriptreact"; + protobuf = "proto"; + sh = "shellscript"; + }; + + languageServers = + let + vscodeServerOf = name: { + name = "vscode-${name}-language-server"; + value = { + args = [ "--stdio" ]; + command = "vscode-${name}-language-server"; + filetypes = [ name "templ" ]; + roots = [ "package.json" ".git" ]; + package = nodePackages.vscode-langservers-extracted; + }; + }; + in + { + ccls = { + args = [ "-v=2" "-log-file=/tmp/ccls.log" ]; + package = ccls; + command = "ccls"; + filetypes = [ "c" "cpp" ]; + roots = [ "compile_commands.json" ".cquery" ".git" ]; + }; + gopls = { + command = "gopls"; + package = gopls; + filetypes = [ "go" ]; + offset_encoding = "utf-8"; + roots = [ "Gopkg.toml" "go.mod" ".git" ".hg" ]; + settings = { gopls = { hoverKind = "SynopsisDocumentation"; semanticTokens = true; }; }; + settings_section = "gopls"; + }; + haskell-language-server = { + args = [ "--lsp" ]; + command = "haskell-language-server-wrapper"; + filetypes = [ "haskell" ]; + roots = [ "Setup.hs" "stack.yaml" "*.cabal" "package.yaml" ]; + settings_section = "haskell"; + }; + nil = { + command = "nil"; + package = nil; + filetypes = [ "nix" ]; + roots = [ "flake.nix" "shell.nix" ".git" ]; + settings.nil = { + formatting.command = [ "${lib.getExe nixpkgs-fmt}" ]; + }; + }; + pylsp = { + command = "pylsp"; + package = python311Packages.python-lsp-server; + filetypes = [ "python" ]; + offset_encoding = "utf-8"; + roots = [ "requirements.txt" "setup.py" ".git" ".hg" ]; + }; + # Spellchecking server + ltex-ls = { + command = "ltex-ls"; + args = [ "--log-file=/tmp" ]; + filetypes = [ "latex" "typst" ]; + roots = [ "main.tex" "main.typ" ".git" ]; + package = ltex-ls; + }; + tailwind = { + command = "tailwindcss-language-server"; + args = [ "--stdio" ]; + filetypes = [ "html" "css" "javascript" "typescript" "templ" ]; + roots = [ "tailwind.config.{js,cjs,mjs,ts}" "package.json" ".git" ]; + settings_section = "tailwindCSS"; + settings.tailwindCSS = { + validate = "warning"; + userLanguages.templ = "html"; + }; + package = tailwindcss-language-server; + }; + elixir-ls = { + args = [ ]; + command = "elixir-ls"; + filetypes = [ "elixir" ]; + roots = [ "mix.exs" ]; + }; + typescript-language-server = { + args = [ "--stdio" ]; + command = "typescript-language-server"; + filetypes = [ "typescript" "javascript" ]; + roots = [ "package.json" ]; + package = nodePackages.typescript-language-server; + }; + fsautocomplete = { + args = [ "--adaptive-lsp-server-enabled" "--project-graph-enabled" "--source-text-factory" "RoslynSourceText" ]; + command = "fsautocomplete"; + filetypes = [ "fsharp" ]; + roots = [ "*.fsproj" ]; + settings_section = "FSharp"; + settings.FSharp = { + AutomaticWorkspaceInit = true; + }; + package = fsautocomplete; + }; + metals = { + command = "metals"; + filetypes = [ "scala" ]; + roots = [ "build.sbt" "build.sc" "build.mill" ]; + settings_section = "metals"; + settings.metals = { + enableSemanticHighlighting = true; + showInferredType = true; + decorationProvider = true; + inlineDecorationProvider = true; + # From kakoune-lsp's own options + icons = "unicode"; + isHttpEnabled = true; + statusBarProvider = "log-message"; + compilerOptions = { overrideDefFormat = "unicode"; }; + }; + package = metals; + }; + texlab = { + command = "texlab"; + filetypes = [ "latex" ]; + roots = [ "main.tex" "all.tex" ".git" ]; + settings_section = "texlab"; + settings.texlab = { + build.executable = "latexmk"; + build.args = [ "-pdf" "-shell-escape" "-interaction=nonstopmode" "-synctex=1" "%f" ]; + + build.forwardSearchAfter = true; + build.onSave = true; + + # forwardSearch = + # (if pkgs.stdenv.isDarwin then { + # executable = "/Applications/Skim.app/Contents/SharedSupport/displayline"; + # args = [ "-r" "-g" "%l" "%p" "%f" ]; + # } else + # { + # executable = "${pkgs.zathura}/bin/zathura"; + # args = [ "--synctex-forward" "%l:1:%f" "%p" "-x" "${./kaktex} jump %%{input} %%{line} %%{column}" ]; + # }); + }; + package = texlab; + }; + tinymist = { + command = "tinymist"; + filetypes = [ "typst" ]; + roots = [ "main.typ" ".git" ]; + settings_section = "tinymist"; + settings.tinymist = { + exportPdf = "onSave"; + formatterMode = "typstfmt"; + }; + package = tinymist; + }; + marksman = { + command = "marksman"; + filetypes = [ "markdown" ]; + roots = [ ".marksman.toml" ".git" ]; + package = marksman; + }; + rust-analyzer = { + args = [ ]; + command = "rust-analyzer"; + filetypes = [ "rust" ]; + roots = [ "Cargo.toml" ]; + package = rust-analyzer; + }; + + } // (builtins.listToAttrs (builtins.map vscodeServerOf [ "html" "css" "json" ])); + + faces = [ + ## Items + # (Rust) Macros + { face = "attribute"; token = "attribute"; } + { face = "attribute"; token = "derive"; } + { face = "macro"; token = "macro"; } # Function-like Macro + # Keyword and Fixed Tokens + { face = "keyword"; token = "keyword"; } + { face = "operator"; token = "operator"; } + # Functions and Methods + { face = "function"; token = "function"; } + { face = "method"; token = "method"; } + # Constants + { face = "string"; token = "string"; } + { face = "format_specifier"; token = "formatSpecifier"; } + # Variables + { face = "variable"; token = "variable"; modifiers = [ "readonly" ]; } + { face = "mutable_variable"; token = "variable"; } + { face = "module"; token = "namespace"; } + { face = "variable"; token = "type_parameter"; } + { face = "class"; token = "enum"; } + { face = "class"; token = "struct"; } + { face = "class"; token = "trait"; } + { face = "class"; token = "union"; } + { face = "class"; token = "class"; } + + ## Comments + { face = "documentation"; token = "comment"; modifiers = [ "documentation" ]; } + { face = "comment"; token = "comment"; } + + # Typst + { face = "header"; token = "heading"; } + { face = "ts_markup_link_url"; token = "link"; } + { face = "ts_markup_link_uri"; token = "ref"; } + { face = "ts_markup_link_label"; token = "label"; } + { face = "ts_property"; token = "pol"; } + { face = "ts_markup_list_checked"; token = "marker"; } + { face = "ts_constant_builtin_boolean"; token = "bool"; } + { face = "ts_keyword_control"; token = "delim"; } + { face = "ts_number"; token = "text"; modifiers = [ "math" ]; } + { face = "ts_markup_bold"; token = "text"; modifiers = [ "strong" ]; } + { face = "ts_markup_italic"; token = "text"; modifiers = [ "emph" ]; } + ]; + + raw = { + server = { timeout = 1800; }; + snippet_support = false; + verbosity = 255; + }; + }; + + kak-lsp-config = + let + toml = formats.toml { }; + toLspConfig = builtins.mapAttrs (_: attrs: builtins.removeAttrs attrs [ "package" ]); + in + toml.generate "kak-lsp.toml" ({ + semantic_tokens.faces = config.faces; + language_server = toLspConfig config.languageServers; + language_ids = config.languageIDs; + } // config.raw); + + serverPackages = + builtins.filter (v: v != null) + (lib.mapAttrsToList (_: serv: serv.package or null) config.languageServers); +in +{ + extraPaths = lib.makeBinPath serverPackages; + plugin = writeTextDir "share/kak/autoload/kak-lsp.kak" '' + hook global KakBegin .* %{ + try %{ + eval %sh{${lib.getExe kak-lsp} --kakoune --config ${kak-lsp-config} -s $kak_session} + } + + lsp-enable + map global lsp N -docstring "Display the next message request" ": lsp-show-message-request-next" + map global normal ": enter-user-mode lsp" + map global normal ": lsp-hover" + map global normal ": lsp-hover-buffer" + # lsp-auto-hover-insert-mode-enable + set global lsp_hover_anchor true + map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' + map global object a 'lsp-object' -docstring 'LSP any symbol' + map global object 'lsp-object' -docstring 'LSP any symbol' + map global object f 'lsp-object Function Method' -docstring 'LSP function or method' + map global object t 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' + map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' + map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' + + hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|haskell|nix|fsharp|templ) %{ + # Format the document if possible + hook window BufWritePre .* %{ lsp-formatting-sync } + } + + hook global WinSetOption filetype=(rust|scala|fsharp) %{ + # Enable inlay hints + lsp-inlay-hints-enable window + } + + hook global WinSetOption filetype=(rust|go|fsharp|typst|scala) %{ + hook window -group semantic-tokens BufReload .* lsp-semantic-tokens + hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens + hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window semantic-tokens + } + } + } + ''; +} + diff --git a/packages/common/nki-kakoune/plugins.nix b/packages/common/nki-kakoune/plugins.nix new file mode 100644 index 0000000..b524a14 --- /dev/null +++ b/packages/common/nki-kakoune/plugins.nix @@ -0,0 +1,205 @@ +{ pkgs, symlinkJoin, writeTextDir, kakouneUtils, ... }: +with { + inherit (kakouneUtils) buildKakounePluginFrom2Nix; +}; +let + toDir = name: file: writeTextDir name (builtins.readFile file); + + writeActivationScript = script: writeTextDir "on-load.kak" '' + hook global KakBegin .* %{ + ${script} + } + ''; + + writeModuleWrapper = name: script: writeTextDir "module.kak" '' + provide-module ${name} %◍ + ${script} + ◍ + ''; + + kakounePlugin = { name, src, wrapAsModule ? false, activationScript ? null, ... }@attrs: + let + module = if wrapAsModule then writeModuleWrapper name (builtins.readFile src) else src; + in + buildKakounePluginFrom2Nix { + pname = name; + version = attrs.version or "latest"; + src = if activationScript == null then module else + symlinkJoin { + name = "${name}-src"; + paths = [ + module + (writeActivationScript activationScript) + ]; + }; + }; +in +builtins.map kakounePlugin [ + # My own scripts + { + name = "latex.kak"; + src = toDir "latex.kak" ./autoload/latex.kak; + } + { + name = "markdown.kak"; + src = toDir "markdown.kak" ./autoload/markdown.kak; + } + + # Plugins + { + name = "luar"; + src = pkgs.fetchFromGitHub { + owner = "gustavo-hms"; + repo = "luar"; + rev = "2f430316f8fc4d35db6c93165e2e77dc9f3d0450"; + sha256 = "sha256-vHn/V3sfzaxaxF8OpA5jPEuPstOVwOiQrogdSGtT6X4="; + }; + activationScript = '' + # Enable luar + require-module luar + # Use luajit + set-option global luar_interpreter ${pkgs.luajit}/bin/luajit + ''; + } + { + name = "peneira"; + src = pkgs.fetchFromGitHub { + owner = "natsukagami"; + repo = "peneira"; + rev = "743b9971472853a752475e7c070ce99089c6840c"; + sha256 = "sha256-E4ndbF9YC1p0KrvSuGgwmG1Y2IGTuGKJo/AuMixhzlM="; + }; + activationScript = '' + require-module peneira + + # Change selection color + set-face global PeneiraSelected @PrimarySelection + + # Buffers list + define-command -hidden peneira-buffers %{ + peneira 'buffers: ' %{ printf '%s\n' $kak_quoted_buflist } %{ + buffer %arg{1} + } + } + + # Grep in the current location + define-command peneira-grep %{ + peneira 'line: ' "rg -n ." %{ + lua %arg{1} %{ + local file, line = arg[1]:match("([^:]+):(%d+):") + kak.edit(file, line) + } + } + } + + # A peneira menu + declare-user-mode fuzzy-match-menu + + map -docstring "Switch to buffer" global fuzzy-match-menu b ": peneira-buffers" + map -docstring "Symbols" global fuzzy-match-menu s ": peneira-symbols" + map -docstring "Lines" global fuzzy-match-menu l ": peneira-lines" + map -docstring "Lines in the current directory" global fuzzy-match-menu g ": peneira-grep" + map -docstring "Files in project" global fuzzy-match-menu f ": peneira-files" + map -docstring "Files in currently opening file's directory" global fuzzy-match-menu F ": peneira-local-files" + + # Bind menu to user mode + map -docstring "Fuzzy matching" global user f ": enter-user-mode fuzzy-match-menu" + ''; + } + { + name = "kakoune-focus"; + src = pkgs.fetchFromGitHub { + owner = "caksoylar"; + repo = "kakoune-focus"; + rev = "949c0557cd4c476822acfa026ca3c50f3d38a3c0"; + sha256 = "sha256-ZV7jlLJQyL420YG++iC9rq1SMjo3WO5hR9KVvJNUiCs="; + }; + activationScript = '' + map global user ': focus-toggle' -docstring "toggle selections focus" + ''; + } + { + name = "kakoune-inc-dec"; + src = pkgs.fetchFromGitLab { + owner = "Screwtapello"; + repo = "kakoune-inc-dec"; + rev = "7bfe9c51"; + sha256 = "0f33wqxqbfygxypf348jf1fiscac161wf2xvnh8zwdd3rq5yybl0"; + }; + } + { + name = "racket.kak"; + src = (builtins.fetchTree { + type = "git"; + url = "https://bitbucket.org/KJ_Duncan/kakoune-racket.kak.git"; + rev = "e397042009b46916ff089d79166ec0e8ca813a18"; + narHash = "sha256-IcxFmvG0jqpMCG/dT9crVRgPgMGKkic6xwrnW5z4+bc="; + }) + "/rc"; + } + # { + # name = "kakoune-discord"; + # src = (builtins.getFlake "github:natsukagami/kakoune-discord/03f95e40d6efd8fd3de7bca31653d43de2dcfc5f").packages.${pkgs.system}.kakoune-discord-rc + "/rc"; + # } + rec { + name = "kakoune-mirror"; + src = pkgs.fetchFromGitHub + { + owner = "Delapouite"; + repo = "kakoune-mirror"; + rev = "5710635f440bcca914d55ff2ec1bfcba9efe0f15"; + sha256 = "sha256-uslx4zZhvjUylrPWvTOugsKYKKpF0EEz1drc1Ckrpjk="; + } + "/mirror.kak"; + wrapAsModule = true; + activationScript = '' + require-module ${name} + + # Bind to ${name} + map global normal ': enter-user-mode -lock mirror' + ''; + } + { + name = "unicode-math"; + src = pkgs.fetchFromGitHub { + owner = "natsukagami"; + repo = "kakoune-unicode-math"; + rev = "08dff25da2b86ee0b0777091992bc7fb28c3cb1d"; + # sha256 = lib.fakeSha256; + sha256 = "sha256-j0L1ARex1i2ma8sGLYwgkfAbh0jWKh/6QGHFaxPXIKc="; + fetchSubmodules = true; + }; + activationScript = '' + require-module unicode-math + + # Bind to the menu + map global insert ': insert-unicode ' + ''; + } + { + name = "kakoune-buffers"; + src = pkgs.fetchFromGitHub { + owner = "Delapouite"; + repo = "kakoune-buffers"; + rev = "6b2081f5b7d58c72de319a5cba7bf628b6802881"; + sha256 = "sha256-jOSrzGcLJjLK1GiTSsl2jLmQMPbPxjycR0pwF5t/eV0="; + }; + activationScript = '' + # Suggested hook + + hook global WinDisplay .* info-buffers + + # Suggested mappings + + map global user b ':enter-buffers-mode' -docstring 'buffers…' + map global normal ^ ':enter-buffers-mode' -docstring 'buffers…' + map global user B ':enter-user-mode -lock buffers' -docstring 'buffers (lock)…' + + # Suggested aliases + + alias global bd delete-buffer + alias global bf buffer-first + alias global bl buffer-last + alias global bo buffer-only + alias global bo! buffer-only-force + ''; + } +] diff --git a/packages/common/nki-kakoune/rc.nix b/packages/common/nki-kakoune/rc.nix new file mode 100644 index 0000000..ac579c9 --- /dev/null +++ b/packages/common/nki-kakoune/rc.nix @@ -0,0 +1,27 @@ +{ lib +, fish +, writeScript +, writeTextDir +, prependRc ? "" +, appendRc ? "" +, ... +}: + +let + source-pwd = writeScript "source-pwd" '' + #!/usr/bin/env ${lib.getExe fish} + + ${builtins.readFile ./source-pwd.fish} + ''; +in +writeTextDir "share/kak/kakrc.local" '' + ${prependRc} + ${builtins.readFile ./kakrc} + ${appendRc} + + # Source any settings in the current working directory, + # recursive upwards + evaluate-commands %sh{ + ${source-pwd} + } +'' diff --git a/home/kakoune/source-pwd b/packages/common/nki-kakoune/source-pwd.fish similarity index 91% rename from home/kakoune/source-pwd rename to packages/common/nki-kakoune/source-pwd.fish index 35e5b0f..aa9aa37 100755 --- a/home/kakoune/source-pwd +++ b/packages/common/nki-kakoune/source-pwd.fish @@ -1,5 +1,3 @@ -#!/usr/bin/env fish - if test (pwd) = "/home/natsukagami/.config/kak" exit 0 end diff --git a/packages/common/nki-kakoune/themes.nix b/packages/common/nki-kakoune/themes.nix new file mode 100644 index 0000000..5c24299 --- /dev/null +++ b/packages/common/nki-kakoune/themes.nix @@ -0,0 +1,9 @@ +{ writeTextDir, ... }: +let + themes = [ + { name = "catppuccin-latte"; src = ./themes/catppuccin-latte.kak; } + ]; + + themeToColorscheme = { name, src }: writeTextDir "share/kak/colors/${name}.kak" (builtins.readFile src); +in +builtins.map themeToColorscheme themes diff --git a/home/kakoune/catppuccin-latte.kak b/packages/common/nki-kakoune/themes/catppuccin-latte.kak similarity index 100% rename from home/kakoune/catppuccin-latte.kak rename to packages/common/nki-kakoune/themes/catppuccin-latte.kak diff --git a/packages/common/nki-kakoune/utils.nix b/packages/common/nki-kakoune/utils.nix new file mode 100644 index 0000000..0307bc6 --- /dev/null +++ b/packages/common/nki-kakoune/utils.nix @@ -0,0 +1,7 @@ +{ lib, writeTextDir, ... }: { + mkFacesScript = name: faces: writeTextDir "share/kak/autoload/${name}/faces.kak" '' + hook global KakBegin .* %{ + ${lib.concatStringsSep "\n" (builtins.attrValues (builtins.mapAttrs (name: face: " face global ${name} \"${face}\"") faces))} + } + ''; +}