2022-02-21 04:41:50 +01:00
|
|
|
{
|
|
|
|
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 {
|
2022-11-18 18:35:17 +01:00
|
|
|
nixosModules.default = { config, ... }:
|
2022-02-21 04:41:50 +01:00
|
|
|
let
|
|
|
|
cfg = config.boot.loader.grub2-theme;
|
2022-03-27 17:52:59 +02:00
|
|
|
splashImage = if cfg.splashImage == null then "" else cfg.splashImage;
|
2022-11-18 18:35:17 +01:00
|
|
|
hasBootMenuConfig = cfg.bootMenuConfig != null;
|
|
|
|
hasTerminalConfig = cfg.terminalConfig != null;
|
2022-02-21 04:41:50 +01:00
|
|
|
resolutions = {
|
|
|
|
"1080p" = "1920x1080";
|
|
|
|
"ultrawide" = "2560x1080";
|
|
|
|
"2k" = "2560x1440";
|
|
|
|
"4k" = "3840x2160";
|
|
|
|
"ultrawide2k" = "3440x1440";
|
2024-09-17 18:25:41 +02:00
|
|
|
};
|
2022-02-21 04:41:50 +01:00
|
|
|
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} \
|
2024-09-17 18:25:41 +02:00
|
|
|
--icon ${cfg.icon} \
|
|
|
|
${if cfg.customResolution != null then "--custom-resolution ${cfg.customResolution}" else ""}
|
2022-02-21 17:59:04 +01:00
|
|
|
|
2022-03-27 17:52:59 +02:00
|
|
|
if [ -n "${splashImage}" ]; then
|
2022-11-18 18:35:17 +01:00
|
|
|
rm $out/grub/themes/${cfg.theme}/background.jpg;
|
2024-02-16 13:25:23 +01:00
|
|
|
${pkgs.imagemagick}/bin/convert ${splashImage} $out/grub/themes/${cfg.theme}/background.jpg;
|
2022-02-21 17:59:04 +01:00
|
|
|
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;
|
2022-11-18 18:35:17 +01:00
|
|
|
if [ ${pkgs.lib.trivial.boolToString hasBootMenuConfig} == "true" ]; then
|
|
|
|
sed -i ':again;$!N;$!b again; s/\+ boot_menu {[^}]*}//g' $out/grub/themes/${cfg.theme}/theme.txt;
|
|
|
|
cat << EOF >> $out/grub/themes/${cfg.theme}/theme.txt
|
|
|
|
+ boot_menu {
|
|
|
|
${if cfg.bootMenuConfig == null then "" else cfg.bootMenuConfig}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
fi;
|
|
|
|
if [ ${pkgs.lib.trivial.boolToString hasTerminalConfig} == "true" ]; then
|
|
|
|
sed -i 's/^terminal-.*$//g' $out/grub/themes/${cfg.theme}/theme.txt
|
|
|
|
cat << EOF >> $out/grub/themes/${cfg.theme}/theme.txt
|
|
|
|
${if cfg.terminalConfig == null then "" else cfg.terminalConfig}
|
|
|
|
EOF
|
|
|
|
fi;
|
2022-02-21 04:41:50 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-09-17 18:08:35 +02:00
|
|
|
resolution = if cfg.customResolution != null
|
|
|
|
then cfg.customResolution
|
|
|
|
else resolutions."${cfg.screen}";
|
2022-02-21 04:41:50 +01:00
|
|
|
in
|
|
|
|
rec {
|
|
|
|
options = {
|
|
|
|
boot.loader.grub2-theme = {
|
2022-02-21 17:59:04 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
example = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enable grub2 theming
|
|
|
|
'';
|
|
|
|
};
|
2022-02-21 04:41:50 +01:00
|
|
|
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";
|
2024-09-17 18:25:41 +02:00
|
|
|
type = types.enum [ "1080p" "2k" "4k" "ultrawide" "ultrawide2k" ];
|
2024-09-17 18:08:35 +02:00
|
|
|
description = ''
|
2024-09-17 18:25:41 +02:00
|
|
|
The screen resolution to use for grub2.
|
2024-09-17 18:08:35 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
customResolution = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "1600x900";
|
|
|
|
type = types.nullOr (types.strMatching "[0-9]+x[0-9]+");
|
2022-02-21 04:41:50 +01:00
|
|
|
description = ''
|
2024-09-17 18:08:35 +02:00
|
|
|
Custom resolution for grub2 theme. Should be in the format "WIDTHxHEIGHT".
|
2024-09-17 18:25:41 +02:00
|
|
|
If set, this will override the 'screen' option.
|
2022-02-21 04:41:50 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
splashImage = mkOption {
|
2022-03-27 17:52:59 +02:00
|
|
|
default = null;
|
2022-02-21 04:41:50 +01:00
|
|
|
example = "/my/path/background.jpg";
|
2022-03-27 17:52:59 +02:00
|
|
|
type = types.nullOr types.path;
|
2022-02-21 04:41:50 +01:00
|
|
|
description = ''
|
2022-11-18 18:35:17 +01:00
|
|
|
The path of the image to use for background (must be jpg or png).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
bootMenuConfig = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "left = 30%";
|
2023-08-15 20:54:51 +02:00
|
|
|
type = types.nullOr types.str;
|
2022-11-18 18:35:17 +01:00
|
|
|
description = ''
|
|
|
|
Grub theme definition for boot_menu.
|
|
|
|
Refer to config/theme-*.txt for reference.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
terminalConfig = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "terminal-font: \"Terminus Regular 18\"";
|
2023-08-15 20:54:51 +02:00
|
|
|
type = types.nullOr types.str;
|
2022-11-18 18:35:17 +01:00
|
|
|
description = ''
|
|
|
|
Replaces grub theme definition for terminial-*.
|
|
|
|
Refer to config/theme-*.txt for reference.
|
2022-02-21 04:41:50 +01:00
|
|
|
'';
|
|
|
|
};
|
2022-02-21 17:59:04 +01:00
|
|
|
footer = mkOption {
|
|
|
|
default = true;
|
|
|
|
example = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to include the image footer.
|
|
|
|
'';
|
|
|
|
};
|
2022-02-21 04:41:50 +01:00
|
|
|
};
|
|
|
|
};
|
2022-02-21 17:59:04 +01:00
|
|
|
config = mkIf cfg.enable (mkMerge [{
|
2022-02-21 04:41:50 +01:00
|
|
|
environment.systemPackages = [
|
|
|
|
grub2-theme
|
|
|
|
];
|
2024-09-17 18:08:35 +02:00
|
|
|
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";
|
|
|
|
extraConfig = ''
|
|
|
|
insmod gfxterm
|
|
|
|
insmod png
|
|
|
|
set icondir=($root)/theme/icons
|
|
|
|
'';
|
|
|
|
};
|
2022-02-21 17:59:04 +01:00
|
|
|
}]);
|
2022-02-21 04:41:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|