stylix: add config.lib.stylix.{mkHexColor,mkOpacityHexColor} functions (#1274)

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

Approved-by: awwpotato <awwpotato@voidq.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
NAHO 2025-09-08 21:33:25 +02:00 committed by GitHub
commit 834a743c11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 5 deletions

View file

@ -182,6 +182,15 @@ individually.
Also note that reading generated files with `builtins.readFile` can be very slow
and should be avoided.
### Hexadecimal colors
- config.lib.stylix.mkHexColor`: Converts a hex `color` (e.g., `RRGGBB` or
`#RRGGBB`) to `0xRRGGBB`.
- `config.lib.stylix.mkOpacityHexColor`: Converts a hex `color` and `opacity`
(01) to `0xRRGGBBAA`.
## How to apply other things
For everything else, like fonts and wallpapers, you can just take option values

View file

@ -6,14 +6,14 @@
config = lib.mkIf (config.stylix.enable && config.stylix.targets.river.enable) {
wayland.windowManager.river.settings =
let
inherit (config.lib.stylix) colors;
inherit (config.lib.stylix) colors mkHexColor;
inherit (config.stylix) cursor;
in
{
border-color-focused = "0x${colors.base0D}";
border-color-unfocused = "0x${colors.base03}";
border-color-urgent = "0x${colors.base08}";
background-color = "0x${colors.base00}";
border-color-focused = mkHexColor colors.base0D;
border-color-unfocused = mkHexColor colors.base03;
border-color-urgent = mkHexColor colors.base08;
background-color = mkHexColor colors.base00;
xcursor-theme = lib.mkIf (
config.stylix.cursor != null
) "${cursor.name} ${toString cursor.size}";

16
stylix/colors.nix Normal file
View file

@ -0,0 +1,16 @@
{ lib, ... }:
{
config.lib.stylix = {
mkHexColor = color: "0x${lib.removePrefix "#" color}";
mkOpacityHexColor =
let
opacityHex =
percentage:
lib.throwIfNot (percentage >= 0 && percentage <= 1)
"value must be between 0 and 1 (inclusive): ${toString percentage}"
(lib.toHexString (builtins.floor (percentage * 255 + 0.5)));
in
color: opacity: "0x${opacityHex opacity}${lib.removePrefix "#" color}";
};
}

View file

@ -9,6 +9,7 @@ in
{
imports = [
./palette.nix
../colors.nix
../fonts.nix
../home-manager-integration.nix
../opacity.nix

View file

@ -6,6 +6,7 @@ in
imports = [
./fonts.nix
./palette.nix
../colors.nix
../fonts.nix
../home-manager-integration.nix
../opacity.nix

View file

@ -11,6 +11,7 @@ in
./cursor.nix
./icons.nix
./palette.nix
../colors.nix
../cursor.nix
../fonts.nix
../icons.nix

View file

@ -10,6 +10,7 @@ in
imports = [
./cursor.nix
./palette.nix
../colors.nix
../cursor.nix
../fonts.nix
../home-manager-integration.nix