diff --git a/stylix/palette.nix b/stylix/palette.nix index 0ae7bf47..718683f7 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -8,7 +8,7 @@ let cfg = config.stylix; - + opts = options.stylix; in { options.stylix = { @@ -117,18 +117,23 @@ in ''; type = with lib.types; - nullOr (oneOf [ + oneOf [ path lines attrs - ]); - # defaults to null when cfg.image is also null, in order to trigger the assertion below correctly - default = if cfg.image == null then null else cfg.generated.palette; + ]; + # We add an assertion here, because this value is used throughout Stylix. + # Using the assertions option is ineffective because it is checked after + # the errors caused by reading `base16Scheme` have occurred. + # See https://github.com/nix-community/stylix/pull/1408 + # and https://github.com/nix-community/stylix/pull/1446 + default = + lib.throwIf (cfg.image == null) + "stylix: one of `${opts.image}' or `${opts.base16Scheme}' must be set." + cfg.generated.palette; defaultText = lib.literalMD '' - The colors used in the theming. - - Those are automatically selected from the background image by default, - but could be overridden manually. + Automatically selected from the background image. The default will + throw if `stylix.image` is null. ''; }; @@ -167,24 +172,7 @@ in config = { # This attrset can be used like a function too, see # https://github.com/SenchoPens/base16.nix/blob/b390e87cd404e65ab4d786666351f1292e89162a/README.md#theme-step-22 - # - # NOTE: base16Scheme is nullable. If null, we cannot pass it to mkSchemeAttrs. - # See https://github.com/nix-community/stylix/pull/1408 - lib.stylix.colors = - if cfg.base16Scheme == null then - null - else - (cfg.base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override; - - assertions = lib.mkIf cfg.enable [ - { - assertion = !(cfg.image == null && cfg.base16Scheme == null); - - message = '' - stylix: one of `stylix.image` or `stylix.base16Scheme` must be set - ''; - } - ]; + lib.stylix.colors = (cfg.base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override; stylix.generated.fileTree = { # The raw output of the palette generator.