diff --git a/themes/engine/plymouth.nix b/themes/engine/plymouth.nix index 8d72a62..3ed8b6e 100644 --- a/themes/engine/plymouth.nix +++ b/themes/engine/plymouth.nix @@ -1,6 +1,37 @@ { 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.0–1.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"; @@ -10,8 +41,21 @@ let 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 + 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 diff --git a/themes/engine/plymouth/nomarchy.plymouth b/themes/engine/plymouth/nomarchy.plymouth index c082755..4ade91c 100644 --- a/themes/engine/plymouth/nomarchy.plymouth +++ b/themes/engine/plymouth/nomarchy.plymouth @@ -6,6 +6,6 @@ ModuleName=script [script] ImageDir=/usr/share/plymouth/themes/nomarchy ScriptFile=/usr/share/plymouth/themes/nomarchy/nomarchy.script -ConsoleLogBackgroundColor=0x1a1b26 +ConsoleLogBackgroundColor=0x@BG_HEX@ MonospaceFont=Cantarell 11 Font=Cantarell 11 diff --git a/themes/engine/plymouth/nomarchy.script b/themes/engine/plymouth/nomarchy.script index d012882..216dac9 100644 --- a/themes/engine/plymouth/nomarchy.script +++ b/themes/engine/plymouth/nomarchy.script @@ -1,7 +1,7 @@ # Nomarchy Plymouth Theme Script -Window.SetBackgroundTopColor(0.101, 0.105, 0.149); -Window.SetBackgroundBottomColor(0.101, 0.105, 0.149); +Window.SetBackgroundTopColor(@BG_R@, @BG_G@, @BG_B@); +Window.SetBackgroundBottomColor(@BG_R@, @BG_G@, @BG_B@); logo.image = Image("logo.png");