Enable overriding part of theme (#41)

This commit is contained in:
Luc Chabassier 2023-02-25 16:22:00 +01:00 committed by GitHub
parent 02a1a02386
commit 75ae5f52e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -189,6 +189,18 @@ use:
`base16Scheme` can also accept other formats as supported by
[`mkSchemeAttrs`](https://github.com/SenchoPens/base16.nix/blob/main/DOCUMENTATION.md#mkschemeattrs).
## Overriding
For convenience, it is possible to override parts of `stylix.base16Scheme` using
`stylix.override`. Anything that
[base16.nix](https://github.com/SenchoPens/base16.nix) accepts as override is
valid.
When using both the Home Manager and NixOS modules, both the system overrides
and the user-provided one are used in the user configuration if
`stylix.base16Scheme` is not changed in the user config. If that is the case,
only the user override is used.
## Fonts
The default combination of fonts is:

View file

@ -19,6 +19,12 @@ let
slug = "stylix";
};
override =
(if cfg.base16Scheme == fromOs [ "base16Scheme" ] {}
then fromOs [ "override" ] {}
else {})
// cfg.override;
in {
# TODO link to doc on how to do instead
imports = [
@ -100,11 +106,23 @@ in {
but could be overridden manually.
'';
};
override = mkOption {
description = ''
An override that will be applied to stylix.base16Scheme when generating
lib.stylix.colors.
Takes anything that a scheme generated by base16nix can take as argument
to override.
'';
type = types.attrs;
default = {};
};
};
config = {
# This attrset can be used like a function too, see
# https://github.com/SenchoPens/base16.nix#mktheme
lib.stylix.colors = base16.mkSchemeAttrs cfg.base16Scheme;
lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override override;
};
}