stylix: restrict access to config while using mkTarget (#1368)

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

Reviewed-by: Flameopathic <64027365+Flameopathic@users.noreply.github.com>
Reviewed-by: Matt Sturgeon <matt@sturgeon.me.uk>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
awwpotato 2025-07-04 10:08:21 -07:00 committed by GitHub
parent 85d84607b2
commit dea0337e0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 33 deletions

View file

@ -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 = [
(

View file

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

View file

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

View file

@ -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
@ -273,8 +275,5 @@ let
};
in
{
imports = [
{ options.stylix.targets.${name} = extraOptions; }
module
];
imports = [ module ];
}