glance: init nixos module (#1187)

Link: https://github.com/danth/stylix/pull/1187

Reviewed-by: awwpotato <awwpotato@voidq.com>
Tested-by: awwpotato <awwpotato@voidq.com>
This commit is contained in:
Louis Thevenet 2025-05-02 06:04:50 +02:00 committed by GitHub
parent 87df2a1d9c
commit bc38629511
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 148 additions and 45 deletions

View file

@ -1,4 +1,7 @@
{ config, lib, ... }:
let
rgb-to-hsl = import ./rgb-to-hsl.nix { inherit lib config; };
in
{
options.stylix.targets.glance.enable =
config.lib.stylix.mkEnableTarget "Glance" true;
@ -6,50 +9,13 @@
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.glance.enable)
{
services.glance.settings.theme =
let
rgb-to-hsl =
color:
let
r = ((lib.toInt config.lib.stylix.colors."${color}-rgb-r") * 100.0) / 255;
g = ((lib.toInt config.lib.stylix.colors."${color}-rgb-g") * 100.0) / 255;
b = ((lib.toInt config.lib.stylix.colors."${color}-rgb-b") * 100.0) / 255;
max = lib.max r (lib.max g b);
min = lib.min r (lib.min g b);
delta = max - min;
fmod = base: int: base - (int * builtins.floor (base / int));
h =
if delta == 0 then
0
else if max == r then
60 * (fmod ((g - b) / delta) 6)
else if max == g then
60 * (((b - r) / delta) + 2)
else if max == b then
60 * (((r - g) / delta) + 4)
else
0;
l = (max + min) / 2;
s =
if delta == 0 then
0
else
100 * delta / (100 - lib.max (2 * l - 100) (100 - (2 * l)));
roundToString = value: toString (builtins.floor (value + 0.5));
in
lib.concatMapStringsSep " " roundToString [
h
s
l
];
in
{
light = config.stylix.polarity == "light";
contrast-multiplier = 1.0;
background-color = rgb-to-hsl "base00";
primary-color = rgb-to-hsl "base05";
positive-color = rgb-to-hsl "base01";
negative-color = rgb-to-hsl "base04";
};
services.glance.settings.theme = {
light = config.stylix.polarity == "light";
contrast-multiplier = 1.0;
background-color = rgb-to-hsl "base00";
primary-color = rgb-to-hsl "base05";
positive-color = rgb-to-hsl "base01";
negative-color = rgb-to-hsl "base04";
};
};
}

22
modules/glance/nixos.nix Normal file
View file

@ -0,0 +1,22 @@
{ config, lib, ... }:
let
rgb-to-hsl = import ./rgb-to-hsl.nix { inherit lib config; };
in
{
options.stylix.targets.glance.enable =
config.lib.stylix.mkEnableTarget "Glance" true;
config =
lib.mkIf (config.stylix.enable && config.stylix.targets.glance.enable)
{
services.glance.settings.theme = {
light = config.stylix.polarity == "light";
contrast-multiplier = 1.0;
background-color = rgb-to-hsl "base00";
primary-color = rgb-to-hsl "base05";
positive-color = rgb-to-hsl "base01";
negative-color = rgb-to-hsl "base04";
};
};
}

View file

@ -0,0 +1,34 @@
{ lib, config, ... }:
color:
let
r = ((lib.toInt config.lib.stylix.colors."${color}-rgb-r") * 100.0) / 255;
g = ((lib.toInt config.lib.stylix.colors."${color}-rgb-g") * 100.0) / 255;
b = ((lib.toInt config.lib.stylix.colors."${color}-rgb-b") * 100.0) / 255;
max = lib.max r (lib.max g b);
min = lib.min r (lib.min g b);
delta = max - min;
fmod = base: int: base - (int * builtins.floor (base / int));
h =
if delta == 0 then
0
else if max == r then
60 * (fmod ((g - b) / delta) 6)
else if max == g then
60 * (((b - r) / delta) + 2)
else if max == b then
60 * (((r - g) / delta) + 4)
else
0;
l = (max + min) / 2;
s =
if delta == 0 then
0
else
100 * delta / (100 - lib.max (2 * l - 100) (100 - (2 * l)));
roundToString = value: toString (builtins.floor (value + 0.5));
in
lib.concatMapStringsSep " " roundToString [
h
s
l
]

View file

@ -0,0 +1,81 @@
{ lib, pkgs, ... }:
let
host = "127.0.0.1";
package = pkgs.wrapFirefox pkgs.firefox-unwrapped {
extraPolicies.OverrideFirstRunPage = "http://${host}:${builtins.toString port}";
};
port = 1234;
in
{
stylix.testbed.ui.application = {
name = "firefox";
inherit package;
};
programs.firefox = {
enable = true;
inherit package;
};
services.glance = {
enable = true;
settings = {
pages = lib.singleton {
columns = [
{
size = "small";
widgets = lib.singleton {
hide-location = false;
hour-format = "24h";
location = "Tokyo, Japan";
show-area-name = true;
type = "weather";
units = "metric";
};
}
{
size = "full";
widgets = [
{
autofocus = true;
search-engine = "https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+{QUERY}";
type = "search";
}
{
type = "group";
widgets = lib.singleton {
collapse-after = 15;
feeds = lib.singleton {
title = "LessWrong";
url = "https://www.lesswrong.com/feed.xml?view=curated-rss";
};
style = "vertical-list";
type = "rss";
};
}
];
}
{
size = "small";
widgets = [ { type = "calendar"; } ];
}
];
name = "Home";
};
server = { inherit host port; };
};
};
}