From 030af3e0717e32b8c0c0133d17bcba8659d2d1b2 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Mon, 10 Jun 2024 20:33:08 +0100 Subject: [PATCH 1/5] stylix: remove `cfg.enable` from `mkEnableTarget` default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The global `stylix.enable` option is not relevant to the per-target `enable` option's default. The individual modules should already be gated behind `stylix.enable`, so there is no need for it to also affect the value of `stylix.targets.«name».enable`. This should not produce any change in behavior for correctly written modules. --- To give a concrete example: ```nix { stylix.enable = false; stylix.autoEnable = true; stylix.targets.foo.enable = true; } ``` Here, the `stylix.enable` option is set to `false`, so no targets should be enabled, regardless of their per-target `enable` option's value. However if the `foo` target assumes it only needs to read its own `enable` option, in this example it would define its config even though Stylix is disabled globally. --- stylix/target.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stylix/target.nix b/stylix/target.nix index 12b8494b3..1074acb3d 100644 --- a/stylix/target.nix +++ b/stylix/target.nix @@ -40,7 +40,7 @@ humanName: autoEnable: lib.mkEnableOption "theming for ${humanName}" // { - default = cfg.enable && cfg.autoEnable && autoEnable; + default = cfg.autoEnable && autoEnable; example = !autoEnable; } // lib.optionalAttrs autoEnable { From 94e68af4a4a05ffcc773fff09c6387e2934e2352 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 11 May 2025 22:04:05 +0100 Subject: [PATCH 2/5] doc: note modules must check `stylix.enable` Added a note to the docs to clarify that a target module must always check the global `stylix.enable`, in addition to its own `enable` option. --- docs/src/modules.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/src/modules.md b/docs/src/modules.md index ab80668a8..98365e2e8 100644 --- a/docs/src/modules.md +++ b/docs/src/modules.md @@ -58,6 +58,13 @@ A general format for modules is shown below. } ``` +> [!CAUTION] +> You **must** check _both_ `config.stylix.enable` _and_ your target's own +> `enable` option before defining any config. +> +> In the above example this is done using +> `config = lib.mkIf (config.stylix.enable && config.stylix.targets.«name».enable)`. + The human readable name will be inserted into the following sentence: > Whether to enable theming for «human readable name». From d419d335c011960d60b70d3687348efc5bd718e2 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 11 May 2025 22:21:05 +0100 Subject: [PATCH 3/5] gtk: check `stylix.enable` All targets should check the global `enable` option, not just their own. --- modules/gtk/hm.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gtk/hm.nix b/modules/gtk/hm.nix index 48774d541..dfb63c1a0 100644 --- a/modules/gtk/hm.nix +++ b/modules/gtk/hm.nix @@ -38,7 +38,7 @@ in flatpakSupport.enable = config.lib.stylix.mkEnableTarget "support for theming Flatpak apps" true; }; - config = lib.mkIf cfg.enable ( + config = lib.mkIf (config.stylix.enable && cfg.enable) ( lib.mkMerge [ { warnings = From 7051eb4db14d9aa827b6ba4070fe465e5d987879 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 11 May 2025 22:21:05 +0100 Subject: [PATCH 4/5] kitty: check `stylix.enable` All targets should check the global `enable` option, not just their own. --- modules/kitty/hm.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/kitty/hm.nix b/modules/kitty/hm.nix index 72594ae55..2c2ed99b1 100644 --- a/modules/kitty/hm.nix +++ b/modules/kitty/hm.nix @@ -21,7 +21,7 @@ in }; }; - config = lib.mkIf cfg.enable { + config = lib.mkIf (config.stylix.enable && cfg.enable) { programs.kitty = { font = { inherit (config.stylix.fonts.monospace) package name; From 69303679a4e33a407f3fa36fa9b9585d917f2bf8 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 11 May 2025 22:21:05 +0100 Subject: [PATCH 5/5] kubecolor: check `stylix.enable` All targets should check the global `enable` option, not just their own. --- modules/kubecolor/hm.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/kubecolor/hm.nix b/modules/kubecolor/hm.nix index 8a3061306..64d878fa5 100644 --- a/modules/kubecolor/hm.nix +++ b/modules/kubecolor/hm.nix @@ -1,9 +1,12 @@ { config, lib, ... }: +let + cfg = config.stylix.targets.kubecolor; +in { options.stylix.targets.kubecolor.enable = config.lib.stylix.mkEnableTarget "kubecolor" true; - config = lib.mkIf config.stylix.targets.kubecolor.enable { + config = lib.mkIf (config.stylix.enable && cfg.enable) { programs.kubecolor.settings = { preset = if config.stylix.polarity == "either" then "" else "${config.stylix.polarity}";