From c8bc1c1d9ec5f3c852da40983ae0e9cfe775dbda Mon Sep 17 00:00:00 2001 From: awwpotato <153149335+awwpotato@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:22:18 -0700 Subject: [PATCH] treewide: remove use of multiple with statements (#1085) --- modules/alacritty/hm.nix | 2 +- modules/bemenu/hm.nix | 5 ++-- modules/dunst/hm.nix | 53 +++++++++++++++++++----------------- modules/ghostty/hm.nix | 38 +++++++++++++------------- modules/grub/nixos.nix | 7 +++-- modules/kitty/hm.nix | 4 +-- modules/lazygit/hm.nix | 38 +++++++++++++------------- modules/mako/hm.nix | 14 +++++----- modules/mangohud/hm.nix | 56 ++++++++++++++++++++------------------- modules/rio/hm.nix | 2 +- modules/swaync/hm.nix | 8 +++--- modules/sxiv/hm.nix | 14 +++++----- modules/tofi/hm.nix | 6 ++--- modules/wezterm/hm.nix | 12 +++++---- modules/wob/hm.nix | 14 +++++----- modules/wofi/hm.nix | 8 +++--- modules/xresources/hm.nix | 8 +++--- modules/zed/hm.nix | 27 ++++++++++--------- 18 files changed, 161 insertions(+), 155 deletions(-) diff --git a/modules/alacritty/hm.nix b/modules/alacritty/hm.nix index cdf95062..abc1718e 100644 --- a/modules/alacritty/hm.nix +++ b/modules/alacritty/hm.nix @@ -21,7 +21,7 @@ in }; size = sizes.terminal; }; - window.opacity = with config.stylix.opacity; terminal; + window.opacity = config.stylix.opacity.terminal; colors = with colors; { primary = { foreground = base05; diff --git a/modules/bemenu/hm.nix b/modules/bemenu/hm.nix index b5fc2663..bd1384ed 100644 --- a/modules/bemenu/hm.nix +++ b/modules/bemenu/hm.nix @@ -25,9 +25,8 @@ { programs.bemenu.settings = with config.lib.stylix.colors.withHashtag; - with config.stylix.fonts; - with config.stylix.targets.bemenu; let + inherit (config.stylix.targets.bemenu) alternate fontSize; bemenuOpacity = lib.toHexString ( ((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100 ); @@ -51,7 +50,7 @@ af = "${if alternate then base04 else base05}"; # Alternate fg # Font name - fn = "${sansSerif.name} ${ + fn = "${config.stylix.fonts.sansSerif.name} ${ lib.optionalString (fontSize != null) (builtins.toString fontSize) }"; }; diff --git a/modules/dunst/hm.nix b/modules/dunst/hm.nix index c13dcf53..fbeb50b0 100644 --- a/modules/dunst/hm.nix +++ b/modules/dunst/hm.nix @@ -1,37 +1,40 @@ { config, lib, ... }: -let - dunstOpacity = lib.toHexString ( - ((builtins.floor (config.stylix.opacity.popups * 100 + 0.5)) * 255) / 100 - ); -in { options.stylix.targets.dunst.enable = config.lib.stylix.mkEnableTarget "Dunst" true; config = lib.mkIf (config.stylix.enable && config.stylix.targets.dunst.enable) { - services.dunst.settings = with config.lib.stylix.colors.withHashtag; { - global = { - separator_color = base02; - font = with config.stylix.fonts; "${sansSerif.name} ${toString sizes.popups}"; - }; + services.dunst.settings = + with config.lib.stylix.colors.withHashtag; + let + inherit (config.stylix) fonts; + dunstOpacity = lib.toHexString ( + ((builtins.floor (config.stylix.opacity.popups * 100 + 0.5)) * 255) / 100 + ); + in + { + global = { + separator_color = base02; + font = "${fonts.sansSerif.name} ${toString fonts.sizes.popups}"; + }; - urgency_low = { - background = base01 + dunstOpacity; - foreground = base05; - frame_color = base0B; - }; + urgency_low = { + background = base01 + dunstOpacity; + foreground = base05; + frame_color = base0B; + }; - urgency_normal = { - background = base01 + dunstOpacity; - foreground = base05; - frame_color = base0E; - }; + urgency_normal = { + background = base01 + dunstOpacity; + foreground = base05; + frame_color = base0E; + }; - urgency_critical = { - background = base01 + dunstOpacity; - foreground = base05; - frame_color = base08; + urgency_critical = { + background = base01 + dunstOpacity; + foreground = base05; + frame_color = base08; + }; }; - }; }; } diff --git a/modules/ghostty/hm.nix b/modules/ghostty/hm.nix index b75f79e1..1b14f22c 100644 --- a/modules/ghostty/hm.nix +++ b/modules/ghostty/hm.nix @@ -26,32 +26,32 @@ themes.stylix = let inherit (config.lib.stylix) colors; - inherit (config.lib.stylix.colors) withHashtag; in { - palette = [ - "0=${withHashtag.base00}" - "1=${withHashtag.base08}" - "2=${withHashtag.base0B}" - "3=${withHashtag.base0A}" - "4=${withHashtag.base0D}" - "5=${withHashtag.base0E}" - "6=${withHashtag.base0C}" - "7=${withHashtag.base05}" - "8=${withHashtag.base03}" - "9=${withHashtag.base08}" - "10=${withHashtag.base0B}" - "11=${withHashtag.base0A}" - "12=${withHashtag.base0D}" - "13=${withHashtag.base0E}" - "14=${withHashtag.base0C}" - "15=${withHashtag.base07}" - ]; background = colors.base00; foreground = colors.base05; cursor-color = colors.base05; selection-background = colors.base02; selection-foreground = colors.base05; + + palette = with colors.withHashtag; [ + "0=${base00}" + "1=${base08}" + "2=${base0B}" + "3=${base0A}" + "4=${base0D}" + "5=${base0E}" + "6=${base0C}" + "7=${base05}" + "8=${base03}" + "9=${base08}" + "10=${base0B}" + "11=${base0A}" + "12=${base0D}" + "13=${base0E}" + "14=${base0C}" + "15=${base07}" + ]; }; }; }; diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix index 463c07e7..b74095f3 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -8,6 +8,7 @@ let cfg = config.stylix.targets.grub; inherit (config.stylix) imageScalingMode fonts; + inherit (config.lib.stylix) mkEnableTarget mkEnableWallpaper pixel; # Grub requires fonts to be converted to "PFF2 format" # This function takes a font { name, package } and produces a .pf2 file mkGrubFont = @@ -57,15 +58,13 @@ in ]; }) ]; - options.stylix.targets.grub = with config.lib.stylix; { + options.stylix.targets.grub = { enable = mkEnableTarget "GRUB" true; useWallpaper = mkEnableWallpaper "GRUB" false; }; config.boot.loader.grub = with config.lib.stylix.colors.withHashtag; - with config.lib.stylix; - with config.stylix.fonts; lib.mkIf (config.stylix.enable && cfg.enable) { backgroundColor = base00; # Need to override the NixOS splash, this will match the background @@ -144,7 +143,7 @@ in cp ${pixel "base01"} $out/background_c.png cp ${pixel "base0B"} $out/selection_c.png - cp ${mkGrubFont sansSerif} $out/sans_serif.pf2 + cp ${mkGrubFont fonts.sansSerif} $out/sans_serif.pf2 ''; }; } diff --git a/modules/kitty/hm.nix b/modules/kitty/hm.nix index 9b60997b..72594ae5 100644 --- a/modules/kitty/hm.nix +++ b/modules/kitty/hm.nix @@ -27,9 +27,7 @@ in inherit (config.stylix.fonts.monospace) package name; size = config.stylix.fonts.sizes.terminal; }; - settings.background_opacity = - with config.stylix.opacity; - "${builtins.toString terminal}"; + settings.background_opacity = "${builtins.toString config.stylix.opacity.terminal}"; extraConfig = '' include ${theme} ''; diff --git a/modules/lazygit/hm.nix b/modules/lazygit/hm.nix index 59f6a0b7..baaf6390 100644 --- a/modules/lazygit/hm.nix +++ b/modules/lazygit/hm.nix @@ -3,9 +3,6 @@ lib, ... }: -let - colors = config.lib.stylix.colors.withHashtag; -in { options.stylix.targets.lazygit.enable = config.lib.stylix.mkEnableTarget "lazygit" true; @@ -13,22 +10,23 @@ in config = lib.mkIf (config.stylix.enable && config.stylix.targets.lazygit.enable) { - programs.lazygit.settings.gui.theme = { - activeBorderColor = [ - colors.base07 - "bold" - ]; - inactiveBorderColor = [ colors.base04 ]; - searchingActiveBorderColor = [ - colors.base02 - "bold" - ]; - optionsTextColor = [ colors.base06 ]; - selectedLineBgColor = [ colors.base03 ]; - cherryPickedCommitBgColor = [ colors.base02 ]; - cherryPickedCommitFgColor = [ colors.base03 ]; - unstagedChangesColor = [ colors.base08 ]; - defaultFgColor = [ colors.base05 ]; - }; + programs.lazygit.settings.gui.theme = + with config.lib.stylix.colors.withHashtag; { + activeBorderColor = [ + base07 + "bold" + ]; + inactiveBorderColor = [ base04 ]; + searchingActiveBorderColor = [ + base02 + "bold" + ]; + optionsTextColor = [ base06 ]; + selectedLineBgColor = [ base03 ]; + cherryPickedCommitBgColor = [ base02 ]; + cherryPickedCommitFgColor = [ base03 ]; + unstagedChangesColor = [ base08 ]; + defaultFgColor = [ base05 ]; + }; }; } diff --git a/modules/mako/hm.nix b/modules/mako/hm.nix index 54ca5e29..d24890f7 100644 --- a/modules/mako/hm.nix +++ b/modules/mako/hm.nix @@ -4,11 +4,6 @@ options, ... }: -let - makoOpacity = lib.toHexString ( - ((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100 - ); -in { options.stylix.targets.mako.enable = config.lib.stylix.mkEnableTarget "Mako" true; @@ -17,14 +12,19 @@ in config = lib.optionalAttrs (options.services ? mako) ( lib.mkIf (config.stylix.enable && config.stylix.targets.mako.enable) { services.mako = + let + makoOpacity = lib.toHexString ( + ((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100 + ); + inherit (config.stylix) fonts; + in with config.lib.stylix.colors.withHashtag; - with config.stylix.fonts; { backgroundColor = base00 + makoOpacity; borderColor = base0D; textColor = base05; progressColor = "over ${base02}"; - font = "${sansSerif.name} ${toString sizes.popups}"; + font = "${fonts.sansSerif.name} ${toString fonts.sizes.popups}"; # I wish the mako hm module was like the dunst one extraConfig = '' [urgency=low] diff --git a/modules/mangohud/hm.nix b/modules/mangohud/hm.nix index ef78662e..12800538 100644 --- a/modules/mangohud/hm.nix +++ b/modules/mangohud/hm.nix @@ -1,7 +1,4 @@ { config, lib, ... }: -let - inherit (config.stylix) fonts opacity; -in { options.stylix.targets.mangohud.enable = config.lib.stylix.mkEnableTarget "mangohud" true; @@ -9,31 +6,36 @@ in config = lib.mkIf (config.stylix.enable && config.stylix.targets.mangohud.enable) { - programs.mangohud.settings = with config.lib.stylix.colors; { - font_size = fonts.sizes.applications; - font_size_text = fonts.sizes.applications; - background_alpha = opacity.popups; - alpha = opacity.applications; - text_color = base05; - text_outline_color = base00; - background_color = base00; - gpu_color = base0B; - cpu_color = base0D; - vram_color = base0C; - media_player_color = base05; - engine_color = base0E; - wine_color = base0E; - frametime_color = base0B; - battery_color = base04; - io_color = base0A; - gpu_load_color = "${base0B}, ${base0A}, ${base08}"; - cpu_load_color = "${base0B}, ${base0A}, ${base08}"; - fps_color = "${base0B}, ${base0A}, ${base08}"; + programs.mangohud.settings = + let + inherit (config.stylix) fonts opacity; + in + with config.lib.stylix.colors; + { + font_size = fonts.sizes.applications; + font_size_text = fonts.sizes.applications; + background_alpha = opacity.popups; + alpha = opacity.applications; + text_color = base05; + text_outline_color = base00; + background_color = base00; + gpu_color = base0B; + cpu_color = base0D; + vram_color = base0C; + media_player_color = base05; + engine_color = base0E; + wine_color = base0E; + frametime_color = base0B; + battery_color = base04; + io_color = base0A; + gpu_load_color = "${base0B}, ${base0A}, ${base08}"; + cpu_load_color = "${base0B}, ${base0A}, ${base08}"; + fps_color = "${base0B}, ${base0A}, ${base08}"; - # TODO: Use the point unit: - # https://github.com/danth/stylix/issues/251. - font_scale = 1.33333; - }; + # TODO: Use the point unit: + # https://github.com/danth/stylix/issues/251. + font_scale = 1.33333; + }; }; } diff --git a/modules/rio/hm.nix b/modules/rio/hm.nix index a0dfb581..1dda9bab 100644 --- a/modules/rio/hm.nix +++ b/modules/rio/hm.nix @@ -16,7 +16,7 @@ # converting font size to px size = sizes.terminal * 4.0 / 3.0; }; - window.opacity = with config.stylix.opacity; terminal; + window.opacity = config.stylix.opacity.terminal; colors = with config.lib.stylix.colors.withHashtag; { selection-background = base02; selection-foreground = base05; diff --git a/modules/swaync/hm.nix b/modules/swaync/hm.nix index 4a6f828e..d1d4fb59 100644 --- a/modules/swaync/hm.nix +++ b/modules/swaync/hm.nix @@ -12,7 +12,9 @@ lib.mkIf (config.stylix.enable && config.stylix.targets.swaync.enable) { services.swaync.style = - with config.stylix.fonts; + let + inherit (config.stylix) fonts; + in with config.lib.stylix.colors.withHashtag; '' @define-color base00 ${base00}; @define-color base01 ${base01}; @define-color base02 ${base02}; @define-color base03 ${base03}; @@ -22,8 +24,8 @@ @define-color base0C ${base0C}; @define-color base0D ${base0D}; @define-color base0E ${base0E}; @define-color base0F ${base0F}; * { - font-family: "${sansSerif.name}"; - font-size: ${builtins.toString sizes.desktop}pt; + font-family: "${fonts.sansSerif.name}"; + font-size: ${builtins.toString fonts.sizes.desktop}pt; } '' + (builtins.readFile ./base.css); diff --git a/modules/sxiv/hm.nix b/modules/sxiv/hm.nix index 827fc4f0..55661385 100644 --- a/modules/sxiv/hm.nix +++ b/modules/sxiv/hm.nix @@ -1,20 +1,18 @@ { config, lib, ... }: - -let - inherit (config.lib.stylix) colors; - inherit (config.stylix) fonts; -in { options.stylix.targets.sxiv.enable = config.lib.stylix.mkEnableTarget "Sxiv" true; config = lib.mkIf (config.stylix.enable && config.stylix.targets.sxiv.enable) { - xresources = { - properties = { + xresources.properties = + let + inherit (config.lib.stylix) colors; + inherit (config.stylix) fonts; + in + { "Sxiv.foreground" = "#${colors.base01}"; "Sxiv.background" = "#${colors.base04}"; "Sxiv.font" = "${fonts.sansSerif.name}-${toString fonts.sizes.applications}"; }; - }; }; } diff --git a/modules/tofi/hm.nix b/modules/tofi/hm.nix index c0b6c1bf..79c8661b 100644 --- a/modules/tofi/hm.nix +++ b/modules/tofi/hm.nix @@ -9,9 +9,9 @@ config = lib.mkIf (config.stylix.enable && config.stylix.targets.tofi.enable) { programs.tofi.settings = - with config.stylix.fonts; with config.lib.stylix.colors.withHashtag; let + inherit (config.stylix) fonts; opacity = lib.toHexString ( ((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100 ); @@ -21,8 +21,8 @@ selection = base03 + opacity; in { - font = monospace.name; - font-size = toString sizes.popups; + font = fonts.monospace.name; + font-size = toString fonts.sizes.popups; background-color = background; outline-color = darkForeground; border-color = foreground; diff --git a/modules/wezterm/hm.nix b/modules/wezterm/hm.nix index 5a915e88..89deb24e 100644 --- a/modules/wezterm/hm.nix +++ b/modules/wezterm/hm.nix @@ -70,7 +70,9 @@ }; xdg.configFile."wezterm/wezterm.lua".text = - with config.stylix.fonts; + let + inherit (config.stylix) fonts; + in lib.mkForce '' -- Generated by Stylix local wezterm = require("wezterm") @@ -83,10 +85,10 @@ stylix_base_config = { color_scheme = "stylix", font = wezterm.font_with_fallback { - "${monospace.name}", - "${emoji.name}", + "${fonts.monospace.name}", + "${fonts.emoji.name}", }, - font_size = ${builtins.toString sizes.terminal}, + font_size = ${builtins.toString fonts.sizes.terminal}, window_background_opacity = ${builtins.toString config.stylix.opacity.terminal}, window_frame = { active_titlebar_bg = "${base03}", @@ -132,7 +134,7 @@ }, command_palette_bg_color = "${base01}", command_palette_fg_color = "${base05}", - command_palette_font_size = ${builtins.toString sizes.popups}, + command_palette_font_size = ${builtins.toString fonts.sizes.popups}, } for key, value in pairs(stylix_user_config) do stylix_base_config[key] = value diff --git a/modules/wob/hm.nix b/modules/wob/hm.nix index ad68738c..ee3bd5e2 100644 --- a/modules/wob/hm.nix +++ b/modules/wob/hm.nix @@ -5,13 +5,13 @@ config = lib.mkIf (config.stylix.enable && config.stylix.targets.wob.enable) { services.wob.settings = { - "" = { - border_color = config.lib.stylix.colors.base05; - background_color = config.lib.stylix.colors.base00; - bar_color = config.lib.stylix.colors.base0A; - overflow_bar_color = config.lib.stylix.colors.base08; - overflow_background_color = config.lib.stylix.colors.base00; - overflow_border_color = config.lib.stylix.colors.base05; + "" = with config.lib.stylix.colors; { + border_color = base05; + background_color = base00; + bar_color = base0A; + overflow_bar_color = base08; + overflow_background_color = base00; + overflow_border_color = base05; }; }; }; diff --git a/modules/wofi/hm.nix b/modules/wofi/hm.nix index 70adae68..7aa39393 100644 --- a/modules/wofi/hm.nix +++ b/modules/wofi/hm.nix @@ -9,12 +9,14 @@ config = lib.mkIf (config.stylix.enable && config.stylix.targets.wofi.enable) { programs.wofi.style = + let + inherit (config.stylix) fonts; + in with config.lib.stylix.colors.withHashtag; - with config.stylix.fonts; '' window { - font-family: "${monospace.name}"; - font-size: ${toString sizes.popups}pt; + font-family: "${fonts.monospace.name}"; + font-size: ${toString fonts.sizes.popups}pt; background-color: ${base00}; color: ${base05}; diff --git a/modules/xresources/hm.nix b/modules/xresources/hm.nix index 1bfc504f..de6d8629 100644 --- a/modules/xresources/hm.nix +++ b/modules/xresources/hm.nix @@ -8,11 +8,13 @@ lib.mkIf (config.stylix.enable && config.stylix.targets.xresources.enable) { xresources.properties = + let + inherit (config.stylix) fonts; + in with config.lib.stylix.colors.withHashtag; - with config.stylix.fonts; { - "*.faceName" = monospace.name; - "*.faceSize" = toString sizes.terminal; + "*.faceName" = fonts.monospace.name; + "*.faceSize" = toString fonts.sizes.terminal; "*.renderFont" = true; "*foreground" = base05; "*background" = base00; diff --git a/modules/zed/hm.nix b/modules/zed/hm.nix index c9a91e02..f102b8f3 100644 --- a/modules/zed/hm.nix +++ b/modules/zed/hm.nix @@ -3,11 +3,6 @@ lib, ... }: -let - theme = config.lib.stylix.colors { - templateRepo = config.stylix.inputs.tinted-zed; - }; -in { options.stylix.targets.zed.enable = config.lib.stylix.mkEnableTarget "zed" true; @@ -19,14 +14,20 @@ in && config.programs.zed-editor.enable ) { - programs.zed-editor.userSettings = { - "buffer_font_family" = config.stylix.fonts.monospace.name; - "buffer_font_size" = config.stylix.fonts.sizes.terminal * 4.0 / 3.0; - "theme" = "Base16 ${config.lib.stylix.colors.scheme-name}"; - "ui_font_family" = config.stylix.fonts.sansSerif.name; - "ui_font_size" = config.stylix.fonts.sizes.applications * 4.0 / 3.0; - }; + programs.zed-editor.userSettings = + let + inherit (config.stylix) fonts; + in + { + "buffer_font_family" = fonts.monospace.name; + "buffer_font_size" = fonts.sizes.terminal * 4.0 / 3.0; + "theme" = "Base16 ${config.lib.stylix.colors.scheme-name}"; + "ui_font_family" = fonts.sansSerif.name; + "ui_font_size" = fonts.sizes.applications * 4.0 / 3.0; + }; - xdg.configFile."zed/themes/nix.json".source = theme; + xdg.configFile."zed/themes/nix.json".source = config.lib.stylix.colors { + templateRepo = config.stylix.inputs.tinted-zed; + }; }; }