Skip to content

Commit

Permalink
plymouth: set custom font
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeidnx committed Apr 12, 2024
1 parent 406f793 commit 1abbaa7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/plymouth/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

with lib;
with config.lib.stylix.colors;
with config.stylix.fonts;

let
cfg = config.stylix.targets.plymouth;
Expand Down Expand Up @@ -41,6 +42,25 @@ let
" > $themeDir/stylix.plymouth
'';

mkPlymouthFont =
font:
pkgs.runCommand "${font.package.name}.ttf"
{ FONTCONFIG_FILE = pkgs.makeFontsConf { fontDirectories = [ font.package ]; }; }
''
matchingFonts=$(${pkgs.fontconfig}/bin/fc-match -asf "%{family}|%{file}\n" "${font.name}" | grep "^${font.name}|" | cut -d'|' -f2)
if [[ -z "$matchingFonts" ]]; then
echo "No font named `$font` found."
exit 1
fi
if ttfFont=$(echo "$matchingFonts" | grep -m1 -E "\.ttf$"); then
cp "$ttfFont" "$out"
else
font=$(echo "$matchingFonts" | head -n1)
${pkgs.fontforge}/bin/fontforge -lang=ff -c 'Open($1); Generate($2); Close()' "$font" "$out"
fi
'';
in {
options.stylix.targets.plymouth = {
enable = config.lib.stylix.mkEnableTarget "the Plymouth boot screen" true;
Expand Down Expand Up @@ -88,5 +108,6 @@ in {
config.boot.plymouth = mkIf cfg.enable {
theme = "stylix";
themePackages = [ theme ];
font = mkPlymouthFont sansSerif;
};
}

0 comments on commit 1abbaa7

Please sign in to comment.