fork/home-manager
git clone https://git.julia.blue/fork/home-manager
9d0f799c
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . helix ; 7tomlFormat = pkgs . formats . toml { }; 8in { 9meta . maintainers = [ hm . maintainers . Philipp-M ]; 10 11options . programs . helix = { 12enable = mkEnableOption "helix text editor" ; 13 14package = mkOption { 15type = types . package ; 16default = pkgs . helix ; 17defaultText = literalExpression "pkgs.helix" ; 18description = "The package to use for helix." ; 19}; 20 21extraPackages = mkOption { 22type = with types ; listOf package ; 23default = [ ]; 24example = literalExpression "[ pkgs.marksman ]" ; 25description = "Extra packages available to hx." ; 26}; 27 28defaultEditor = mkOption { 29type = types . bool ; 30default = false ; 31description = '' 32Whether to configure {command}`hx` as the default 33editor using the {env}`EDITOR` environment variable. 34'' ; 35}; 36 37settings = mkOption { 38type = tomlFormat . type ; 39default = { }; 40example = literalExpression '' 41{ 42theme = "base16"; 43editor = { 44line-number = "relative"; 45lsp.display-messages = true; 46}; 47keys.normal = { 48space.space = "file_picker"; 49space.w = ":w"; 50space.q = ":q"; 51esc = [ "collapse_selection" "keep_primary_selection" ]; 52}; 53} 54'' ; 55description = '' 56Configuration written to 57{file}`$XDG_CONFIG_HOME/helix/config.toml`. 58 59See <https://docs.helix-editor.com/configuration.html> 60for the full list of options. 61'' ; 62}; 63 64languages = mkOption { 65type = with types ; 66coercedTo ( listOf tomlFormat . type ) ( language : 67lib . warn '' 68The syntax of programs.helix.languages has changed. 69It now generates the whole languages.toml file instead of just the language array in that file. 70 71Use 72programs.helix.languages = { language = <languages list>; } 73instead. 74'' { inherit language ; }) ( addCheck tomlFormat . type builtins . isAttrs ); 75default = { }; 76example = literalExpression '' 77{ 78# the language-server option currently requires helix from the master branch at https://github.com/helix-editor/helix/ 79language-server.typescript-language-server = with pkgs.nodePackages; { 80command = "''${typescript-language-server}/bin/typescript-language-server"; 81args = [ "--stdio" "--tsserver-path=''${typescript}/lib/node_modules/typescript/lib" ]; 82}; 83 84language = [{ 85name = "rust"; 86auto-format = false; 87}]; 88} 89'' ; 90description = '' 91Language specific configuration at 92{file}`$XDG_CONFIG_HOME/helix/languages.toml`. 93 94See <https://docs.helix-editor.com/languages.html> 95for more information. 96'' ; 97}; 98 99themes = mkOption { 100type = types . attrsOf tomlFormat . type ; 101default = { }; 102example = literalExpression '' 103{ 104base16 = let 105transparent = "none"; 106gray = "#665c54"; 107dark-gray = "#3c3836"; 108white = "#fbf1c7"; 109black = "#282828"; 110red = "#fb4934"; 111green = "#b8bb26"; 112yellow = "#fabd2f"; 113orange = "#fe8019"; 114blue = "#83a598"; 115magenta = "#d3869b"; 116cyan = "#8ec07c"; 117in { 118"ui.menu" = transparent; 119"ui.menu.selected" = { modifiers = [ "reversed" ]; }; 120"ui.linenr" = { fg = gray; bg = dark-gray; }; 121"ui.popup" = { modifiers = [ "reversed" ]; }; 122"ui.linenr.selected" = { fg = white; bg = black; modifiers = [ "bold" ]; }; 123"ui.selection" = { fg = black; bg = blue; }; 124"ui.selection.primary" = { modifiers = [ "reversed" ]; }; 125"comment" = { fg = gray; }; 126"ui.statusline" = { fg = white; bg = dark-gray; }; 127"ui.statusline.inactive" = { fg = dark-gray; bg = white; }; 128"ui.help" = { fg = dark-gray; bg = white; }; 129"ui.cursor" = { modifiers = [ "reversed" ]; }; 130"variable" = red; 131"variable.builtin" = orange; 132"constant.numeric" = orange; 133"constant" = orange; 134"attributes" = yellow; 135"type" = yellow; 136"ui.cursor.match" = { fg = yellow; modifiers = [ "underlined" ]; }; 137"string" = green; 138"variable.other.member" = red; 139"constant.character.escape" = cyan; 140"function" = blue; 141"constructor" = blue; 142"special" = blue; 143"keyword" = magenta; 144"label" = magenta; 145"namespace" = blue; 146"diff.plus" = green; 147"diff.delta" = yellow; 148"diff.minus" = red; 149"diagnostic" = { modifiers = [ "underlined" ]; }; 150"ui.gutter" = { bg = black; }; 151"info" = blue; 152"hint" = dark-gray; 153"debug" = dark-gray; 154"warning" = yellow; 155"error" = red; 156}; 157} 158'' ; 159description = '' 160Each theme is written to 161{file}`$XDG_CONFIG_HOME/helix/themes/theme-name.toml`. 162Where the name of each attribute is the theme-name (in the example "base16"). 163 164See <https://docs.helix-editor.com/themes.html> 165for the full list of options. 166'' ; 167}; 168}; 169 170config = mkIf cfg . enable { 171home . packages = if cfg . extraPackages != [ ] then 172[ 173( pkgs . symlinkJoin { 174name = 175" ${ lib . getName cfg . package } -wrapped- ${ lib . getVersion cfg . package } " ; 176paths = [ cfg . package ]; 177preferLocalBuild = true ; 178nativeBuildInputs = [ pkgs . makeWrapper ]; 179postBuild = '' 180wrapProgram $ out /bin/hx \ 181--prefix PATH : ${ lib . makeBinPath cfg . extraPackages } 182'' ; 183}) 184] 185else 186[ cfg . package ]; 187 188home . sessionVariables = mkIf cfg . defaultEditor { EDITOR = "hx" ; }; 189 190xdg . configFile = let 191settings = { 192"helix/config.toml" = mkIf ( cfg . settings != { }) { 193source = tomlFormat . generate "helix-config" cfg . settings ; 194}; 195"helix/languages.toml" = mkIf ( cfg . languages != { }) { 196source = tomlFormat . generate "helix-languages-config" cfg . languages ; 197}; 198}; 199 200themes = ( mapAttrs' ( n :v : 201nameValuePair "helix/themes/ ${ n } .toml" { 202source = tomlFormat . generate "helix-theme- ${ n } " v ; 203}) cfg . themes ); 204in settings // themes ; 205}; 206}