From 70ff68055bc831a5284b0c7ee7c381c23402d897 Mon Sep 17 00:00:00 2001 From: madisetti Date: Sun, 20 Feb 2022 22:41:50 -0500 Subject: [PATCH 1/4] Added flake for grub on NixOS --- flake.nix | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0fbada7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,91 @@ +{ + description = "Flake to manage grub2 themes from vinceliuice"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/master"; + }; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + }; + in + with nixpkgs.lib; + rec { + nixosModule = { config, ... }: + let + cfg = config.boot.loader.grub2-theme; + resolutions = { + "1080p" = "1920x1080"; + "ultrawide" = "2560x1080"; + "2k" = "2560x1440"; + "4k" = "3840x2160"; + "ultrawide2k" = "3440x1440"; + }; + grub2-theme = pkgs.stdenv.mkDerivation { + name = "grub2-theme"; + src = "${self}"; + installPhase = '' + mkdir -p $out/grub/themes; + bash ./install.sh \ + --generate $out/grub/themes \ + --screen ${cfg.screen} \ + --theme ${cfg.theme} \ + --icon ${cfg.icon}; + ''; + }; + resolution = resolutions."${cfg.screen}"; + in + rec { + options = { + boot.loader.grub2-theme = { + theme = mkOption { + default = "tela"; + example = "tela"; + type = types.enum [ "tela" "vimix" "stylish" "whitesur" ]; + description = '' + The theme to use for grub2. + ''; + }; + icon = mkOption { + default = "white"; + example = "white"; + type = types.enum [ "color" "white" "whitesur" ]; + description = '' + The icon to use for grub2. + ''; + }; + screen = mkOption { + default = "1080p"; + example = "1080p"; + type = types.enum [ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ]; + description = '' + The screen resolution to use for grub2. + ''; + }; + splashImage = mkOption { + default = ""; + example = "/my/path/background.jpg"; + type = types.string; + description = '' + The path of the image to use for background (must be jpg). + ''; + }; + }; + }; + config = mkMerge [{ + environment.systemPackages = [ + grub2-theme + ]; + boot.loader.grub = { + theme = "${grub2-theme}/grub/themes/${cfg.theme}"; + splashImage = "${grub2-theme}/grub/themes/${cfg.theme}/background.jpg"; + gfxmodeEfi = "${resolution},auto"; + gfxmodeBios = "${resolution},auto"; + }; + }]; + }; + }; +} From 824064faa99b0f63fd3510661b9fb5332388f672 Mon Sep 17 00:00:00 2001 From: madisetti Date: Sun, 20 Feb 2022 22:46:11 -0500 Subject: [PATCH 2/4] Move clear to remove busybox dependency --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ab22448..b245ea2 100755 --- a/install.sh +++ b/install.sh @@ -69,8 +69,6 @@ usage() { } generate() { - clear - # Make a themes directory if it doesn't exist prompt -s "\n Checking for the existence of themes directory..." @@ -115,6 +113,8 @@ install() { # Check for root access and proceed if it is present if [[ "$UID" -eq "$ROOT_UID" ]]; then + clear + # Generate the theme in "/usr/share/grub/themes" generate "${theme}" "${icon}" "${screen}" From 2fd6eb9b662efa5b0fb5f29bfb2cf9b6e289e644 Mon Sep 17 00:00:00 2001 From: madisetti Date: Sun, 20 Feb 2022 23:00:36 -0500 Subject: [PATCH 3/4] Needs to exit 0 --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b245ea2..8f59e74 100755 --- a/install.sh +++ b/install.sh @@ -599,4 +599,4 @@ if [[ "${dialog:-}" == 'false' ]]; then dialog_installer fi -exit 1 +exit 0 From 4f3b99cdf3900f7f5fd396f92b256ddfd90ec646 Mon Sep 17 00:00:00 2001 From: madisetti Date: Mon, 21 Feb 2022 11:59:04 -0500 Subject: [PATCH 4/4] Added footer and enable option --- flake.nix | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 0fbada7..5079697 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,13 @@ --screen ${cfg.screen} \ --theme ${cfg.theme} \ --icon ${cfg.icon}; + + if [ -f ${cfg.splashImage} ]; then + cp ${cfg.splashImage} $out/grub/themes/${cfg.theme}/background.jpg; + fi; + if [ ${pkgs.lib.trivial.boolToString cfg.footer} == "false" ]; then + sed -i ':again;$!N;$!b again; s/\+ image {[^}]*}//g' $out/grub/themes/${cfg.theme}/theme.txt; + fi; ''; }; resolution = resolutions."${cfg.screen}"; @@ -41,6 +48,14 @@ rec { options = { boot.loader.grub2-theme = { + enable = mkOption { + default = true; + example = true; + type = types.bool; + description = '' + Enable grub2 theming + ''; + }; theme = mkOption { default = "tela"; example = "tela"; @@ -68,14 +83,22 @@ splashImage = mkOption { default = ""; example = "/my/path/background.jpg"; - type = types.string; + type = types.path; description = '' The path of the image to use for background (must be jpg). ''; }; + footer = mkOption { + default = true; + example = true; + type = types.bool; + description = '' + Whether to include the image footer. + ''; + }; }; }; - config = mkMerge [{ + config = mkIf cfg.enable (mkMerge [{ environment.systemPackages = [ grub2-theme ]; @@ -84,8 +107,13 @@ splashImage = "${grub2-theme}/grub/themes/${cfg.theme}/background.jpg"; gfxmodeEfi = "${resolution},auto"; gfxmodeBios = "${resolution},auto"; + extraConfig = '' + insmod gfxterm + insmod png + set icondir=($root)/theme/icons + ''; }; - }]; + }]); }; }; }