I always try to modularize my configs, speacilly my desktop (nix-darwin) config. So I came with this module to set helix editor up with home-manager:
{
pkgs,
lib,
next-ls,
custom-config,
...
}: let
inherit (lib) mkEnableOption mkIf mkOption types mkDefault;
cfg = custom-config.helix;
elixir = cfg.languages.elixir;
rust = cfg.languages.rust;
clojure = cfg.languages.clojure;
nix = cfg.languages.nix;
html = cfg.languages.html;
css = cfg.languages.css;
json = cfg.languages.json;
typescript = cfg.languages.typescript;
vscode-lsp = pkgs.nodePackages.vscode-langservers-extracted;
inherit (pkgs.beam.packages) erlangR25;
in {
options.helix = {
enable = mkEnableOption "Enbales Helix Editor";
languages = {
elixir = {
enable = mkEnableOption "Enables Elixir Support";
package = mkOption {
default = mkDefault erlangR25.elixir_1_15;
type = types.package;
description = "The Elixir pkg used to build both next-ls and lexical-lsp";
};
erlang = mkOption {
default = mkDefault erlangR25;
type = types.package;
description = "The Erlang pkg used to build both next-ls and lexical-lsp";
};
};
nix.enable = mkEnableOption "Enables Nix Support";
rust.enable = mkEnableOption "Enables Rust Support";
clojure.enable = mkEnableOption "Enables Clojure Support";
html.enable = mkEnableOption "Enables HTML Support";
css.enable = mkEnableOption "Enables CSS Support";
json.enable = mkEnableOption "Enables JSON Support";
typescript.enable = mkEnableOption "Enables Typescript Support";
};
};
config = mkIf cfg.enable {
programs.helix = {
inherit (cfg) enable;
settings = {
theme = "onedark";
editor = {
cursorline = true;
color-modes = true;
line-number = "relative";
lsp.display-messages = true;
true-color = true;
statusline.center = ["position-percentage"];
whitespace.characters = {
newline = "↴";
tab = "⇥";
};
indent-guides = {
render = true;
rainbow-option = "dim";
};
cursor-shape = {
insert = "bar";
normal = "block";
select = "underline";
};
};
keys.normal = {
esc = ["collapse_selection" "keep_primary_selection"];
};
};
languages = {
language-server = {
nextls = mkIf elixir.enable {
command = "${next-ls.packages."${pkgs.system}".default}/bin/nextls";
args = ["--stdio=true"];
};
typescript-language-server = let
ts-server = pkgs.nodePackages.typescript-language-server;
in
mkIf typescript.enable {
command = "${ts-server}/bin/typescript-language-server";
args = ["--stdio"];
};
nil.command = mkIf nix.enable "${pkgs.nil}/bin/nil";
lexical-lsp.command = let
lexical-lsp = elixir.erlang.callPackage ../../custom/lexical-lsp.nix {elixir = elixir.package;};
in
mkIf elixir.enable "${lexical-lsp}/bin/lexical";
# elixir-ls.command = mkIf elixir.enable "${beam.elixir-ls}/bin/elixir-ls";
clojure-lsp.command = mkIf clojure.enable "${pkgs.clojure-lsp}/bin/clojure-lsp";
rust-analyzer.command = mkIf rust.enable "${pkgs.rust-analyzer}bin/rust-analyzer";
vscode-css-language-server = mkIf css.enable {
command = "${vscode-lsp}/bin/vscode-css-language-server";
args = ["--stdio"];
config = {
provideFormatter = true;
css = {validate = {enable = true;};};
};
};
vscode-html-language-server = mkIf html.enable {
command = "${vscode-lsp}/bin/vscode-css-language-server";
args = ["--stdio"];
config = {
provideFormatter = true;
html = {validate = {enable = true;};};
};
};
vscode-json-language-server = mkIf json.enable {
command = "${vscode-lsp}/bin/vscode-css-language-server";
args = ["--stdio"];
config = {
provideFormatter = true;
json = {validate = {enable = true;};};
};
};
};
language = let
mix = {
formatter = {
command = "${pkgs.elixir}/bin/mix";
args = ["format" "-"];
};
};
n = {
formatter = {
command = "${pkgs.alejandra}/bin/alejandra";
};
};
ts = {
formatter = {
command = "${pkgs.nodePackages.prettier}/bin/prettier";
};
};
in [
(mkIf elixir.enable {
inherit (mix) formatter;
name = "elixir";
auto-format = true;
language-servers = ["lexical-lsp" "nextls"];
})
(mkIf elixir.enable {
inherit (mix) formatter;
name = "heex";
auto-format = true;
})
(mkIf elixir.enable {
inherit (mix) formatter;
name = "eex";
auto-format = true;
})
(mkIf nix.enable {
inherit (n) formatter;
name = "nix";
auto-format = true;
})
(mkIf typescript.enable {
inherit (ts) formatter;
name = "typescript";
auto-format = true;
})
];
};
};
};
}
then I define my custom module as:
{pkgs, …}:
{
helix = {
enable = true;
languages = {
clojure.enable = false;
html.enable = true;
css.enable = true;
json.enable = true;
rust.enable = true;
nix.enable = true;
typescript.enable = true;
elixir.enable = true;
};
}
however if I try to build I receive this error message:
warning: Git tree '/Users/zoedsoupe/dev/personal/zoeyrinha' is dirty
trace: warning: optionsDocBook is deprecated since 23.11 and will be removed in 24.05
trace: warning: optionsDocBook is deprecated since 23.11 and will be removed in 24.05
trace: warning: optionsDocBook is deprecated since 23.11 and will be removed in 24.05
error:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'darwin-system-23.11pre-git+darwin4.e67f2bf'
whose name attribute is located at /nix/store/kcmipm57ph9bpzz8bs80iiijiwbyzwy3-source/pkgs/stdenv/generic/make-derivation.nix:311:7
… while evaluating attribute 'activationScript' of derivation 'darwin-system-23.11pre-git+darwin4.e67f2bf'
at /nix/store/54y7x50iy7y0i6zfp2bf6bxsngl7fml3-source/modules/system/default.nix:95:7:
94|
95| activationScript = cfg.activationScripts.script.text;
| ^
96| activationUserScript = cfg.activationScripts.userScript.text;
(stack trace truncated; use '--show-trace' to show the full trace)
error: attribute 'erlang' missing
at /nix/store/rnh0gza8ljyxfysc8wk3rg96ifzdk0d5-source/modules/users/helix.nix:93:27:
92| lexical-lsp.command = let
93| lexical-lsp = elixir.erlang.callPackage ../../custom/lexical-lsp.nix {elixir = elixir.package;};
| ^
94| in
So defaults weren’t set? Why it is complaining about a missing config?