Add Plymouth module

This commit is contained in:
Daniel Thwaites 2020-12-21 15:10:12 +00:00
parent 7cefd745bf
commit c8addbbf5a
No known key found for this signature in database
GPG key ID: D8AFC4BF05670F9D
3 changed files with 84 additions and 0 deletions

View file

@ -8,6 +8,7 @@
./modules/gtk.nix
./modules/kitty.nix
./modules/lightdm.nix
./modules/plymouth
./modules/qutebrowser.nix
./modules/vim.nix
];

View file

@ -0,0 +1,35 @@
{ config, pkgs, ... }:
with config.lib.stylix.colors;
let theme = pkgs.runCommandLocal "plymouth-theme" {}
''
themeDir="$out/share/plymouth/themes/stylix"
mkdir -p $themeDir
cp ${./theme.script} $themeDir/stylix.script
# Convert in case the input image is not PNG
${pkgs.imagemagick}/bin/convert ${config.stylix.image} $themeDir/background.png
# A single pixel of base0B, will be stretched to make the progress bar
# (Plymouth scripts can only display images)
${pkgs.imagemagick}/bin/convert xc:#${base0B-hex} $themeDir/progress.png
echo "
[Plymouth Theme]
Name=Stylix
ModuleName=script
[script]
ImageDir=$themeDir
ScriptFile=$themeDir/stylix.script
" > $themeDir/stylix.plymouth
'';
in {
boot.plymouth = {
theme = "stylix";
themePackages = [ theme ];
};
}

View file

@ -0,0 +1,48 @@
### BACKGROUND ###
background.original_image = Image("background.png");
background.ratio = Math.Max(
Window.GetWidth() / background.original_image.GetWidth(),
Window.GetHeight() / background.original_image.GetHeight()
);
background.image = background.original_image.Scale(
Math.Int(background.original_image.GetWidth() * background.ratio),
Math.Int(background.original_image.GetHeight() * background.ratio)
);
background.sprite = Sprite(background.image);
background.sprite.SetPosition(
Math.Int((Window.GetWidth() - background.image.GetWidth()) / 2),
Math.Int((Window.GetHeight() - background.image.GetHeight()) / 2),
0
);
### PROGRESS ###
progress_bar.width = 0;
progress_bar.height = 4;
progress_bar.original_image = Image("progress.png");
progress_bar.sprite = Sprite();
progress_bar.sprite.SetY(Window.GetHeight() - progress_bar.height);
progress_bar.sprite.SetZ(1);
fun progress_callback (duration, progress) {
progress_bar.width = Math.Int(Window.GetWidth() * progress);
if (progress_bar.image.GetWidth() != progress_bar.width) {
progress_bar.image = progress_bar.original_image.Scale(progress_bar.width, progress_bar.height);
progress_bar.sprite.SetImage(progress_bar.image);
}
}
Plymouth.SetBootProgressFunction(progress_callback);
### QUIT ###
fun quit_callback () {
progress_bar.sprite.SetOpacity(0);
}
Plymouth.SetQuitFunction(quit_callback);