From ad592a0e99386474a1826f3d90aeaff97848182c Mon Sep 17 00:00:00 2001 From: Flameopathic <64027365+Flameopathic@users.noreply.github.com> Date: Sun, 15 Jun 2025 13:57:02 +0200 Subject: [PATCH] wezterm: use mkTarget (#1472) Link: https://github.com/nix-community/stylix/pull/1472 Reviewed-by: Daniel Thwaites Reviewed-by: awwpotato Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com> --- modules/wezterm/hm.nix | 226 ++++++++++++++++++++++++----------------- 1 file changed, 131 insertions(+), 95 deletions(-) diff --git a/modules/wezterm/hm.nix b/modules/wezterm/hm.nix index c4aa0f83..b9350568 100644 --- a/modules/wezterm/hm.nix +++ b/modules/wezterm/hm.nix @@ -1,16 +1,21 @@ -{ config, lib, ... }: { - options.stylix.targets.wezterm.enable = - config.lib.stylix.mkEnableTarget "wezterm" true; - - config = - with config.lib.stylix.colors.withHashtag; - lib.mkIf - ( - config.stylix.enable - && config.stylix.targets.wezterm.enable - && config.programs.wezterm.enable - ) + mkTarget, + config, + lib, + ... +}: +mkTarget { + name = "wezterm"; + humanName = "WezTerm"; + extraOptions.luaBody = lib.mkOption { + type = lib.types.lines; + default = ""; + internal = true; + }; + configElements = [ + ( + { colors }: + with colors; { programs.wezterm.colorSchemes.stylix = { ansi = [ @@ -68,87 +73,118 @@ }; }; }; - - xdg.configFile."wezterm/wezterm.lua".text = - let - inherit (config.stylix) fonts; - in - lib.mkForce '' - -- Generated by Stylix - local wezterm = require("wezterm") - wezterm.add_to_config_reload_watch_list(wezterm.config_dir) - -- Allow working with both the current release and the nightly - local config = {} - if wezterm.config_builder then - config = wezterm.config_builder() - end - local stylix_base_config = { - color_scheme = "stylix", - font = wezterm.font_with_fallback { - "${fonts.monospace.name}", - "${fonts.emoji.name}", - }, - font_size = ${builtins.toString fonts.sizes.terminal}, - window_background_opacity = ${builtins.toString config.stylix.opacity.terminal}, - window_frame = { - active_titlebar_bg = "${base03}", - active_titlebar_fg = "${base05}", - active_titlebar_border_bottom = "${base03}", - border_left_color = "${base01}", - border_right_color = "${base01}", - border_bottom_color = "${base01}", - border_top_color = "${base01}", - button_bg = "${base01}", - button_fg = "${base05}", - button_hover_bg = "${base05}", - button_hover_fg = "${base03}", - inactive_titlebar_bg = "${base01}", - inactive_titlebar_fg = "${base05}", - inactive_titlebar_border_bottom = "${base03}", - }, - colors = { - tab_bar = { - background = "${base01}", - inactive_tab_edge = "${base01}", - active_tab = { - bg_color = "${base00}", - fg_color = "${base05}", - }, - inactive_tab = { - bg_color = "${base03}", - fg_color = "${base05}", - }, - inactive_tab_hover = { - bg_color = "${base05}", - fg_color = "${base00}", - }, - new_tab = { - bg_color = "${base03}", - fg_color = "${base05}", - }, - new_tab_hover = { - bg_color = "${base05}", - fg_color = "${base00}", - }, - }, - }, - command_palette_bg_color = "${base01}", - command_palette_fg_color = "${base05}", - command_palette_font_size = ${builtins.toString fonts.sizes.popups}, - } - for key, value in pairs(stylix_base_config) do - config[key] = value - end - local function stylix_wrapped_config() - ${config.programs.wezterm.extraConfig} - end - local stylix_user_config = stylix_wrapped_config() - if stylix_user_config then - for key, value in pairs(stylix_user_config) do - config[key] = value - end - end - return config - ''; - }; + stylix.targets.wezterm.luaBody = '' + color_scheme = "stylix", + window_frame = { + active_titlebar_bg = "${base03}", + active_titlebar_fg = "${base05}", + active_titlebar_border_bottom = "${base03}", + border_left_color = "${base01}", + border_right_color = "${base01}", + border_bottom_color = "${base01}", + border_top_color = "${base01}", + button_bg = "${base01}", + button_fg = "${base05}", + button_hover_bg = "${base05}", + button_hover_fg = "${base03}", + inactive_titlebar_bg = "${base01}", + inactive_titlebar_fg = "${base05}", + inactive_titlebar_border_bottom = "${base03}", + }, + colors = { + tab_bar = { + background = "${base01}", + inactive_tab_edge = "${base01}", + active_tab = { + bg_color = "${base00}", + fg_color = "${base05}", + }, + inactive_tab = { + bg_color = "${base03}", + fg_color = "${base05}", + }, + inactive_tab_hover = { + bg_color = "${base05}", + fg_color = "${base00}", + }, + new_tab = { + bg_color = "${base03}", + fg_color = "${base05}", + }, + new_tab_hover = { + bg_color = "${base05}", + fg_color = "${base00}", + }, + }, + }, + command_palette_bg_color = "${base01}", + command_palette_fg_color = "${base05}", + ''; + } + ) + ( + { fonts }: + { + stylix.targets.wezterm.luaBody = '' + font = wezterm.font_with_fallback { + "${fonts.monospace.name}", + "${fonts.emoji.name}", + }, + font_size = ${builtins.toString fonts.sizes.terminal}, + command_palette_font_size = ${builtins.toString fonts.sizes.popups}, + ''; + } + ) + ( + { opacity }: + { + stylix.targets.wezterm.luaBody = "window_background_opacity = ${builtins.toString opacity.terminal},"; + } + ) + ( + { cfg }: + let + indent = + string: " " + lib.concatStringsSep "\n " (lib.splitString "\n" string); + in + { + xdg.configFile."wezterm/wezterm.lua" = + lib.mkIf (config.programs.wezterm.enable && cfg.luaBody != "") + { + text = lib.mkForce ( + lib.concatLines [ + '' + -- Generated by Stylix + local wezterm = require("wezterm") + wezterm.add_to_config_reload_watch_list(wezterm.config_dir) + -- Allow working with both the current release and the nightly + local config = {} + if wezterm.config_builder then + config = wezterm.config_builder() + end + local stylix_base_config = { + '' + (indent cfg.luaBody) + '' + } + for key, value in pairs(stylix_base_config) do + config[key] = value + end + local function stylix_wrapped_config() + ${config.programs.wezterm.extraConfig} + end + local stylix_user_config = stylix_wrapped_config() + if stylix_user_config then + for key, value in pairs(stylix_user_config) do + config[key] = value + end + end + return config + '' + ] + ); + }; + } + ) + ]; }