From 8bf1de0fdc8c3b0b8defc76d06ea969eb69f4eed Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 19 Jul 2025 22:06:05 +0300 Subject: [PATCH] editors: init --- modules/common/default-packages.nix | 3 + modules/common/editor/default.nix | 177 +++++++++++++++++++ modules/common/editor/helix.nix | 97 +++++++++++ modules/common/editor/nano.nix | 7 + modules/common/helix.nix | 256 ---------------------------- modules/linux/nano.nix | 7 - 6 files changed, 284 insertions(+), 263 deletions(-) create mode 100644 modules/common/default-packages.nix create mode 100644 modules/common/editor/default.nix create mode 100644 modules/common/editor/helix.nix create mode 100644 modules/common/editor/nano.nix delete mode 100644 modules/common/helix.nix delete mode 100644 modules/linux/nano.nix diff --git a/modules/common/default-packages.nix b/modules/common/default-packages.nix new file mode 100644 index 0000000..e03f027 --- /dev/null +++ b/modules/common/default-packages.nix @@ -0,0 +1,3 @@ +{ + environment.defaultPackages = []; +} diff --git a/modules/common/editor/default.nix b/modules/common/editor/default.nix new file mode 100644 index 0000000..8e549c1 --- /dev/null +++ b/modules/common/editor/default.nix @@ -0,0 +1,177 @@ +{ config, lib, pkgs, ... }: let + inherit (lib) attrValues enabled mkIf mkValue mapAttrs optionalAttrs elem; +in { + options.editor.defaultAlias = mkValue "nano"; + + options.editor.languageConfigsHelix = mkValue (let + formattedLanguages = { + astro = "astro"; + css = "css"; + html = "html"; + javascript = "js"; + json = "json"; + jsonc = "jsonc"; + jsx = "jsx"; + markdown = "md"; + scss = "scss"; + svelte = "svelte"; + tsx = "tsx"; + typescript = "ts"; + vue = "vue"; + yaml = "yaml"; + } + |> mapAttrs (name: extension: { + inherit name; + + auto-format = true; + formatter.command = "deno"; + formatter.args = [ "fmt" "--unstable-component" "--ext" extension "-" ]; + } // optionalAttrs (elem name [ "javascript" "jsx" "typescript" "tsx" ]) { + language-servers = [ "deno" ]; + }) + |> attrValues; + in formattedLanguages ++ [ + { + name = "nix"; + auto-format = false; + formatter.command = "nixfmt"; + } + + { + name = "python"; + auto-format = true; + language-servers = [ "basedpyright" ]; + } + + { + name = "toml"; + auto-format = true; + } + + { + name = "rust"; + + debugger.name = "lldb-dap"; + debugger.transport = "stdio"; + debugger.command = "lldb-dap"; + + debugger.templates = [{ + name = "binary"; + request = "launch"; + + completion = [{ + name = "binary"; + completion = "filename"; + }]; + + args.program = "{0}"; + args.initCommands = let + primer = pkgs.runCommand "primer" {} (/* py */ '' + mkdir $out + echo ' + + import subprocess + import pathlib + import lldb + + # Not hardcoding a nix store path here on purpose. + rustlib_etc = pathlib.Path(subprocess.getoutput("rustc --print sysroot")) / "lib" / "rustlib" / "etc" + if not rustlib_etc.exists(): + raise RuntimeError("Unable to determine rustc sysroot") + + # Load lldb_lookup.py and execute lldb_commands with the correct path + lldb.debugger.HandleCommand(f"""command script import "{rustlib_etc / 'lldb_lookup.py'}" """) + lldb.debugger.HandleCommand(f"""command source -s 0 "{rustlib_etc / 'lldb_commands'}" """) + + ' > $out/primer.py + ''); + in [ "command script import ${primer}/primer.py" ]; + }]; + } + ]); + + options.editor.lspConfigsHelix = mkValue { + deno = { + command = "deno"; + args = [ "lsp" ]; + + environment.NO_COLOR = "1"; + + config.javascript = enabled { + lint = true; + unstable = true; + + suggest.imports.hosts."https://deno.land" = true; + + inlayHints.enumMemberValues.enabled = true; + inlayHints.functionLikeReturnTypes.enabled = true; + inlayHints.parameterNames.enabled = "all"; + inlayHints.parameterTypes.enabled = true; + inlayHints.propertyDeclarationTypes.enabled = true; + inlayHints.variableTypes.enabled = true; + }; + }; + + rust-analyzer = { + config = { + cargo.features = "all"; + check.command = "clippy"; + completion.callable.snippets = "add_parentheses"; + completion.excludeTraits = [ "yansi::Paint" ]; + diagnostics.disabled = [ "inactive-code" "unlinked-file" ]; + }; + }; + }; + + config.environment = { + shellAliases.x = "echo 'use `e`, retard'"; + + shellAliases.e = config.editor.defaultAlias; + variables.EDITOR = config.editor.defaultAlias; + + systemPackages = mkIf config.isDesktop <| attrValues { + inherit (pkgs) + # CMAKE + cmake-language-server + + # GO + gopls + + # HTML + vscode-langservers-extracted + + # KOTLIN + kotlin-language-server + + # LATEX + texlab + + # LUA + lua-language-server + + # MARKDOWN + markdown-oxide + + # NIX + nixfmt-rfc-style + nil + + # PYTHON + basedpyright + + # RUST + rust-analyzer-nightly + lldb + + # TYPESCRIPT & OTHERS + deno + + # YAML + yaml-language-server + + # ZIG + zls + ; + }; + }; +} diff --git a/modules/common/editor/helix.nix b/modules/common/editor/helix.nix new file mode 100644 index 0000000..8044eed --- /dev/null +++ b/modules/common/editor/helix.nix @@ -0,0 +1,97 @@ +{ config, lib, pkgs, ... }: let + inherit (lib) const enabled genAttrs mkAfter mkIf; + + # CullOS Helix with Cab support: + _package_cab = pkgs.helix.overrideAttrs (old: { + src = pkgs.fetchzip { + url = "https://github.com/cull-os/helix/releases/download/ci-release-25.01.1/helix-ci-release-25.01.1-source.tar.xz"; + hash = "sha256-bvlzXRAdPvz8P49KENSw9gupQNaUm/+3eZZ1q7+fTsw="; + stripRoot = false; + }; + + cargoDeps = pkgs.rustPlatform.fetchCargoVendor { + inherit (pkgs.helix) src; + hash = "sha256-soOnSRvWO7OzxYENFUBGmgSAk1Oy9Av+wDDLKkcuIbs="; + }; + }); + + package = pkgs.helix.overrideAttrs (finalAttrs: _previousAttrs: { + version = "25.07.2"; + src = pkgs.fetchzip { + url = "https://github.com/bloxx12/helix/releases/download/${finalAttrs.version}/helix-${finalAttrs.version}-source.tar.xz"; + hash = "sha256-ZNsQwFfPXe6oewajx1tl68W60kVo7q2SuvTgy/o1HKk="; + stripRoot = false; + }; + + doInstallCheck = false; + + cargoDeps = pkgs.rustPlatform.fetchCargoVendor { + inherit (pkgs.helix) src; + hash = "sha256-3poZSvIrkx8lguxxDeNfngW6+4hH8TV/LHcZx5W5aXg="; + }; + }); +in { + editor.defaultAlias = "hx"; + + home-manager.sharedModules = [{ + programs.nushell.configFile.text = mkIf /*(*/config.isDesktop/* && config.isLinux)*/ <| mkAfter /* nu */ '' + def --wrapped hx [...arguments] { + if $env.TERM == "xterm-kitty" { + kitty @ set-spacing padding=0 + } + + RUST_BACKTRACE=full ^hx ...($arguments | each { glob $in } | flatten) + + if $env.TERM == "xterm-kitty" { + kitty @ set-spacing padding=${toString config.theme.padding} + } + } + ''; + + programs.helix = enabled { + inherit package; + + languages.language = config.editor.languageConfigsHelix; + languages.language-server = config.editor.lspConfigsHelix; + + settings.theme = "gruvbox_dark_hard"; + + settings.editor = { + auto-completion = false; + bufferline = "multiple"; + color-modes = true; + cursorline = true; + file-picker.hidden = false; + idle-timeout = 0; + shell = [ "nu" "--commands" ]; + text-width = 100; + }; + + settings.editor.cursor-shape = { + insert = "bar"; + normal = "block"; + select = "underline"; + }; + + settings.editor.statusline.mode = { + insert = "INSERT"; + normal = "NORMAL"; + select = "SELECT"; + }; + + settings.editor.indent-guides = { + character = "▏"; + render = true; + }; + + settings.editor.whitespace = { + characters.tab = "→"; + render.tab = "all"; + }; + + settings.keys = genAttrs [ "normal" "select" ] <| const { + D = "extend_to_line_end"; + }; + }; + }]; +} diff --git a/modules/common/editor/nano.nix b/modules/common/editor/nano.nix new file mode 100644 index 0000000..8de3ffe --- /dev/null +++ b/modules/common/editor/nano.nix @@ -0,0 +1,7 @@ +{ config, lib, ... }: let + inherit (lib) disabled optionalAttrs; +in { + programs = optionalAttrs config.isLinux { + nano = disabled; # Garbage. + }; +} diff --git a/modules/common/helix.nix b/modules/common/helix.nix deleted file mode 100644 index d896322..0000000 --- a/modules/common/helix.nix +++ /dev/null @@ -1,256 +0,0 @@ -{ config, lib, pkgs, ... }: let - inherit (lib) attrValues const elem enabled genAttrs mapAttrs mkAfter mkIf optionalAttrs; -in { - environment = { - variables.EDITOR = "hx"; - shellAliases.x = "hx"; - }; - - nixpkgs.overlays = [(self: super: { - # CullOS Helix with Cab support: - # helix = super.helix.overrideAttrs (old: { - # src = self.fetchzip { - # url = "https://github.com/cull-os/helix/releases/download/ci-release-25.01.1/helix-ci-release-25.01.1-source.tar.xz"; - # hash = "sha256-bvlzXRAdPvz8P49KENSw9gupQNaUm/+3eZZ1q7+fTsw="; - # stripRoot = false; - # }; - - # cargoDeps = self.rustPlatform.fetchCargoVendor { - # inherit (self.helix) src; - # hash = "sha256-soOnSRvWO7OzxYENFUBGmgSAk1Oy9Av+wDDLKkcuIbs="; - # }; - # }); - - helix = super.helix.overrideAttrs (finalAttrs: _previousAttrs: { - version = "25.07.2"; - src = self.fetchzip { - url = "https://github.com/bloxx12/helix/releases/download/${finalAttrs.version}/helix-${finalAttrs.version}-source.tar.xz"; - hash = "sha256-ZNsQwFfPXe6oewajx1tl68W60kVo7q2SuvTgy/o1HKk="; - stripRoot = false; - }; - - doInstallCheck = false; - - cargoDeps = self.rustPlatform.fetchCargoVendor { - inherit (self.helix) src; - hash = "sha256-3poZSvIrkx8lguxxDeNfngW6+4hH8TV/LHcZx5W5aXg="; - }; - }); - })]; - - home-manager.sharedModules = [{ - programs.nushell.configFile.text = mkIf /*(*/config.isDesktop/* && config.isLinux)*/ <| mkAfter /* nu */ '' - def --wrapped hx [...arguments] { - if $env.TERM == "xterm-kitty" { - kitty @ set-spacing padding=0 - } - - RUST_BACKTRACE=full ^hx ...($arguments | each { glob $in } | flatten) - - if $env.TERM == "xterm-kitty" { - kitty @ set-spacing padding=${toString config.theme.padding} - } - } - ''; - - programs.helix = enabled { - languages.language = let - formattedLanguages = { - astro = "astro"; - css = "css"; - html = "html"; - javascript = "js"; - json = "json"; - jsonc = "jsonc"; - jsx = "jsx"; - markdown = "md"; - scss = "scss"; - svelte = "svelte"; - tsx = "tsx"; - typescript = "ts"; - vue = "vue"; - yaml = "yaml"; - } |> mapAttrs (name: extension: { - inherit name; - - auto-format = true; - formatter.command = "deno"; - formatter.args = [ "fmt" "--unstable-component" "--ext" extension "-" ]; - } // optionalAttrs (elem name [ "javascript" "jsx" "typescript" "tsx" ]) { - language-servers = [ "deno" ]; - }) - |> attrValues; - in formattedLanguages ++ [ - { - name = "nix"; - auto-format = false; - formatter.command = "nixfmt"; - } - - { - name = "python"; - auto-format = true; - language-servers = [ "basedpyright" ]; - } - - { - name = "rust"; - - debugger.name = "lldb-dap"; - debugger.transport = "stdio"; - debugger.command = "lldb-dap"; - - debugger.templates = [{ - name = "binary"; - request = "launch"; - - completion = [{ - name = "binary"; - completion = "filename"; - }]; - - args.program = "{0}"; - args.initCommands = let - primer = pkgs.runCommand "primer" {} (/* py */ '' - mkdir $out - echo ' - - import subprocess - import pathlib - import lldb - - # Not hardcoding a nix store path here on purpose. - rustlib_etc = pathlib.Path(subprocess.getoutput("rustc --print sysroot")) / "lib" / "rustlib" / "etc" - if not rustlib_etc.exists(): - raise RuntimeError("Unable to determine rustc sysroot") - - # Load lldb_lookup.py and execute lldb_commands with the correct path - lldb.debugger.HandleCommand(f"""command script import "{rustlib_etc / 'lldb_lookup.py'}" """) - lldb.debugger.HandleCommand(f"""command source -s 0 "{rustlib_etc / 'lldb_commands'}" """) - - ' > $out/primer.py - ''); - in [ "command script import ${primer}/primer.py" ]; - }]; - } - ]; - - languages.language-server.deno = { - command = "deno"; - args = [ "lsp" ]; - - environment.NO_COLOR = "1"; - - config.javascript = enabled { - lint = true; - unstable = true; - - suggest.imports.hosts."https://deno.land" = true; - - inlayHints = { - enumMemberValues.enabled = true; - functionLikeReturnTypes.enabled = true; - parameterNames.enabled = "all"; - parameterTypes.enabled = true; - propertyDeclarationTypes.enabled = true; - variableTypes.enabled = true; - }; - }; - }; - - languages.language-server.rust-analyzer = { - config = { - cargo.features = "all"; - check.command = "clippy"; - completion.callable.snippets = "add_parentheses"; - completion.excludeTraits = [ "yansi::Paint" ]; - diagnostics.disabled = [ "inactive-code" "unlinked-file" ]; - }; - }; - - settings.theme = "gruvbox_dark_hard"; - - settings.editor = { - auto-completion = false; - bufferline = "multiple"; - color-modes = true; - cursorline = true; - file-picker.hidden = false; - idle-timeout = 0; - shell = [ "nu" "--commands" ]; - text-width = 100; - }; - - settings.editor.cursor-shape = { - insert = "bar"; - normal = "block"; - select = "underline"; - }; - - settings.editor.statusline.mode = { - insert = "INSERT"; - normal = "NORMAL"; - select = "SELECT"; - }; - - settings.editor.indent-guides = { - character = "▏"; - render = true; - }; - - settings.editor.whitespace = { - characters.tab = "→"; - render.tab = "all"; - }; - - settings.keys = genAttrs [ "normal" "select" ] <| const { - D = "extend_to_line_end"; - }; - }; - }]; - - environment.systemPackages = mkIf config.isDesktop <| attrValues { - inherit (pkgs) - # CMAKE - cmake-language-server - - # GO - gopls - - # HTML - vscode-langservers-extracted - - # KOTLIN - kotlin-language-server - - # LATEX - texlab - - # LUA - lua-language-server - - # MARKDOWN - markdown-oxide - - # NIX - nixfmt-rfc-style - nil - - # PYTHON - basedpyright - - # RUST - rust-analyzer-nightly - lldb - - # TYPESCRIPT & OTHERS - deno - - # YAML - yaml-language-server - - # ZIG - zls - ; - }; -} diff --git a/modules/linux/nano.nix b/modules/linux/nano.nix deleted file mode 100644 index 4f3d1d5..0000000 --- a/modules/linux/nano.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ lib, ... }: let - inherit (lib) disabled; -in { - environment.defaultPackages = []; - - programs.nano = disabled; # Garbage. -}