treewide: use mkTarget (batch 3) (#1371)

Link: https://github.com/nix-community/stylix/pull/1371

Reviewed-by: pancho horrillo <pancho@pancho.name>
Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk>
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
awwpotato 2025-06-03 06:58:55 -07:00 committed by GitHub
parent ced2af0622
commit aa5e3c0333
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 270 additions and 249 deletions

View file

@ -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 ];
}
))
];
};
}
)
];
}

View file

@ -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}";
};
};
};
}

View file

@ -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}";
};
}

View file

@ -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}',
\ }
'';
};
}
)
];
}

View file

@ -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;
};
};
}
)
];
}

View file

@ -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;
};
};
};
}