From 9666babb928377cb0e33a45220fe9114d6c8bae3 Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Mon, 4 Jan 2021 15:39:41 +0000 Subject: [PATCH] Add GRUB module --- default.nix | 1 + modules/grub.nix | 101 +++++++++++++++++++++++++++++++++++ modules/plymouth/default.nix | 4 +- stylix/default.nix | 1 + stylix/pixel.nix | 9 ++++ 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 modules/grub.nix create mode 100644 stylix/pixel.nix diff --git a/default.nix b/default.nix index aee1ec6f..ad248ea3 100644 --- a/default.nix +++ b/default.nix @@ -5,6 +5,7 @@ ./modules/console.nix ./modules/feh.nix ./modules/fish.nix + ./modules/grub.nix ./modules/gtk.nix ./modules/kitty.nix ./modules/lightdm.nix diff --git a/modules/grub.nix b/modules/grub.nix new file mode 100644 index 00000000..eec7cd14 --- /dev/null +++ b/modules/grub.nix @@ -0,0 +1,101 @@ +{ pkgs, config, ... }: + +with config.lib.stylix; +with config.stylix.fonts; +with config.lib.stylix.colors; + +let + # Grub requires fonts to be converted to "PFF2 format" + # This function takes a font { name, package } and produces a .pf2 file + mkGrubFont = font: + pkgs.runCommand "${font.package.name}.pf2" + { + FONTCONFIG_FILE = pkgs.makeFontsConf { + fontDirectories = [ font.package ]; + }; + } + '' + # Use fontconfig to select the correct .ttf or .otf file based on name + font=$( + ${pkgs.fontconfig}/bin/fc-match -v "${font.name}" \ + | grep "file:" | cut -d '"' -f 2 + ) + + # Convert to .pf2 + ${pkgs.grub2}/bin/grub-mkfont $font --output $out --size 17 + ''; + +in { + boot.loader.grub = { + backgroundColor = base00-hash; + # Need to override the NixOS splash, this will match the background + splashImage = pixel "base00"; + + # This font will be used for the GRUB terminal + font = toString (mkGrubFont monospace); + + # TODO: Include OS icons + theme = pkgs.runCommand "stylix-grub" { + themeTxt = '' + desktop-image: "background.png" + desktop-image-scale-method: "crop" + desktop-color: "${base00-hash}" + + title-text: "" + + terminal-left: "10%" + terminal-top: "20%" + terminal-width: "80%" + terminal-height: "60%" + + + progress_bar { + left = 25% + top = 80%+20 # 20 pixels below boot menu + width = 50% + height = 30 + + id = "__timeout__" + show_text = true + font = "${sansSerif.name}" + text = "@TIMEOUT_NOTIFICATION_MIDDLE@" + + border_color = "${base00-hash}" + bg_color = "${base00-hash}" + fg_color = "${base0B-hash}" + text_color = "${base05-hash}" + } + + + boot_menu { + left = 25% + top = 20% + width = 50% + height = 60% + menu_pixmap_style = "background_*.png" + + item_height = 40 + item_icon_space = 8 + item_spacing = 0 + item_padding = 0 + item_font = "${sansSerif.name}" + item_color = "${base05-hash}" + + selected_item_color = "${base01-hash}" + selected_item_pixmap_style = "selection_*.png" + } + ''; + passAsFile = [ "themeTxt" ]; + } + '' + mkdir $out + cp $themeTxtPath $out/theme.txt + + # Make sure the background image is .png by asking to convert it + ${pkgs.imagemagick}/bin/convert ${config.stylix.image} png32:$out/background.png + + cp ${pixel "base00"} $out/background_c.png + cp ${pixel "base0B"} $out/selection_c.png + + cp ${mkGrubFont sansSerif} $out/sans_serif.pf2 + ''; + }; +} diff --git a/modules/plymouth/default.nix b/modules/plymouth/default.nix index 8efb5bf7..b12cf92a 100644 --- a/modules/plymouth/default.nix +++ b/modules/plymouth/default.nix @@ -12,9 +12,7 @@ let theme = pkgs.runCommandLocal "plymouth-theme" {} # 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 + cp ${config.lib.stylix.pixel "base0B"} $themeDir/progress.png echo " [Plymouth Theme] diff --git a/stylix/default.nix b/stylix/default.nix index 81ead8c6..73472f2d 100644 --- a/stylix/default.nix +++ b/stylix/default.nix @@ -8,6 +8,7 @@ with lib; ./colors.nix ./fonts.nix ./home-manager.nix + ./pixel.nix ]; options.stylix.image = mkOption { diff --git a/stylix/pixel.nix b/stylix/pixel.nix new file mode 100644 index 00000000..6c27b2e4 --- /dev/null +++ b/stylix/pixel.nix @@ -0,0 +1,9 @@ +{ pkgs, config, ... }: + +{ + # Generate a PNG image containing a named color + config.lib.stylix.pixel = color: + pkgs.runCommand "${color}-pixel.png" + { color = config.lib.stylix.colors."${color}-hash"; } + "${pkgs.imagemagick}/bin/convert xc:$color png32:$out"; +}