{ pkgs, config, lib, ... }: let inherit (config.grimmShared) enable tooling; inherit (lib) mkOption types getExe mkIf ; inherit (pkgs) helix symlinkJoin writeTextDir concatTextFile makeWrapper ; inherit (pkgs.writers) writeTOML; conf-file-name = "config.toml"; lang-file-name = "languages.toml"; helix-conf = symlinkJoin { name = "helix-conf"; paths = [ (concatTextFile { name = "helix-conf-partial"; destination = "/${conf-file-name}"; files = [ (writeTOML conf-file-name config.programs.helix.config) ]; }) (writeTextDir lang-file-name '' [[language]] language-servers = ["nixd"] name = "nix" [language-server.nixd] command = "${getExe pkgs.nixd}" '') ]; }; helix-wrapped = pkgs.symlinkJoin { name = helix.pname; paths = [ helix ]; buildInputs = [ makeWrapper ]; postBuild = '' wrapProgram $out/bin/${helix.meta.mainProgram} --add-flags "-c ${helix-conf}/${conf-file-name}" ''; }; in { config = mkIf (enable && tooling.enable) { environment.systemPackages = [ helix-wrapped ]; environment.sessionVariables.EDITOR = getExe helix; programs.helix.config = { theme = "catppuccin_mocha"; }; }; options.programs.helix = { config = mkOption { type = types.attrs; default = { }; description = "Helix configuration"; }; }; }