From 35c92d1a4813dd0d4a83d5273a8bbb1e90069327 Mon Sep 17 00:00:00 2001 From: awwpotato Date: Sun, 15 Jun 2025 18:00:48 -0700 Subject: [PATCH 1/2] stylix: restrict access to config while using mkTarget --- modules/bemenu/hm.nix | 41 +++++++++++++++++++---------------------- modules/hyprland/hm.nix | 26 +++++++++++++++----------- stylix/autoload.nix | 14 +++++++++++++- stylix/mk-target.nix | 9 ++++----- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/modules/bemenu/hm.nix b/modules/bemenu/hm.nix index 38fb913c3..68f1653d3 100644 --- a/modules/bemenu/hm.nix +++ b/modules/bemenu/hm.nix @@ -1,31 +1,28 @@ -{ - mkTarget, - lib, - config, - ... -}: +{ mkTarget, lib, ... }: mkTarget { name = "bemenu"; humanName = "bemenu"; - extraOptions = { - fontSize = lib.mkOption { - description = '' - Font size used for bemenu. - ''; - type = with lib.types; nullOr int; - default = config.stylix.fonts.sizes.popups; - defaultText = lib.literalExpression "config.stylix.fonts.sizes.popups"; - }; # optional argument + extraOptions = + { fonts }: + { + fontSize = lib.mkOption { + description = '' + Font size used for bemenu. + ''; + type = with lib.types; nullOr int; + default = fonts.sizes.popups; + defaultText = lib.literalExpression "config.stylix.fonts.sizes.popups"; + }; # optional argument - alternate = lib.mkOption { - description = '' - Whether to use alternating colours. - ''; - type = lib.types.bool; - default = false; + alternate = lib.mkOption { + description = '' + Whether to use alternating colours. + ''; + type = lib.types.bool; + default = false; + }; }; - }; configElements = [ ( diff --git a/modules/hyprland/hm.nix b/modules/hyprland/hm.nix index a7c624ce6..7cd746f90 100644 --- a/modules/hyprland/hm.nix +++ b/modules/hyprland/hm.nix @@ -7,11 +7,16 @@ mkTarget { name = "hyprland"; humanName = "Hyprland"; - extraOptions.hyprpaper.enable = config.lib.stylix.mkEnableTargetWith { - name = "Hyprpaper"; - autoEnable = config.stylix.image != null; - autoEnableExpr = "config.stylix.image != null"; - }; + extraOptions = + { image }: + { + hyprpaper.enable = config.lib.stylix.mkEnableTargetWith { + name = "Hyprpaper"; + autoEnable = image != null; + autoEnableExpr = "config.stylix.image != null"; + }; + }; + configElements = [ ( { colors }: @@ -44,12 +49,11 @@ mkTarget { ) ( { cfg }: - lib.mkIf (config.wayland.windowManager.hyprland.enable && cfg.hyprpaper.enable) - { - services.hyprpaper.enable = true; - stylix.targets.hyprpaper.enable = true; - wayland.windowManager.hyprland.settings.misc.disable_hyprland_logo = true; - } + lib.mkIf (config.wayland.windowManager.hyprland.enable && cfg.hyprpaper.enable) { + services.hyprpaper.enable = true; + stylix.targets.hyprpaper.enable = true; + wayland.windowManager.hyprland.settings.misc.disable_hyprland_logo = true; + } ) ]; } diff --git a/stylix/autoload.nix b/stylix/autoload.nix index 34782fbdf..16df30f9f 100644 --- a/stylix/autoload.nix +++ b/stylix/autoload.nix @@ -42,7 +42,19 @@ builtins.concatLists ( { key = file; _file = file; - imports = [ (module (args // extraArgs // { inherit mkTarget; })) ]; + imports = [ + (module ( + args + // extraArgs + // { + inherit mkTarget; + config = lib.recursiveUpdate config { + stylix = throw "stylix: unguareded `config.stylix` accessed while using mkTarget"; + lib.stylix.colors = throw "stylix: unguareded `config.lib.stylix.colors` accessed while using mkTarget"; + }; + } + )) + ]; } else file diff --git a/stylix/mk-target.nix b/stylix/mk-target.nix index a7c557f31..be6a75abe 100644 --- a/stylix/mk-target.nix +++ b/stylix/mk-target.nix @@ -241,7 +241,9 @@ let c; in { - inherit imports; + imports = imports ++ [ + { options.stylix.targets.${name} = mkConfig (lib.toFunction extraOptions); } + ]; options.stylix.targets.${name}.enable = let @@ -267,8 +269,5 @@ let }; in { - imports = [ - { options.stylix.targets.${name} = extraOptions; } - module - ]; + imports = [ module ]; } From 2b9f8d37db99a55a50ff635ab0aa0b1421a652b4 Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Wed, 25 Jun 2025 21:34:46 +0200 Subject: [PATCH 2/2] hyprland: fix formatting --- modules/hyprland/hm.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/hyprland/hm.nix b/modules/hyprland/hm.nix index 7cd746f90..119ba7973 100644 --- a/modules/hyprland/hm.nix +++ b/modules/hyprland/hm.nix @@ -49,11 +49,12 @@ mkTarget { ) ( { cfg }: - lib.mkIf (config.wayland.windowManager.hyprland.enable && cfg.hyprpaper.enable) { - services.hyprpaper.enable = true; - stylix.targets.hyprpaper.enable = true; - wayland.windowManager.hyprland.settings.misc.disable_hyprland_logo = true; - } + lib.mkIf (config.wayland.windowManager.hyprland.enable && cfg.hyprpaper.enable) + { + services.hyprpaper.enable = true; + stylix.targets.hyprpaper.enable = true; + wayland.windowManager.hyprland.settings.misc.disable_hyprland_logo = true; + } ) ]; }