Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plymouth: set custom font #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 36 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,40 @@ let
" > $themeDir/stylix.plymouth
'';

mkPlymouthFont =
danth marked this conversation as resolved.
Show resolved Hide resolved
font:
pkgs.runCommand "${font.package.name}.otf"
{ FONTCONFIG_FILE = pkgs.makeFontsConf { fontDirectories = [ font.package ]; }; }
''
if ! matchingFonts="$(
# sort because otherwise fc-match doesn't print all available formats
${lib.getExe' pkgs.fontconfig "fc-match"} \
--sort \
--format '%{family}|%{file}\n' \
'${font.name}' | \
# Filter for fonts that match the name exactly and only print the path
awk --field-separator '|' '/^${font.name}\|/ { print $2; found=1} END {if (!found) exit 1}'
)"; then
printf 'Font not found: %s' '${font.name}' >&2
exit 1
fi
echo "fonts: '$matchingFonts'" >&2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this not be echoed on every build? Should we remove this debugging statement:

Suggested change
echo "fonts: '$matchingFonts'" >&2

if compatibleFont="$(
# Take the first opentype font or fail when there is none
printf '%s\n' "$matchingFonts" |
grep --max-count 1 --regexp "\.otf$"
)"; then
cp "$compatibleFont" "$out"
else
# If there is no opentype font we take another format and convert it
font=$(printf '%s\n' "$matchingFonts" | head --lines 1)
${lib.getExe' pkgs.fontforge "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 @@ -82,5 +117,6 @@ in {
config.boot.plymouth = mkIf cfg.enable {
theme = "stylix";
themePackages = [ theme ];
font = mkPlymouthFont sansSerif;
};
}