Skip to content

Commit

Permalink
nixos/modules/installer/cd-dvd/iso-image: improved grub and media con…
Browse files Browse the repository at this point in the history
…tents config
  • Loading branch information
Cezary Siwek committed Oct 26, 2024
1 parent c3db199 commit 7974721
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions nixos/modules/installer/cd-dvd/iso-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
Expand All @@ -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 {} +
Expand All @@ -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
Expand Down Expand Up @@ -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.
'';
};

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 7974721

Please sign in to comment.