From aa5e3c03330b8daec5c249d5d58ee970a1afed86 Mon Sep 17 00:00:00 2001 From: awwpotato Date: Tue, 3 Jun 2025 06:58:55 -0700 Subject: [PATCH] treewide: use mkTarget (batch 3) (#1371) Link: https://github.com/nix-community/stylix/pull/1371 Reviewed-by: pancho horrillo Reviewed-by: Matt Sturgeon Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com> Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com> --- modules/emacs/hm.nix | 154 ++++++++++++++++++++------------------- modules/eog/hm.nix | 21 +++--- modules/feh/nixos.nix | 35 ++++----- modules/vim/hm.nix | 121 +++++++++++++++--------------- modules/wayfire/hm.nix | 132 +++++++++++++++++++-------------- modules/wayprompt/hm.nix | 56 +++++++------- 6 files changed, 270 insertions(+), 249 deletions(-) diff --git a/modules/emacs/hm.nix b/modules/emacs/hm.nix index e3d61edf..70a2d776 100644 --- a/modules/emacs/hm.nix +++ b/modules/emacs/hm.nix @@ -1,83 +1,89 @@ -{ - pkgs, - config, - lib, - ... -}: -let - inherit (config.stylix) fonts; - emacsOpacity = builtins.toString ( - builtins.ceil (config.stylix.opacity.applications * 100) - ); - emacsSize = builtins.toString (fonts.sizes.terminal * 1.0); -in -{ - options.stylix.targets.emacs.enable = - config.lib.stylix.mkEnableTarget "Emacs" true; +{ mkTarget, pkgs, ... }: +mkTarget { + name = "emacs"; + humanName = "Emacs"; - config = lib.mkIf (config.stylix.enable && config.stylix.targets.emacs.enable) { - programs.emacs = { - extraPackages = epkgs: [ - (epkgs.trivialBuild ( - with config.lib.stylix.colors.withHashtag; - { - pname = "base16-stylix-theme"; - version = "0.1.0"; - src = pkgs.writeText "base16-stylix-theme.el" '' - (require 'base16-theme) + configElements = [ + ( + { opacity }: + { + programs.emacs.extraConfig = '' + (add-to-list 'default-frame-alist '(alpha-background . ${ + toString (builtins.ceil (opacity.applications * 100)) + })) + ''; + } + ) + ( + { fonts }: + { + programs.emacs.extraConfig = '' + (set-face-attribute 'default nil :font (font-spec :family "${fonts.monospace.name}" :size ${ + toString (fonts.sizes.terminal * 1.0) + })) + ''; + } + ) + ( + { colors }: + { + programs.emacs = { + extraConfig = '' + (require 'base16-stylix-theme) + (setq base16-theme-256-color-source 'colors) + (load-theme 'base16-stylix t) + ''; - (defvar base16-stylix-theme-colors - '(:base00 "${base00}" - :base01 "${base01}" - :base02 "${base02}" - :base03 "${base03}" - :base04 "${base04}" - :base05 "${base05}" - :base06 "${base06}" - :base07 "${base07}" - :base08 "${base08}" - :base09 "${base09}" - :base0A "${base0A}" - :base0B "${base0B}" - :base0C "${base0C}" - :base0D "${base0D}" - :base0E "${base0E}" - :base0F "${base0F}") - "All colors for Base16 stylix are defined here.") + extraPackages = epkgs: [ + (epkgs.trivialBuild ( + with colors.withHashtag; + { + pname = "base16-stylix-theme"; + version = "0.1.0"; + src = pkgs.writeText "base16-stylix-theme.el" '' + (require 'base16-theme) - ;; Define the theme - (deftheme base16-stylix) + (defvar base16-stylix-theme-colors + '(:base00 "${base00}" + :base01 "${base01}" + :base02 "${base02}" + :base03 "${base03}" + :base04 "${base04}" + :base05 "${base05}" + :base06 "${base06}" + :base07 "${base07}" + :base08 "${base08}" + :base09 "${base09}" + :base0A "${base0A}" + :base0B "${base0B}" + :base0C "${base0C}" + :base0D "${base0D}" + :base0E "${base0E}" + :base0F "${base0F}") + "All colors for Base16 stylix are defined here.") - ;; Add all the faces to the theme - (base16-theme-define 'base16-stylix base16-stylix-theme-colors) + ;; Define the theme + (deftheme base16-stylix) - ;; Mark the theme as provided - (provide-theme 'base16-stylix) + ;; Add all the faces to the theme + (base16-theme-define 'base16-stylix base16-stylix-theme-colors) - ;; Add path to theme to theme-path - (add-to-list 'custom-theme-load-path - (file-name-directory - (file-truename load-file-name))) + ;; Mark the theme as provided + (provide-theme 'base16-stylix) - (provide 'base16-stylix-theme) - ''; - packageRequires = [ epkgs.base16-theme ]; - } - )) - ]; + ;; Add path to theme to theme-path + (add-to-list 'custom-theme-load-path + (file-name-directory + (file-truename load-file-name))) - extraConfig = '' - ;; ---- Generated by stylix ---- - (require 'base16-stylix-theme) - (setq base16-theme-256-color-source 'colors) - (load-theme 'base16-stylix t) - ;; Set font - (set-face-attribute 'default nil :font (font-spec :family "${fonts.monospace.name}" :size ${emacsSize})) - ;; ----------------------------- - ;; set opacity - (add-to-list 'default-frame-alist '(alpha-background . ${emacsOpacity})) - ;; ----------------------------- - ''; - }; - }; + (provide 'base16-stylix-theme) + ''; + packageRequires = [ epkgs.base16-theme ]; + } + )) + ]; + }; + } + ) + ]; } diff --git a/modules/eog/hm.nix b/modules/eog/hm.nix index 73b4ff2d..7f1cd9f9 100644 --- a/modules/eog/hm.nix +++ b/modules/eog/hm.nix @@ -1,13 +1,14 @@ -{ config, lib, ... }: +{ mkTarget, ... }: +mkTarget { + name = "eog"; + humanName = "Eye of GNOME Image Viewer"; -{ - options.stylix.targets.eog.enable = - config.lib.stylix.mkEnableTarget "Eye of GNOME Image Viewer" true; - - config = lib.mkIf (config.stylix.enable && config.stylix.targets.eog.enable) { - dconf.settings."org/gnome/eog/view" = { - # transparency = "background"; # Disables the grey and white check pattern. - background-color = "#${config.lib.stylix.colors.base00}"; + configElements = + { colors }: + { + dconf.settings."org/gnome/eog/view" = { + # transparency = "background"; # Disables the grey and white check pattern. + background-color = "#${colors.base00}"; + }; }; - }; } diff --git a/modules/feh/nixos.nix b/modules/feh/nixos.nix index f826a161..eefd8190 100644 --- a/modules/feh/nixos.nix +++ b/modules/feh/nixos.nix @@ -1,29 +1,22 @@ { + mkTarget, + lib, pkgs, config, - lib, ... }: -let - cfg = config.stylix.targets.feh; -in -{ - options.stylix.targets.feh = { - enable = config.lib.stylix.mkEnableTarget "the desktop background using Feh" ( - config.stylix.image != null - ); - }; +mkTarget { + name = "feh"; + humanName = "the desktop background using Feh"; + autoEnable = + with config.services.xserver.windowManager; + xmonad.enable || i3.enable; - config.services.xserver.displayManager.sessionCommands = - lib.mkIf - ( - config.stylix.enable - && cfg.enable - && (with config.services.xserver.windowManager; xmonad.enable || i3.enable) - ) - ( + configElements = + { image, imageScalingMode }: + { + services.xserver.displayManager.sessionCommands = let - inherit (config.stylix) imageScalingMode; bg-arg = if imageScalingMode == "fill" then "--bg-fill" @@ -37,6 +30,6 @@ in else "--bg-max"; in - "${lib.getExe pkgs.feh} --no-fehbg ${bg-arg} ${config.stylix.image}" - ); + "${lib.getExe pkgs.feh} --no-fehbg ${bg-arg} ${image}"; + }; } diff --git a/modules/vim/hm.nix b/modules/vim/hm.nix index 7b04f751..939a7c8d 100644 --- a/modules/vim/hm.nix +++ b/modules/vim/hm.nix @@ -1,69 +1,70 @@ { - pkgs, - config, + mkTarget, lib, + pkgs, ... }: +mkTarget { + name = "vim"; + humanName = "Vim"; -let - themeFile = config.lib.stylix.colors { - templateRepo = config.stylix.inputs.base16-vim; - target = "base16"; - }; + configElements = [ + ( + { fonts }: + { + programs.vim.extraConfig = '' + set guifont=${ + lib.escape [ " " ] fonts.monospace.name + }:h${toString fonts.sizes.terminal} + ''; + } + ) + ( + { colors, inputs }: + { + programs.vim = { + plugins = [ + (pkgs.vimUtils.buildVimPlugin { + name = "stylix"; + pname = "stylix"; - themePlugin = pkgs.vimUtils.buildVimPlugin { - name = "stylix"; - pname = "stylix"; + src = colors { + templateRepo = inputs.base16-vim; + target = "base16"; + }; + dontUnpack = true; - src = themeFile; - dontUnpack = true; + buildPhase = '' + install -D $src $out/colors/base16-stylix.vim + ''; + }) + ]; + extraConfig = with colors.withHashtag; '' + set termguicolors + colorscheme base16-stylix + unlet g:colors_name - buildPhase = '' - install -D $src $out/colors/base16-stylix.vim - ''; - }; - - vimOptions = - let - inherit (config.stylix) fonts; - in - { - plugins = [ themePlugin ]; - extraConfig = with config.lib.stylix.colors.withHashtag; '' - set termguicolors - colorscheme base16-stylix - unlet g:colors_name - - let g:stylix_colors = { - \ 'base00': '${base00}', - \ 'base01': '${base01}', - \ 'base02': '${base02}', - \ 'base03': '${base03}', - \ 'base04': '${base04}', - \ 'base05': '${base05}', - \ 'base06': '${base06}', - \ 'base07': '${base07}', - \ 'base08': '${base08}', - \ 'base09': '${base09}', - \ 'base0A': '${base0A}', - \ 'base0B': '${base0B}', - \ 'base0C': '${base0C}', - \ 'base0D': '${base0D}', - \ 'base0E': '${base0E}', - \ 'base0F': '${base0F}', - \ } - - set guifont=${ - lib.escape [ " " ] fonts.monospace.name - }:h${toString fonts.sizes.terminal} - ''; - }; - -in -{ - options.stylix.targets.vim.enable = config.lib.stylix.mkEnableTarget "Vim" true; - - config = lib.mkIf (config.stylix.enable && config.stylix.targets.vim.enable) { - programs.vim = vimOptions; - }; + let g:stylix_colors = { + \ 'base00': '${base00}', + \ 'base01': '${base01}', + \ 'base02': '${base02}', + \ 'base03': '${base03}', + \ 'base04': '${base04}', + \ 'base05': '${base05}', + \ 'base06': '${base06}', + \ 'base07': '${base07}', + \ 'base08': '${base08}', + \ 'base09': '${base09}', + \ 'base0A': '${base0A}', + \ 'base0B': '${base0B}', + \ 'base0C': '${base0C}', + \ 'base0D': '${base0D}', + \ 'base0E': '${base0E}', + \ 'base0F': '${base0F}', + \ } + ''; + }; + } + ) + ]; } diff --git a/modules/wayfire/hm.nix b/modules/wayfire/hm.nix index 1cc6d9ba..72580c58 100644 --- a/modules/wayfire/hm.nix +++ b/modules/wayfire/hm.nix @@ -1,66 +1,86 @@ { + mkTarget, config, lib, pkgs, ... }: -let - cfg = config.stylix.targets.wayfire; -in +mkTarget { + name = "wayfire"; + humanName = "wayfire"; -{ - options.stylix.targets.wayfire = { - enable = config.lib.stylix.mkEnableTarget "wayfire" true; - useWallpaper = config.lib.stylix.mkEnableWallpaper "wayfire" true; - }; + extraOptions.useWallpaper = config.lib.stylix.mkEnableWallpaper "wayfire" true; - config = lib.mkIf (config.stylix.enable && cfg.enable) ( - let - inherit (config.lib.stylix) colors; - rgba = rgb: a: "\\#${rgb}${a}"; - rgb = (lib.flip rgba) "ff"; - - wayfireConfig = config.wayland.windowManager.wayfire; - - wayfireBackground = pkgs.runCommand "wayfire-background.png" { } '' - ${lib.getExe' pkgs.imagemagick "convert"} ${config.stylix.image} $out - ''; - in - { - wayland.windowManager.wayfire.settings = lib.mkIf wayfireConfig.enable { - cube = { - background = rgb colors.base00; - cubemap_image = lib.mkIf cfg.useWallpaper (toString wayfireBackground); - skydome_texture = lib.mkIf cfg.useWallpaper (toString wayfireBackground); - }; - - expo.background = rgb colors.base00; - vswitch.background = rgb colors.base00; - vswipe.background = rgb colors.base00; - core.background_color = rgb colors.base00; - - decoration = { - font = "${config.stylix.fonts.monospace.name} ${toString config.stylix.fonts.sizes.desktop}"; - active_color = rgb colors.base0D; - inactive_color = rgb colors.base03; - }; - }; - - wayland.windowManager.wayfire.wf-shell.settings = - lib.mkIf wayfireConfig.wf-shell.enable - { - background.image = lib.mkIf cfg.useWallpaper (toString wayfireBackground); - background.fill_mode = - if config.stylix.imageScalingMode == "stretch" then - "stretch" - else if config.stylix.imageScalingMode == "fit" then - "preserve_aspect" - else - "fill_and_crop"; - - panel.background_color = rgb colors.base01; - panel.menu_icon = "${pkgs.nixos-icons}/share/icons/hicolor/256x256/apps/nix-snowflake.png"; + configElements = [ + ( + { fonts }: + { + wayland.windowManager.wayfire.settings.decoration.font = + "${fonts.monospace.name} ${toString fonts.sizes.desktop}"; + } + ) + ( + { + cfg, + image, + imageScalingMode, + }: + let + wayfireBackground = pkgs.runCommand "wayfire-background.png" { } '' + ${lib.getExe' pkgs.imagemagick "convert"} ${image} $out + ''; + in + { + wayland.windowManager.wayfire.wf-shell.settings = { + background.image = lib.mkIf cfg.useWallpaper (toString wayfireBackground); + cube = { + cubemap_image = lib.mkIf cfg.useWallpaper (toString wayfireBackground); + skydome_texture = lib.mkIf cfg.useWallpaper (toString wayfireBackground); }; - } - ); + background.fill_mode = + if imageScalingMode == "stretch" then + "stretch" + else if imageScalingMode == "fit" then + "preserve_aspect" + else + "fill_and_crop"; + + }; + } + ) + (lib.mkIf config.stylix.targets.nixos-icons.enable { + wayland.windowManager.wayfire.wf-shell.settings.panel.menu_icon = + "${pkgs.nixos-icons}/share/icons/hicolor/256x256/apps/nix-snowflake.png"; + }) + ( + { colors }: + let + rgba = rgb: a: "\\#${rgb}${a}"; + rgb = (lib.flip rgba) "ff"; + in + { + wayland.windowManager.wayfire = { + settings = { + cube = { + background = rgb colors.base00; + }; + + expo.background = rgb colors.base00; + vswitch.background = rgb colors.base00; + vswipe.background = rgb colors.base00; + core.background_color = rgb colors.base00; + + decoration = { + active_color = rgb colors.base0D; + inactive_color = rgb colors.base03; + }; + }; + + wf-shell.settings = { + panel.background_color = rgb colors.base01; + }; + }; + } + ) + ]; } diff --git a/modules/wayprompt/hm.nix b/modules/wayprompt/hm.nix index 168dc60d..daf109bf 100644 --- a/modules/wayprompt/hm.nix +++ b/modules/wayprompt/hm.nix @@ -1,35 +1,35 @@ -{ config, lib, ... }: -let - cfg = config.stylix.targets.wayprompt; +{ mkTarget, lib, ... }: +mkTarget { + name = "wayprompt"; + humanName = "Wayprompt"; - opacity = lib.toHexString (builtins.ceil (config.stylix.opacity.popups * 255)); -in -{ - options.stylix.targets.wayprompt.enable = - config.lib.stylix.mkEnableTarget "Wayprompt" true; + configElements = + { colors, opacity }: + let + opacity' = lib.toHexString (builtins.ceil (opacity.popups * 255)); + in + { + programs.wayprompt.settings.colours = with colors; { + background = "${base00-hex}${opacity'}"; + border = base0D; + text = base05; + error-text = base08; - config = lib.mkIf (config.stylix.enable && cfg.enable) { - programs.wayprompt.settings.colours = with config.lib.stylix.colors; { - background = "${base00-hex}${opacity}"; - border = base0D; - text = base05; - error-text = base08; + pin-background = base01; + pin-border = base05; + pin-square = base05; - pin-background = base01; - pin-border = base05; - pin-square = base05; + ok-button = green; + ok-button-border = green; + ok-button-text = base00; - ok-button = green; - ok-button-border = green; - ok-button-text = base00; + not-ok-button = yellow; + not-ok-button-border = yellow; + not-ok-button-text = base00; - not-ok-button = yellow; - not-ok-button-border = yellow; - not-ok-button-text = base00; - - cancel-button = red; - cancel-button-border = red; - cancel-button-text = base00; + cancel-button = red; + cancel-button-border = red; + cancel-button-text = base00; + }; }; - }; }