From c700d41bb8ee32baed490c8128c1077b2b27183b Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Thu, 26 Jun 2025 17:11:18 +0200 Subject: [PATCH] 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 --- stylix/mk-target.nix | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stylix/mk-target.nix b/stylix/mk-target.nix index a7c557f3..64697cb8 100644 --- a/stylix/mk-target.nix +++ b/stylix/mk-target.nix @@ -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 + ) ) ); };