firefox: use mkTarget (#1339)
Link: https://github.com/nix-community/stylix/pull/1339 Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk> Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk> Reviewed-by: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
parent
599c76190f
commit
a231e38dfc
2 changed files with 182 additions and 164 deletions
155
modules/firefox/each-config.nix
Normal file
155
modules/firefox/each-config.nix
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
# manually applied args
|
||||
{
|
||||
mkTarget,
|
||||
name,
|
||||
humanName,
|
||||
}:
|
||||
# module args
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
mkTarget {
|
||||
inherit name humanName;
|
||||
|
||||
extraOptions = {
|
||||
profileNames = lib.mkOption {
|
||||
description = "The ${humanName} profile names to apply styling on.";
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
colorTheme.enable = lib.mkEnableOption "[Firefox Color](https://color.firefox.com/) on ${humanName}";
|
||||
|
||||
firefoxGnomeTheme.enable = lib.mkEnableOption "[Firefox GNOME theme](https://github.com/rafaelmardojai/firefox-gnome-theme) on ${humanName}";
|
||||
};
|
||||
|
||||
configElements = [
|
||||
(
|
||||
{ cfg }:
|
||||
{
|
||||
warnings =
|
||||
lib.optional (config.programs.${name}.enable && cfg.profileNames == [ ])
|
||||
''stylix: ${name}: `config.stylix.targets.${name}.profileNames` is not set. Declare profile names with 'config.stylix.targets.${name}.profileNames = [ "<PROFILE_NAME>" ];'.'';
|
||||
}
|
||||
)
|
||||
(
|
||||
{ cfg, fonts }:
|
||||
{
|
||||
programs.${name}.profiles = lib.genAttrs cfg.profileNames (_: {
|
||||
settings = {
|
||||
"font.name.monospace.x-western" = fonts.monospace.name;
|
||||
"font.name.sans-serif.x-western" = fonts.sansSerif.name;
|
||||
"font.name.serif.x-western" = fonts.serif.name;
|
||||
};
|
||||
});
|
||||
}
|
||||
)
|
||||
(
|
||||
{
|
||||
cfg,
|
||||
colors,
|
||||
inputs,
|
||||
}:
|
||||
{
|
||||
programs.${name}.profiles = lib.mkIf cfg.firefoxGnomeTheme.enable (
|
||||
lib.genAttrs cfg.profileNames (_: {
|
||||
settings = {
|
||||
"toolkit.legacyUserProfileCustomizations.stylesheets" = true;
|
||||
"svg.context-properties.content.enabled" = true;
|
||||
};
|
||||
|
||||
userChrome =
|
||||
let
|
||||
template = colors {
|
||||
template = ./userChrome.css.mustache;
|
||||
extension = ".css";
|
||||
};
|
||||
in
|
||||
''
|
||||
@import "${inputs.firefox-gnome-theme}/userChrome.css";
|
||||
@import "${template}";
|
||||
'';
|
||||
|
||||
userContent = ''
|
||||
@import "${inputs.firefox-gnome-theme}/userContent.css";
|
||||
'';
|
||||
})
|
||||
);
|
||||
}
|
||||
)
|
||||
(
|
||||
{
|
||||
cfg,
|
||||
colors,
|
||||
inputs,
|
||||
}:
|
||||
let
|
||||
mkColor = color: {
|
||||
r = colors."${color}-rgb-r";
|
||||
g = colors."${color}-rgb-g";
|
||||
b = colors."${color}-rgb-b";
|
||||
};
|
||||
inherit (pkgs.stdenv.hostPlatform) system;
|
||||
inherit (inputs.nur.legacyPackages.${system}.repos.rycee)
|
||||
firefox-addons
|
||||
;
|
||||
in
|
||||
{
|
||||
programs.${name}.profiles = lib.mkIf cfg.colorTheme.enable (
|
||||
lib.genAttrs cfg.profileNames (_: {
|
||||
extensions = {
|
||||
packages = [ firefox-addons.firefox-color ];
|
||||
settings."FirefoxColor@mozilla.com".settings = {
|
||||
firstRunDone = true;
|
||||
theme = {
|
||||
title = "Stylix ${colors.description}";
|
||||
images.additional_backgrounds = [ "./bg-000.svg" ];
|
||||
colors = {
|
||||
toolbar = mkColor "base00";
|
||||
toolbar_text = mkColor "base05";
|
||||
frame = mkColor "base01";
|
||||
tab_background_text = mkColor "base05";
|
||||
toolbar_field = mkColor "base02";
|
||||
toolbar_field_text = mkColor "base05";
|
||||
tab_line = mkColor "base0D";
|
||||
popup = mkColor "base00";
|
||||
popup_text = mkColor "base05";
|
||||
button_background_active = mkColor "base04";
|
||||
frame_inactive = mkColor "base00";
|
||||
icons_attention = mkColor "base0D";
|
||||
icons = mkColor "base05";
|
||||
ntp_background = mkColor "base00";
|
||||
ntp_text = mkColor "base05";
|
||||
popup_border = mkColor "base0D";
|
||||
popup_highlight_text = mkColor "base05";
|
||||
popup_highlight = mkColor "base04";
|
||||
sidebar_border = mkColor "base0D";
|
||||
sidebar_highlight_text = mkColor "base05";
|
||||
sidebar_highlight = mkColor "base0D";
|
||||
sidebar_text = mkColor "base05";
|
||||
sidebar = mkColor "base00";
|
||||
tab_background_separator = mkColor "base0D";
|
||||
tab_loading = mkColor "base05";
|
||||
tab_selected = mkColor "base00";
|
||||
tab_text = mkColor "base05";
|
||||
toolbar_bottom_separator = mkColor "base00";
|
||||
toolbar_field_border_focus = mkColor "base0D";
|
||||
toolbar_field_border = mkColor "base00";
|
||||
toolbar_field_focus = mkColor "base00";
|
||||
toolbar_field_highlight_text = mkColor "base00";
|
||||
toolbar_field_highlight = mkColor "base0D";
|
||||
toolbar_field_separator = mkColor "base0D";
|
||||
toolbar_vertical_separator = mkColor "base0D";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
@ -1,170 +1,33 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
mkTarget,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (config.stylix.inputs) firefox-gnome-theme;
|
||||
targets = [
|
||||
{
|
||||
path = "firefox";
|
||||
name = "Firefox";
|
||||
}
|
||||
{
|
||||
path = "librewolf";
|
||||
name = "LibreWolf";
|
||||
}
|
||||
{
|
||||
path = "floorp";
|
||||
name = "Floorp";
|
||||
}
|
||||
];
|
||||
eachConfig = mkCfg: targets: lib.mkMerge (map mkCfg targets);
|
||||
eachTarget =
|
||||
mkCfg:
|
||||
lib.mkIf config.stylix.enable (
|
||||
eachConfig (
|
||||
target:
|
||||
let
|
||||
cfg = config.stylix.targets.${target.path};
|
||||
programCfg = config.programs.${target.path};
|
||||
in
|
||||
lib.mkIf cfg.enable (mkCfg {
|
||||
inherit target cfg programCfg;
|
||||
})
|
||||
) targets
|
||||
);
|
||||
mkColor =
|
||||
color:
|
||||
let
|
||||
inherit (config.lib.stylix) colors;
|
||||
in
|
||||
{
|
||||
r = colors."${color}-rgb-r";
|
||||
g = colors."${color}-rgb-g";
|
||||
b = colors."${color}-rgb-b";
|
||||
};
|
||||
nur =
|
||||
config.stylix.inputs.nur.legacyPackages.${pkgs.stdenv.hostPlatform.system};
|
||||
in
|
||||
{
|
||||
options.stylix.targets = lib.listToAttrs (
|
||||
map (
|
||||
target:
|
||||
lib.nameValuePair target.path {
|
||||
enable = config.lib.stylix.mkEnableTarget target.name true;
|
||||
|
||||
profileNames = lib.mkOption {
|
||||
description = "The ${target.name} profile names to apply styling on.";
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
colorTheme.enable = lib.mkEnableOption "[Firefox Color](https://color.firefox.com/) on ${target.name}";
|
||||
|
||||
firefoxGnomeTheme.enable = lib.mkEnableOption "[Firefox GNOME theme](https://github.com/rafaelmardojai/firefox-gnome-theme) on ${target.name}";
|
||||
}
|
||||
) targets
|
||||
);
|
||||
|
||||
# This and the below assignment aren't merged because of
|
||||
# https://discourse.nixos.org/t/infinite-recursion-in-module-with-mkmerge/10989
|
||||
config = {
|
||||
programs = eachTarget (
|
||||
{ target, cfg, ... }:
|
||||
eachConfig (profileName: {
|
||||
${target.path}.profiles.${profileName} = lib.mkMerge [
|
||||
{
|
||||
settings = {
|
||||
"font.name.monospace.x-western" = config.stylix.fonts.monospace.name;
|
||||
"font.name.sans-serif.x-western" = config.stylix.fonts.sansSerif.name;
|
||||
"font.name.serif.x-western" = config.stylix.fonts.serif.name;
|
||||
};
|
||||
}
|
||||
(lib.mkIf cfg.firefoxGnomeTheme.enable {
|
||||
settings = {
|
||||
"toolkit.legacyUserProfileCustomizations.stylesheets" = true;
|
||||
"svg.context-properties.content.enabled" = true;
|
||||
};
|
||||
|
||||
userChrome =
|
||||
let
|
||||
template = config.lib.stylix.colors {
|
||||
template = ./userChrome.css.mustache;
|
||||
extension = ".css";
|
||||
};
|
||||
in
|
||||
''
|
||||
@import "${firefox-gnome-theme}/userChrome.css";
|
||||
@import "${template}";
|
||||
'';
|
||||
|
||||
userContent = ''
|
||||
@import "${firefox-gnome-theme}/userContent.css";
|
||||
'';
|
||||
})
|
||||
(lib.mkIf cfg.colorTheme.enable {
|
||||
extensions = {
|
||||
packages = [ nur.repos.rycee.firefox-addons.firefox-color ];
|
||||
settings."FirefoxColor@mozilla.com".settings = {
|
||||
firstRunDone = true;
|
||||
theme = {
|
||||
title = "Stylix ${config.lib.stylix.colors.description}";
|
||||
images.additional_backgrounds = [ "./bg-000.svg" ];
|
||||
colors = {
|
||||
toolbar = mkColor "base00";
|
||||
toolbar_text = mkColor "base05";
|
||||
frame = mkColor "base01";
|
||||
tab_background_text = mkColor "base05";
|
||||
toolbar_field = mkColor "base02";
|
||||
toolbar_field_text = mkColor "base05";
|
||||
tab_line = mkColor "base0D";
|
||||
popup = mkColor "base00";
|
||||
popup_text = mkColor "base05";
|
||||
button_background_active = mkColor "base04";
|
||||
frame_inactive = mkColor "base00";
|
||||
icons_attention = mkColor "base0D";
|
||||
icons = mkColor "base05";
|
||||
ntp_background = mkColor "base00";
|
||||
ntp_text = mkColor "base05";
|
||||
popup_border = mkColor "base0D";
|
||||
popup_highlight_text = mkColor "base05";
|
||||
popup_highlight = mkColor "base04";
|
||||
sidebar_border = mkColor "base0D";
|
||||
sidebar_highlight_text = mkColor "base05";
|
||||
sidebar_highlight = mkColor "base0D";
|
||||
sidebar_text = mkColor "base05";
|
||||
sidebar = mkColor "base00";
|
||||
tab_background_separator = mkColor "base0D";
|
||||
tab_loading = mkColor "base05";
|
||||
tab_selected = mkColor "base00";
|
||||
tab_text = mkColor "base05";
|
||||
toolbar_bottom_separator = mkColor "base00";
|
||||
toolbar_field_border_focus = mkColor "base0D";
|
||||
toolbar_field_border = mkColor "base00";
|
||||
toolbar_field_focus = mkColor "base00";
|
||||
toolbar_field_highlight_text = mkColor "base00";
|
||||
toolbar_field_highlight = mkColor "base0D";
|
||||
toolbar_field_separator = mkColor "base0D";
|
||||
toolbar_vertical_separator = mkColor "base0D";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}) cfg.profileNames
|
||||
);
|
||||
warnings = eachTarget (
|
||||
{ target, ... }:
|
||||
lib.optional
|
||||
(
|
||||
config.programs.${target.path}.enable
|
||||
&& config.stylix.targets.${target.path}.profileNames == [ ]
|
||||
)
|
||||
''stylix: ${target.path}: `config.stylix.targets.${target.path}.profileNames` is not set. Declare profile names with 'config.stylix.targets.${target.path}.profileNames = [ "<PROFILE_NAME>" ];'.''
|
||||
);
|
||||
};
|
||||
imports =
|
||||
map
|
||||
(
|
||||
{ name, humanName }:
|
||||
lib.modules.importApply ./each-config.nix {
|
||||
inherit
|
||||
mkTarget
|
||||
name
|
||||
humanName
|
||||
;
|
||||
}
|
||||
)
|
||||
[
|
||||
{
|
||||
name = "firefox";
|
||||
humanName = "Firefox";
|
||||
}
|
||||
{
|
||||
name = "librewolf";
|
||||
humanName = "LibreWolf";
|
||||
}
|
||||
{
|
||||
name = "floorp";
|
||||
humanName = "Floorp";
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue