stylix: allow mkTarget's configuration arguments to receive paths (#1523)

Allow mkTarget's configElements and generalConfig arguments to receive
paths, streamlining the migration away from the config.lib.stylix.colors
function that depends on base16.nix [1] [2].

[1]: https://github.com/nix-community/stylix/issues/159#issuecomment-1937879216
[2]: https://github.com/nix-community/stylix/issues/249#issuecomment-2012933635

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

Reviewed-by: Flameopathic <64027365+Flameopathic@users.noreply.github.com>
Reviewed-by: awwpotato <awwpotato@voidq.com>
This commit is contained in:
NAHO 2025-06-26 17:11:18 +02:00 committed by GitHub
parent 87ec086490
commit c700d41bb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -97,7 +97,7 @@
{ extension.enable = lib.mkEnableOption "the bloated dependency"; }
```
`configElements` (List or attribute set or function)
`configElements` (List or attribute set or function or path)
: Configuration functions that are automatically safeguarded when any of
their arguments is disabled. The provided `cfg` argument conveniently
aliases to `config.stylix.targets.${name}`.
@ -130,7 +130,7 @@
Underscored arguments are considered unused and should never be accessed.
Their sole purpose is satisfying `deadnix` in complex configurations.
`generalConfig` (Attribute set or function)
`generalConfig` (Attribute set or function or path)
: This argument mirrors the `configElements` argument but intentionally
lacks automatic safeguarding and should only be used for complex
configurations where `configElements` is unsuitable.
@ -225,7 +225,7 @@ let
mkConfig = fn: fn (getStylixAttrs fn);
# Safeguard configuration functions when any of their arguments is
# disabled, while non-function configurations are unguarded.
# disabled.
mkConditionalConfig =
c:
if builtins.isFunction c then
@ -260,8 +260,14 @@ let
config = lib.mkIf (config.stylix.enable && cfg.enable) (
lib.mkMerge (
lib.optional (generalConfig != null) (mkConfig generalConfig)
++ map mkConditionalConfig (lib.toList configElements)
lib.optional (generalConfig != null) (
mkConfig (
if builtins.isPath generalConfig then import generalConfig else generalConfig
)
)
++ map (c: mkConditionalConfig (if builtins.isPath c then import c else c)) (
lib.toList configElements
)
)
);
};