diff --git a/default.nix b/default.nix index cfa35c7f..aee1ec6f 100644 --- a/default.nix +++ b/default.nix @@ -8,6 +8,7 @@ ./modules/gtk.nix ./modules/kitty.nix ./modules/lightdm.nix + ./modules/plymouth ./modules/qutebrowser.nix ./modules/vim.nix ]; diff --git a/modules/plymouth/default.nix b/modules/plymouth/default.nix new file mode 100644 index 00000000..8efb5bf7 --- /dev/null +++ b/modules/plymouth/default.nix @@ -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 ]; + }; +} diff --git a/modules/plymouth/theme.script b/modules/plymouth/theme.script new file mode 100644 index 00000000..2e1a224e --- /dev/null +++ b/modules/plymouth/theme.script @@ -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);