Skip to content

grub: migrate to mkTarget#2357

Draft
0xda157 wants to merge 1 commit into
nix-community:masterfrom
0xda157:grub-mkTarget
Draft

grub: migrate to mkTarget#2357
0xda157 wants to merge 1 commit into
nix-community:masterfrom
0xda157:grub-mkTarget

Conversation

@0xda157

@0xda157 0xda157 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

@stylix-automation stylix-automation Bot added topic: nixos NixOS target topic: modules /modules/ subsystem labels Jun 5, 2026
@0xda157

0xda157 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

(marking as draft until I can test locally)

Comment thread modules/grub/nixos.nix
Comment on lines +200 to +201
stylix.targets.grub.theme = {
main = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
stylix.targets.grub.theme = {
main = ''
stylix.targets.grub.theme.main = ''

Comment thread modules/grub/nixos.nix
Comment on lines +200 to +204
stylix.targets.grub.theme = {
main = ''
desktop-color: "${colors.withHashtag.base00}"
'';
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the surrounding newlines are optional, this could be simplified as something like:

Suggested change
stylix.targets.grub.theme = {
main = ''
desktop-color: "${colors.withHashtag.base00}"
'';
};
stylix.targets.grub.theme.main =
''desktop-color: "${colors.withHashtag.base00}"'';

Comment thread modules/grub/nixos.nix
{
mkTarget {
options = {
useWallpaper = mkEnableWallpaper "GRUB" false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider deprecating useWallpaper as in commit ce22070 ("treewide: deprecate manual targets.${target}.useWallpaper.enable options (#2084)").

For consistency, it might be worth introducing the breaking change of useWallpaper changing its default from false to true.

Comment thread modules/grub/nixos.nix
Comment on lines +175 to 176


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the noisy empty lines:

diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix
index 93195cd7..7cd1d2e7 100644
--- a/modules/grub/nixos.nix
+++ b/modules/grub/nixos.nix
@@ -172,8 +172,6 @@ mkTarget {
             desktop-image-scale-method: "${image-scale}"
           '';
           extraBuildScript = ''
-
-
             ${
               if
                 cfg.useWallpaper

Comment thread modules/grub/nixos.nix
# This font will be used for the GRUB terminal
font = toString (mkGrubFont fonts.monospace);

# TODO: Include OS icons

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This vanished comment should probably be brought back.

Comment thread modules/grub/nixos.nix
|| cfg.theme.boot_menu != ""
)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix
index 93195cd7..65a1cf79 100644
--- a/modules/grub/nixos.nix
+++ b/modules/grub/nixos.nix
@@ -63,7 +63,6 @@ mkTarget {
           || cfg.theme.boot_menu != ""
         )
         {
-
           theme =
             pkgs.runCommand "stylix-grub"
               {

Comment thread modules/grub/nixos.nix
Comment on lines +59 to +64
lib.mkIf
(
cfg.theme.main != ""
|| cfg.theme.progress_bar != ""
|| cfg.theme.boot_menu != ""
)

@trueNAHO trueNAHO Jun 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not move this lib.mkIf into the single theme declaration:

theme =
  lib.mkIf
  (
    /* ... */
  )
  (
    pkgs.runCommand "stylix-grub"
      {
        /* ... */
      }
      (
        /* ... */
      )
  );

Comment thread modules/grub/nixos.nix
Comment on lines +61 to +63
cfg.theme.main != ""
|| cfg.theme.progress_bar != ""
|| cfg.theme.boot_menu != ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of this clever condition is to only declare the otherwise unconditional Stylix theme when something of value happens, should it not guard on everything, including cfg.theme.extraBuildScript:

Suggested change
cfg.theme.main != ""
|| cfg.theme.progress_bar != ""
|| cfg.theme.boot_menu != ""
cfg.theme.main != ""
|| cfg.theme.progress_bar != ""
|| cfg.theme.boot_menu != ""
|| cfg.theme.extraBuildScript != ""

Comment thread modules/grub/nixos.nix
pkgs.runCommand "stylix-grub"
{
passAsFile = [ "themeTxt" ];
themeTxt = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this looks better without explicitly concatenating strings:

diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix
index 93195cd7..a32c783c 100644
--- a/modules/grub/nixos.nix
+++ b/modules/grub/nixos.nix
@@ -77,36 +77,38 @@ mkTarget {
                   terminal-height: "60%"
 
                   ${cfg.theme.main}
-                ''
-                + lib.optionalString (cfg.theme.progress_bar != "") ''
-                  + progress_bar {
-                    left = 25%
-                    top = 80%+20  # 20 pixels below boot menu
-                    width = 50%
-                    height = 30
 
-                    id = "__timeout__"
-                    show_text = true
-                    text = "@TIMEOUT_NOTIFICATION_MIDDLE@"
-                    ${cfg.theme.progress_bar}
-                  }
-                ''
-                + lib.optionalString (cfg.theme.boot_menu != "") ''
-                  + boot_menu {
-                    left = 25%
-                    top = 20%
-                    width = 50%
-                    height = 60%
-                    menu_pixmap_style = "background_*.png"
+                  ${lib.optionalString (cfg.theme.progress_bar != "") ''
+                    + progress_bar {
+                      left = 25%
+                      top = 80%+20  # 20 pixels below boot menu
+                      width = 50%
+                      height = 30
+
+                      id = "__timeout__"
+                      show_text = true
+                      text = "@TIMEOUT_NOTIFICATION_MIDDLE@"
+                      ${cfg.theme.progress_bar}
+                    }
+                  ''}
+
+                  ${lib.optionalString (cfg.theme.boot_menu != "") ''
+                    + 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_height = 40
+                      item_icon_space = 8
+                      item_spacing = 0
+                      item_padding = 0
 
-                    selected_item_pixmap_style = "selection_*.png"
-                    ${cfg.theme.boot_menu}
-                  }
+                      selected_item_pixmap_style = "selection_*.png"
+                      ${cfg.theme.boot_menu}
+                    }
+                  ''}
                 '';
               }
               (

Comment thread modules/grub/nixos.nix
Comment on lines +112 to +118
(
''
mkdir $out
cp $themeTxtPath $out/theme.txt
''
+ cfg.theme.extraBuildScript
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this looks better without explicitly concatenating strings:

diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix
index 93195cd7..d4047b66 100644
--- a/modules/grub/nixos.nix
+++ b/modules/grub/nixos.nix
@@ -109,13 +109,12 @@ mkTarget {
                   }
                 '';
               }
-              (
-                ''
-                  mkdir $out
-                  cp $themeTxtPath $out/theme.txt
-                ''
-                + cfg.theme.extraBuildScript
-              );
+              ''
+                mkdir $out
+                cp $themeTxtPath $out/theme.txt
+
+                ${cfg.theme.extraBuildScript}
+              '';
         }
     )
     (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: modules /modules/ subsystem topic: nixos NixOS target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants