Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/tuigreet/meta.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
name = "TUIgreet";
homepage = "https://github.com/apognu/tuigreet";
maintainers = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New modules must have maintainers.

description = ''
Applies Stylix colors to TUIgreet by generating an ANSI theme string at
/etc/tuigreet/stylix.theme. Ensure greetd invokes TUIgreet with a
`--theme` argument, for example:
`--theme "$(cat /etc/tuigreet/stylix.theme)"`.
'';
}
39 changes: 39 additions & 0 deletions modules/tuigreet/nixos.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
mkTarget,
pkgs,
config,
lib,
...
}:
mkTarget {
name = "tuigreet";
humanName = "TUIgreet";

# Auto-enable only when greetd is enabled and configured to run TUIgreet
autoEnable =
pkgs.stdenv.hostPlatform.isLinux
&& (config.services.greetd.enable or false)
&& lib.hasInfix "tuigreet"
(config.services.greetd.settings.default_session.command or "");
autoEnableExpr = ''
pkgs.stdenv.hostPlatform.isLinux && (config.services.greetd.enable or false)
&& lib.hasInfix "tuigreet" (config.services.greetd.settings.default_session.command or "")
'';

# Generate a complete ANSI --theme string and nudge users to wire it in
configElements = [
(
{}: let themeString = config.lib.stylix.ansi.themeStringNearest; in {environment.etc."tuigreet/stylix.theme".text = themeString + "\n";}
)
{
# Nudge users to wire the config into greetd if they are using tuigreet
warnings = let
cmd = config.services.greetd.settings.default_session.command or "";
usesTuigreet = lib.hasInfix "tuigreet" cmd;
hasTheme = lib.hasInfix "--theme" cmd;
needsConfig = usesTuigreet && !hasTheme;
in
lib.optional needsConfig "stylix: tuigreet: services.greetd.settings.default_session.command does not include a '--theme' argument";
}
];
}
170 changes: 170 additions & 0 deletions stylix/ansi.nix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a new public function for a single module?

Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
lib,
config,
...
}: {
# ANSI helpers (nearest-color mapping) and scheme-sensitive theme string
config.lib.stylix.ansi = let
# Default component mapping (Base16 -> semantic UI elements)
defaultComponents = {
text = "base05";
time = "base0C";
container = "base00";
border = "base03";
title = "base0E";
greet = "base0C";
prompt = "base0B";
input = "base0D";
action = "base0D";
button = "base0A";
};

# Scheme-sensitive nearest ANSI mapping
# Reference RGB for ANSI names (0..255)
ansiRGB = {
black = {
r = 0;
g = 0;
b = 0;
};
red = {
r = 205;
g = 0;
b = 0;
};
green = {
r = 0;
g = 205;
b = 0;
};
yellow = {
r = 205;
g = 205;
b = 0;
};
blue = {
r = 0;
g = 0;
b = 205;
};
magenta = {
r = 205;
g = 0;
b = 205;
};
cyan = {
r = 0;
g = 205;
b = 205;
};
white = {
r = 229;
g = 229;
b = 229;
};

# Bright variants (standard 16-color set)
"bright-black" = {
r = 102;
g = 102;
b = 102;
};
"bright-red" = {
r = 255;
g = 0;
b = 0;
};
"bright-green" = {
r = 0;
g = 255;
b = 0;
};
"bright-yellow" = {
r = 255;
g = 255;
b = 0;
};
"bright-blue" = {
r = 0;
g = 0;
b = 255;
};
"bright-magenta" = {
r = 255;
g = 0;
b = 255;
};
"bright-cyan" = {
r = 0;
g = 255;
b = 255;
};
"bright-white" = {
r = 255;
g = 255;
b = 255;
};
};

# Access Base16 RGB components from the current scheme and convert to ints
getRgb = name: comp: lib.toInt (config.lib.stylix.colors."${name}-rgb-${comp}");
rgbOfBase = name: {
r = getRgb name "r";
g = getRgb name "g";
b = getRgb name "b";
};
dist2 = a: b: let
dr = a.r - b.r;
dg = a.g - b.g;
db = a.b - b.b;
in
dr * dr + dg * dg + db * db;
nearestNameFor = baseName: let
c = rgbOfBase baseName;
keys = builtins.attrNames ansiRGB;
scored =
map (k: {
name = k;
d = dist2 c ansiRGB.${k};
})
keys;
sorted = lib.sort (a: b: a.d < b.d) scored;
in
(builtins.head sorted).name;

# Build a theme map and string using nearest ANSI for each component's Base16
themeMapNearest = let
comps = defaultComponents;
in {
text = nearestNameFor comps.text;
time = nearestNameFor comps.time;
container = nearestNameFor comps.container;
border = nearestNameFor comps.border;
title = nearestNameFor comps.title;
greet = nearestNameFor comps.greet;
prompt = nearestNameFor comps.prompt;
input = nearestNameFor comps.input;
action = nearestNameFor comps.action;
button = nearestNameFor comps.button;
};

themeStringNearest =
lib.concatStringsSep ";"
(map (
k: "${k}=" + (builtins.getAttr k themeMapNearest)
) [
"text"
"time"
"container"
"border"
"title"
"greet"
"prompt"
"input"
"action"
"button"
]);
in {
inherit defaultComponents themeMapNearest themeStringNearest;
};
}
1 change: 1 addition & 0 deletions stylix/hm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let
in
{
imports = [
../ansi.nix
./cursor.nix
./icons.nix
./palette.nix
Expand Down
1 change: 1 addition & 0 deletions stylix/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let
in
{
imports = [
../ansi.nix
./cursor.nix
./palette.nix
../cursor.nix
Expand Down
Loading