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

nixos/plymouth: Add label plugin and a font to the initrd #99011

Merged
merged 1 commit into from Feb 21, 2021

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Sep 28, 2020

Motivation for this change

This allows Plymouth to show the “NixOS 21.03” label under the logo at startup like it already does at shutdown.

Fixes #59992.

Increases the compressed initrd size by about 5 MB when Plymouth is enabled, since /etc/plymouth/plugins/label.so depends on rather more libraries than you’d like. Maybe this is fine since Plymouth is opt-in. We might be able to trim this by using a copy of Cairo compiled against fewer backends? A more minimal version of the label plugin was proposed at https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/45.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@michaelpj
Copy link
Contributor

Nice! This has been bugging me for literally years.

I wonder if the font should be controlled by some option. What determines the font that gets used during shutdown? Should we try and make sure it's the same one?

@worldofpeace
Copy link
Contributor

I'd be fine with using the label-ft patches in plymouth, however... there is a PR that fixes this and overhauls a lot of plymouth #84158. But the issue with it is it aspires to do slightly too much in one PR (mostly the commonFunction pieces breaking things)

I'm planning on fixing up that PR and then subsequently defaulting to the bgrt theme. Flicker free boot is blocked on #74842 and that is a long ways to being ready.

@worldofpeace
Copy link
Contributor

I am however interested in why 3128d14 is different from what you have...

@worldofpeace worldofpeace self-assigned this Feb 21, 2021
@andersk
Copy link
Contributor Author

andersk commented Feb 21, 2021

The difference is that this PR uses the upstream label plugin, while 3128d14 (#84158) uses the label-ft plugin via a patch (6502fff) that’s still not merged upstream (https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/45). Plus side for label-ft: it uses Freetype directly, so it can get away without pulling in 5 MB of libraries and needing a fontconfig configuration. Minus side: there seems to have been no upstream activity toward merging that for 4 years.

@worldofpeace
Copy link
Contributor

@jtojnar Does your reservation on using those patches still stand from #84158 (comment) with this in context? If so, I'd defer to that decision and merge this with a font option

@jtojnar
Copy link
Contributor

jtojnar commented Feb 21, 2021

5 MB increase does not sound that bad to me so I would still prefer the upstream label solution over unmerged patches. But initrd maintainers will have final say. We can try to slim down cairo as suggested above it they see it as a problem.

Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

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

I actually compared this to my intrd and then a the size increase... not really something to be overly concerned about. It's off by default too.
If we can add a font option like that other plymouth PR I'd merge.

This allows Plymouth to show the “NixOS 21.03” label under the logo at
startup like it already does at shutdown.

Fixes NixOS#59992.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@andersk
Copy link
Contributor Author

andersk commented Feb 21, 2021

Okay, I added an option for the font file.

It’s a little weird in that the theme actually decides which font to request from Fontconfig, and this option only affects which font file is made available to Fontconfig during boot to satisfy this request. During shutdown, the normal system Fontconfig configuration and fonts are used.

I set the default as DejaVu Sans because it has the privileged position of being our Fontconfig fallback font:

"--with-default-fonts=${dejavu_fonts.minimal}"

If the user adds noto-fonts to config.fonts.fonts, they’ll actually get Noto Sans during shutdown because that’s what our default breeze theme specifies. Those users can configure boot.plymouth.font = "${pkgs.noto-fonts}/share/fonts/truetype/noto/NotoSans-Regular.ttf" for a matching font during boot.

@@ -38,6 +38,14 @@ in

enable = mkEnableOption "Plymouth boot splash screen";

font = mkOption {
default = "${pkgs.dejavu_fonts.minimal}/share/fonts/truetype/DejaVuSans.ttf";
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice to be able to figure what font is the default sans font for a system. this is just a comment and not a suggestion, but I feel it would be pretty boring to do this with passthru listing all the paths to a font within a package, and making a fonts.fonts.primaryFont, and fonts having $variant.path attr.

Copy link
Contributor Author

@andersk andersk Feb 21, 2021

Choose a reason for hiding this comment

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

The relevant font here is not a system default, but one specified by the theme.

Finding the default sans font is a simple matter of running fc-match -f '%{file}' Sans in an environment with the appropriate Fontconfig configuration. Or if we could somehow pull out the value Noto Sans from the selected Plymouth theme, we could run fc-match -f '%{file}' 'Noto Sans'. Unfortunately Plymouth themes are written in a custom scripting language and I don’t see a way to evaluate them except in Plymouth itself. We could maybe write some atrocious regex that works most of the time.

Copy link
Contributor

@worldofpeace worldofpeace left a comment

Choose a reason for hiding this comment

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

I now see the nixos version at boot

@worldofpeace worldofpeace merged commit 0c3514f into NixOS:master Feb 21, 2021
@andersk andersk deleted the plymouth-label branch December 26, 2022 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plymouth shows NixOS version only at shutdown, not at start (when GRUB is used)
4 participants