Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions modules/zen-browser/deprecated.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
lib,
config,
options,
...
}:
let
cfg = config.stylix.targets.zen-browser;
in
{
options.stylix.targets.zen-browser = {
enable = config.lib.stylix.mkEnableTarget "Zen Browser" true;

profileNames = lib.mkOption {
description = "The Zen Browser profile names to apply styling on.";
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "default" ];
};

enableCss = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enables userChrome and userContent css styles for the browser";
};
};

config = lib.optionalAttrs (options.programs ? zen-browser) (
lib.mkIf cfg.enable {
warnings = [
(lib.mkIf (!cfg.enable)
"stylix: zen-browser: `stylix.targets.zen-browser.enable` is deprecated, use `programs.zen-browser.profiles.<name>.stylix.enable` instead"
)
(lib.mkIf (cfg.profileNames != [ ])
"stylix: zen-browser: `stylix.targets.zen-browser.profileNames` is deprecated, use `programs.zen-browser.profiles.<name>.stylix.enable` instead"
)
(lib.mkIf (!cfg.enableCss)
"stylix: zen-browser: `stylix.targets.zen-browser.enableCss` is deprecated, use `programs.zen-browser.profiles.<name>.stylix.enableCss` instead"
)
];

programs.zen-browser.profiles = lib.genAttrs cfg.profileNames (_: {
stylix = { inherit (cfg) enable enableCss; };
});
}
);
}
65 changes: 11 additions & 54 deletions modules/zen-browser/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,19 @@
mkTarget,
lib,
config,
options,
...
}:
mkTarget {
options = {
profileNames = lib.mkOption {
description = "The Zen Browser profile names to apply styling on.";
type = lib.types.listOf lib.types.str;

default = [ ];
example = [ "default" ];
};
{
imports = [ ./deprecated.nix ];

enableCss = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enables userChrome and userContent css styles for the browser";
};
options.programs.zen-browser.profiles = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule (
lib.modules.importApply ./pre-profile.nix {
inherit mkTarget;
stylixLib = config.lib.stylix;
}
)
);
};

config = lib.optionals (options.programs ? zen-browser) [
(
{ cfg }:
{
warnings =
lib.optional (config.programs.zen-browser.enable && cfg.profileNames == [ ])
''stylix: zen-browser: `config.stylix.targets.zen-browser.profileNames` is not set. Declare profile names with 'config.stylix.targets.zen-browser.profileNames = [ "<PROFILE_NAME>" ];'.'';
}
)
(
{ cfg, fonts }:
{
programs.zen-browser.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 }:
{
programs.zen-browser.profiles = lib.mkIf cfg.enableCss (
lib.genAttrs cfg.profileNames (_: {
settings = {
"toolkit.legacyUserProfileCustomizations.stylesheets" = true;
};

userChrome = import ./userChrome.nix { inherit colors; };

userContent = import ./userContent.nix { inherit colors; };
})
);
}
)
];
}
37 changes: 37 additions & 0 deletions modules/zen-browser/pre-profile.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ mkTarget, stylixLib }:
{ lib, ... }:
mkTarget {
submodule = true;
inherit stylixLib;

options.enableCss = lib.mkOption {
type = lib.types.bool;
default = true;
description = "enables userChrome and userContent css styles for the browser";
};

config = [
(
{ fonts }:
{
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 }:
lib.mkIf cfg.enableCss {
settings = {
"toolkit.legacyUserProfileCustomizations.stylesheets" = true;
};

userChrome = import ./userChrome.nix { inherit colors; };

userContent = import ./userContent.nix { inherit colors; };
}
)
];
}
22 changes: 22 additions & 0 deletions modules/zen-browser/testbeds/zen-browser-deprecated.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ lib, ... }:
let
profileName = "stylix";
in
{
stylix.testbed.ui.command.text = "zen";

home-manager.sharedModules = lib.singleton {
programs.zen-browser = {
enable = true;
profiles.${profileName} = {
isDefault = true;
settings = {
"app.normandy.first_run" = false;
"zen.welcome-screen.seen" = true;
};
};
};

stylix.targets.zen-browser.profileNames = [ profileName ];
};
}
2 changes: 0 additions & 2 deletions modules/zen-browser/testbeds/zen-browser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ in
};
};
};

stylix.targets.zen-browser.profileNames = [ profileName ];
};
}
142 changes: 81 additions & 61 deletions stylix/mk-target.nix
Comment thread
trueNAHO marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
automatic safeguarding and should only be used for complex configurations
where `config` is unsuitable.

`submodule` (Boolean)
: When true options will be added at `options.stylix` instead of
`options.stylix.targets.<name>`. Useful when using stylix inside of a submodule.

`stylixLib` (Attrs of functions)
: Defaults to `config.lib.stylix`. Useful when `config.lib.stylix` doesn't
exist, for example inside a submodule.

# Environment

The function is provided alongside module arguments in any modules imported
Expand Down Expand Up @@ -183,13 +191,17 @@ in
name ? name',
options ? [ ],
unconditionalConfig ? { },
submodule ? false,
stylixLib ? null,
}@args:
let
mkTargetConfig = config;

module =
{ config, lib, ... }:
let
stylixLib' = if stylixLib != null then stylixLib else config.lib.stylix;

callModule =
let
areArgumentsEnabled = lib.flip lib.pipe [
Expand Down Expand Up @@ -220,7 +232,7 @@ let
lib.generators.toPretty { } config'
}";

cfg = config.stylix.targets.${name};
cfg = if submodule then config.stylix else config.stylix.targets.${name};

getArguments =
function:
Expand Down Expand Up @@ -251,7 +263,7 @@ let
)
(
if argument == "colors" then
config.lib.stylix.colors
stylixLib'.colors

else
config.stylix.${argument} or (throw "stylix: mkTarget expected one of ${
Expand All @@ -277,68 +289,76 @@ let

normalizedConfig = normalize mkTargetConfig;
normalizedOptions = normalize options;

options' = lib.foldl lib.attrsets.unionOfDisjoint { } (
(map (option: callModule false option) normalizedOptions)
++ [
{
enable =
let
enableArgs = {
name = humanName;
}
// lib.optionalAttrs (args ? autoEnable) { inherit autoEnable; }
// lib.optionalAttrs (args ? autoEnableExpr) { inherit autoEnableExpr; }
// lib.optionalAttrs (args ? autoWrapEnableExpr) {
autoWrapExpr = autoWrapEnableExpr;
}
// lib.optionalAttrs (args ? enableExample) { example = enableExample; };
in
stylixLib'.mkEnableTargetWith enableArgs;
}
(lib.genAttrs
(lib.concatLists (
map (lib.flip lib.pipe [
(
config': lib.optionalAttrs (builtins.isFunction config') (getArguments config')
)
builtins.attrNames
(lib.remove "cfg")
]) (normalizedConfig ++ normalizedOptions)
))
(
argument:
let
config = "`${
if argument == "colors" then
"config.lib.stylix.colors"
else
"config.stylix.${argument}"
}`";
in
{
enable = lib.mkEnableOption "${config} for ${humanName}" // {
default = true;
example = false;
};

override = lib.mkOption {
default = null;

description = ''
Attribute sets are recursively merged with ${config},
while all other non-`null` types override ${config}.
'';

type = lib.types.anything;
};
}
)
)
]
);
in
{
imports =
lib.singleton {
options.stylix.targets.${name} =
lib.genAttrs
(lib.concatLists (
map (lib.flip lib.pipe [
(
config': lib.optionalAttrs (builtins.isFunction config') (getArguments config')
)
builtins.attrNames
(lib.remove "cfg")
]) (normalizedConfig ++ normalizedOptions)
))
(
argument:
let
config = "`${
if argument == "colors" then
"config.lib.stylix.colors"
else
"config.stylix.${argument}"
}`";
in
{
enable = lib.mkEnableOption "${config} for ${humanName}" // {
default = true;
example = false;
};

override = lib.mkOption {
default = null;

description = ''
Attribute sets are recursively merged with ${config},
while all other non-`null` types override ${config}.
'';

type = lib.types.anything;
};
}
);
}
++ imports
++ map (option: {
options.stylix.targets.${name} = callModule false option;
}) normalizedOptions;

options.stylix.targets.${name}.enable =
let
enableArgs = {
name = humanName;
}
// lib.optionalAttrs (args ? autoEnable) { inherit autoEnable; }
// lib.optionalAttrs (args ? autoEnableExpr) { inherit autoEnableExpr; }
// lib.optionalAttrs (args ? autoWrapEnableExpr) {
autoWrapExpr = autoWrapEnableExpr;
}
// lib.optionalAttrs (args ? enableExample) { example = enableExample; };
in
config.lib.stylix.mkEnableTargetWith enableArgs;
imports
++ lib.singleton (
if submodule then
{ options.stylix = options'; }
else
{ options.stylix.targets.${name} = options'; }
);

config = lib.mkIf (config.stylix.enable && cfg.enable) (
lib.mkMerge (
Expand Down
Loading