Files
Nomarchy/themes/engine/plymouth.nix
Bernardo Magri 474bc16eb3 feat(plymouth): boot splash background follows the active palette
themes/engine/plymouth/nomarchy.script had
`Window.SetBackgroundTopColor(0.101, 0.105, 0.149)` hardcoded — a
Tokyo-Night-ish #1a1b26 — and nomarchy.plymouth had a matching
`ConsoleLogBackgroundColor=0x1a1b26`. Both were frozen regardless of
the active nomarchy.system.theme.

Replaced the literals with placeholders (@BG_R@, @BG_G@, @BG_B@,
@BG_HEX@) in the source files. themes/engine/plymouth.nix now reads
the active palette via `nomarchyLib.getPalette
config.nomarchy.system.theme`, converts palette.base00 into three
0.0–1.0 floats (Nix has no floating-point math, so `(byte * 1000) /
255` integer division formatted as `0.XXX`), and `sed`-substitutes
both files during installPhase.

Smoke-built the derivation against the default summer-night palette:

  $ cat .../nomarchy.script | grep BackgroundTopColor
  Window.SetBackgroundTopColor(0.176, 0.207, 0.231);
  $ cat .../nomarchy.plymouth | grep ConsoleLogBackgroundColor
  ConsoleLogBackgroundColor=0x2d353b

Both match the expected byte→float conversion from base00=2d353b.

Closes the "Plymouth theme variants per palette" Next-column item.
`nix flake check --no-build` clean.
2026-05-22 19:27:04 +01:00

75 lines
2.7 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{ config, pkgs, lib, ... }:
let
nomarchyLib = import ../../lib { inherit lib; };
palette = nomarchyLib.getPalette config.nomarchy.system.theme;
# Plymouth's Window.SetBackgroundTopColor takes three floats in 0.01.0;
# the .plymouth metadata's ConsoleLogBackgroundColor takes a 0xRRGGBB
# hex. Compute both from palette.base00 so the boot splash matches the
# rest of the active theme instead of staying frozen on the hardcoded
# Tokyo-Night-ish #1a1b26 it used to ship with.
hex = palette.base00;
rByte = lib.fromHexString (lib.substring 0 2 hex);
gByte = lib.fromHexString (lib.substring 2 2 hex);
bByte = lib.fromHexString (lib.substring 4 2 hex);
# byte → "0.XXX" decimal string. Nix has no floating-point math, so
# multiply first, integer-divide, then format. Plymouth tolerates more
# decimals than this (0.1019 etc.) but three digits matches the visual
# precision Plymouth renders at and keeps the substitution readable.
byteToFloat = n:
let
thousandths = (n * 1000) / 255;
s = toString thousandths;
padded =
if lib.stringLength s == 1 then "00${s}"
else if lib.stringLength s == 2 then "0${s}"
else s;
in "0.${padded}";
bgR = byteToFloat rByte;
bgG = byteToFloat gByte;
bgB = byteToFloat bByte;
nomarchy-plymouth = pkgs.stdenv.mkDerivation {
pname = "nomarchy-plymouth";
version = "1.0";
src = ./plymouth;
installPhase = ''
mkdir -p $out/share/plymouth/themes/nomarchy
cp * $out/share/plymouth/themes/nomarchy/
# Fix path in the plymouth file to point to the nix store
sed -i "s|/[a-z]*/share/plymouth/themes/nomarchy|$out/share/plymouth/themes/nomarchy|g" \
$out/share/plymouth/themes/nomarchy/nomarchy.plymouth
# Substitute the active theme's base00 in both the .script (RGB
# floats for the Window.SetBackground* calls) and the .plymouth
# metadata (0xRRGGBB for ConsoleLogBackgroundColor).
sed -i \
-e 's|@BG_R@|${bgR}|g' \
-e 's|@BG_G@|${bgG}|g' \
-e 's|@BG_B@|${bgB}|g' \
$out/share/plymouth/themes/nomarchy/nomarchy.script
sed -i 's|@BG_HEX@|${hex}|g' \
$out/share/plymouth/themes/nomarchy/nomarchy.plymouth
'';
};
in
{
boot.initrd.systemd.enable = lib.mkDefault true;
boot.initrd.verbose = lib.mkDefault false;
console.earlySetup = lib.mkDefault true;
boot.consoleLogLevel = lib.mkDefault 0;
boot.plymouth = {
enable = lib.mkDefault true;
themePackages = lib.mkDefault [ nomarchy-plymouth ];
theme = lib.mkDefault "nomarchy";
};
boot.kernelParams = lib.mkDefault [ "quiet" "splash" "loglevel=3" "rd.systemd.show_status=false" "rd.udev.log_level=3" "udev.log_priority=3" "boot.shell_on_fail" ];
}