From 79747211dbedae098f04f5ec7e77a084625b7aad Mon Sep 17 00:00:00 2001 From: Cezary Siwek Date: Sat, 26 Oct 2024 11:37:34 +0200 Subject: [PATCH] nixos/modules/installer/cd-dvd/iso-image: improved grub and media contents config --- nixos/modules/installer/cd-dvd/iso-image.nix | 66 ++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index 63abf88cab09e..3a4cb1a427465 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -422,6 +422,18 @@ let echo "If you see this message, your EFI system doesn't support this feature." echo "" } + + ${lib.concatStrings + ( + map + ({name, class, body}: '' + menuentry '${name}' --class ${class} { + ${body} + } + '') + config.isoImage.grubExtraMenus + )} + menuentry 'Shutdown' --class shutdown { halt } @@ -433,7 +445,11 @@ let ''; efiImg = pkgs.runCommand "efi-image_eltorito" { - nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ]; + nativeBuildInputs = [ + pkgs.buildPackages.mtools + pkgs.buildPackages.libfaketime + pkgs.buildPackages.dosfstools + ]; strictDeps = true; } # Be careful about determinism: du --apparent-size, @@ -443,6 +459,16 @@ let mkdir -p ./EFI/BOOT cp -rp "${efiDir}"/EFI/BOOT/{grub.cfg,*.EFI,*.efi} ./EFI/BOOT + ${lib.concatStrings + ( + map + ({source, target}: '' + mkdir -p ./`dirname ./${target}` + cp -rp ${source} ./${target} + '') + config.isoImage.bootContents + )} + # Rewrite dates for everything in the FS find . -exec touch --date=2000-01-01 {} + @@ -459,11 +485,11 @@ let mkfs.vfat --invariant -i 12345678 -n EFIBOOT "$out" # Force a fixed order in mcopy for better determinism, and avoid file globbing - for d in $(find EFI -type d | sort); do + for d in $(find -type d | tail -n +2 | sort); do faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d" done - for f in $(find EFI -type f | sort); do + for f in $(find -type f | sort); do mcopy -pvm -i "$out" "$f" "::/$f" done @@ -540,7 +566,19 @@ in ''; description = '' This option lists files to be copied to fixed locations in the - generated ISO image. + main data partition of the generated ISO image. + ''; + }; + + isoImage.bootContents = lib.mkOption { + example = lib.literalExpression '' + [ { source = ./your-custom-efi-app.efi; + target = "EFI/boot/your-custom-efi-app.efi"; + } ] + ''; + description = lib.mdDoc '' + This option lists files to be copied to fixed locations in the + El-Torito boot catalog. ''; }; @@ -626,6 +664,26 @@ in ''; }; + isoImage.grubExtraMenus = lib.mkOption { + default = []; + type = lib.types.listOf (lib.types.submodule { + options.name = lib.mkOption { + description = lib.mdDoc "Label of the option on the GRUB menu."; + type = lib.types.str; + }; + + options.class = lib.mkOption { + description = lib.mdDoc "Class of the option in the GRUB menu (i.e. `settings`)"; + type = lib.types.str; + }; + + options.body = lib.mkOption { + description = lib.mdDoc "GRUB script to be executed when the option is selected"; + type = lib.types.str; + }; + }); + }; + isoImage.syslinuxTheme = lib.mkOption { default = '' MENU TITLE ${config.system.nixos.distroName}