2009-06-05 13:35:27 +00:00
|
|
|
|
# This module creates a bootable ISO image containing the given NixOS
|
|
|
|
|
# configuration. The derivation for the ISO image will be placed in
|
|
|
|
|
# config.system.build.isoImage.
|
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
2009-11-14 16:12:02 +00:00
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
|
with lib;
|
2009-06-05 13:35:27 +00:00
|
|
|
|
|
|
|
|
|
let
|
2018-01-12 04:32:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Given a list of `options`, concats the result of mapping each options
|
|
|
|
|
* to a menuentry for use in grub.
|
|
|
|
|
*
|
|
|
|
|
* * defaults: {name, image, params, initrd}
|
|
|
|
|
* * options: [ option... ]
|
|
|
|
|
* * option: {name, params, class}
|
|
|
|
|
*/
|
|
|
|
|
menuBuilderGrub2 =
|
|
|
|
|
defaults: options: lib.concatStrings
|
|
|
|
|
(
|
|
|
|
|
map
|
|
|
|
|
(option: ''
|
|
|
|
|
menuentry '${defaults.name} ${
|
|
|
|
|
# Name appended to menuentry defaults to params if no specific name given.
|
2023-03-19 20:44:31 +00:00
|
|
|
|
option.name or (optionalString (option ? params) "(${option.params})")
|
|
|
|
|
}' ${optionalString (option ? class) " --class ${option.class}"} {
|
2023-08-14 21:35:47 +00:00
|
|
|
|
# Fallback to UEFI console for boot, efifb sometimes has difficulties.
|
|
|
|
|
terminal_output console
|
|
|
|
|
|
2019-09-21 15:08:00 +00:00
|
|
|
|
linux ${defaults.image} \''${isoboot} ${defaults.params} ${
|
2018-01-12 04:32:56 +00:00
|
|
|
|
option.params or ""
|
|
|
|
|
}
|
|
|
|
|
initrd ${defaults.initrd}
|
|
|
|
|
}
|
|
|
|
|
'')
|
|
|
|
|
options
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-29 10:22:51 +00:00
|
|
|
|
* Builds the default options.
|
2018-01-12 04:32:56 +00:00
|
|
|
|
*/
|
2022-09-29 10:22:51 +00:00
|
|
|
|
buildMenuGrub2 = buildMenuAdditionalParamsGrub2 "";
|
2018-01-12 04:32:56 +00:00
|
|
|
|
|
2022-09-29 10:19:06 +00:00
|
|
|
|
targetArch =
|
|
|
|
|
if config.boot.loader.grub.forcei686 then
|
|
|
|
|
"ia32"
|
|
|
|
|
else
|
|
|
|
|
pkgs.stdenv.hostPlatform.efiArch;
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
/**
|
2022-09-29 10:22:51 +00:00
|
|
|
|
* Given params to add to `params`, build a set of default options.
|
2018-01-12 04:32:56 +00:00
|
|
|
|
* Use this one when creating a variant (e.g. hidpi)
|
|
|
|
|
*/
|
2022-09-29 10:22:51 +00:00
|
|
|
|
buildMenuAdditionalParamsGrub2 = additional:
|
2018-01-12 04:32:56 +00:00
|
|
|
|
let
|
|
|
|
|
finalCfg = {
|
2023-03-28 18:35:58 +00:00
|
|
|
|
name = "${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}";
|
2018-01-12 04:32:56 +00:00
|
|
|
|
params = "init=${config.system.build.toplevel}/init ${additional} ${toString config.boot.kernelParams}";
|
2018-12-02 05:34:58 +00:00
|
|
|
|
image = "/boot/${config.system.boot.loader.kernelFile}";
|
2018-01-12 04:32:56 +00:00
|
|
|
|
initrd = "/boot/initrd";
|
|
|
|
|
};
|
2022-09-27 12:10:45 +00:00
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
in
|
|
|
|
|
menuBuilderGrub2
|
|
|
|
|
finalCfg
|
|
|
|
|
[
|
|
|
|
|
{ class = "installer"; }
|
|
|
|
|
{ class = "nomodeset"; params = "nomodeset"; }
|
|
|
|
|
{ class = "copytoram"; params = "copytoram"; }
|
|
|
|
|
{ class = "debug"; params = "debug"; }
|
|
|
|
|
]
|
|
|
|
|
;
|
|
|
|
|
|
2014-11-16 19:11:56 +00:00
|
|
|
|
# Timeout in syslinux is in units of 1/10 of a second.
|
2022-12-22 16:33:50 +00:00
|
|
|
|
# null means max timeout (35996, just under 1h in 1/10 seconds)
|
|
|
|
|
# 0 means disable timeout
|
2014-11-16 19:11:56 +00:00
|
|
|
|
syslinuxTimeout = if config.boot.loader.timeout == null then
|
2022-12-22 16:33:50 +00:00
|
|
|
|
35996
|
2014-11-16 19:11:56 +00:00
|
|
|
|
else
|
2022-12-22 16:33:50 +00:00
|
|
|
|
config.boot.loader.timeout * 10;
|
2009-06-09 12:01:31 +00:00
|
|
|
|
|
2022-12-05 18:46:59 +00:00
|
|
|
|
# Timeout in grub is in seconds.
|
|
|
|
|
# null means max timeout (infinity)
|
|
|
|
|
# 0 means disable timeout
|
|
|
|
|
grubEfiTimeout = if config.boot.loader.timeout == null then
|
|
|
|
|
-1
|
|
|
|
|
else
|
|
|
|
|
config.boot.loader.timeout;
|
|
|
|
|
|
2014-10-26 20:29:04 +00:00
|
|
|
|
# The configuration file for syslinux.
|
2014-11-16 19:13:11 +00:00
|
|
|
|
|
2022-12-18 00:31:14 +00:00
|
|
|
|
# Notes on syslinux configuration and UNetbootin compatibility:
|
2014-11-16 19:13:11 +00:00
|
|
|
|
# * Do not use '/syslinux/syslinux.cfg' as the path for this
|
|
|
|
|
# configuration. UNetbootin will not parse the file and use it as-is.
|
|
|
|
|
# This results in a broken configuration if the partition label does
|
|
|
|
|
# not match the specified config.isoImage.volumeID. For this reason
|
|
|
|
|
# we're using '/isolinux/isolinux.cfg'.
|
|
|
|
|
# * Use APPEND instead of adding command-line arguments directly after
|
|
|
|
|
# the LINUX entries.
|
|
|
|
|
# * COM32 entries (chainload, reboot, poweroff) are not recognized. They
|
|
|
|
|
# result in incorrect boot entries.
|
|
|
|
|
|
2015-07-25 17:03:52 +00:00
|
|
|
|
baseIsolinuxCfg = ''
|
2019-03-24 08:29:52 +00:00
|
|
|
|
SERIAL 0 115200
|
2014-11-16 19:11:56 +00:00
|
|
|
|
TIMEOUT ${builtins.toString syslinuxTimeout}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
UI vesamenu.c32
|
|
|
|
|
MENU BACKGROUND /isolinux/background.png
|
2022-02-15 15:02:23 +00:00
|
|
|
|
|
|
|
|
|
${config.isoImage.syslinuxTheme}
|
2018-01-08 03:09:42 +00:00
|
|
|
|
|
2014-11-16 19:11:56 +00:00
|
|
|
|
DEFAULT boot
|
2014-10-26 20:29:04 +00:00
|
|
|
|
|
|
|
|
|
LABEL boot
|
2023-03-28 18:35:58 +00:00
|
|
|
|
MENU LABEL ${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}
|
2015-11-15 00:00:00 +00:00
|
|
|
|
LINUX /boot/${config.system.boot.loader.kernelFile}
|
2014-11-16 19:13:11 +00:00
|
|
|
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
|
2015-11-15 00:00:00 +00:00
|
|
|
|
INITRD /boot/${config.system.boot.loader.initrdFile}
|
2015-12-24 17:31:07 +00:00
|
|
|
|
|
|
|
|
|
# A variant to boot with 'nomodeset'
|
|
|
|
|
LABEL boot-nomodeset
|
2023-03-28 18:35:58 +00:00
|
|
|
|
MENU LABEL ${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (nomodeset)
|
2015-11-15 00:00:00 +00:00
|
|
|
|
LINUX /boot/${config.system.boot.loader.kernelFile}
|
2015-12-24 17:31:07 +00:00
|
|
|
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} nomodeset
|
2015-11-15 00:00:00 +00:00
|
|
|
|
INITRD /boot/${config.system.boot.loader.initrdFile}
|
2017-05-08 08:22:07 +00:00
|
|
|
|
|
|
|
|
|
# A variant to boot with 'copytoram'
|
|
|
|
|
LABEL boot-copytoram
|
2023-03-28 18:35:58 +00:00
|
|
|
|
MENU LABEL ${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (copytoram)
|
2015-11-15 00:00:00 +00:00
|
|
|
|
LINUX /boot/${config.system.boot.loader.kernelFile}
|
2017-05-08 08:22:07 +00:00
|
|
|
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} copytoram
|
2015-11-15 00:00:00 +00:00
|
|
|
|
INITRD /boot/${config.system.boot.loader.initrdFile}
|
2017-09-23 17:46:45 +00:00
|
|
|
|
|
|
|
|
|
# A variant to boot with verbose logging to the console
|
2018-04-22 19:12:17 +00:00
|
|
|
|
LABEL boot-debug
|
2023-03-28 18:35:58 +00:00
|
|
|
|
MENU LABEL ${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (debug)
|
2015-11-15 00:00:00 +00:00
|
|
|
|
LINUX /boot/${config.system.boot.loader.kernelFile}
|
2017-09-23 17:46:45 +00:00
|
|
|
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} loglevel=7
|
2015-11-15 00:00:00 +00:00
|
|
|
|
INITRD /boot/${config.system.boot.loader.initrdFile}
|
2020-06-19 07:57:04 +00:00
|
|
|
|
|
|
|
|
|
# A variant to boot with a serial console enabled
|
|
|
|
|
LABEL boot-serial
|
2023-03-28 18:35:58 +00:00
|
|
|
|
MENU LABEL ${config.isoImage.prependToMenuLabel}${config.system.nixos.distroName} ${config.system.nixos.label}${config.isoImage.appendToMenuLabel} (serial console=ttyS0,115200n8)
|
2020-06-19 07:57:04 +00:00
|
|
|
|
LINUX /boot/${config.system.boot.loader.kernelFile}
|
|
|
|
|
APPEND init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} console=ttyS0,115200n8
|
|
|
|
|
INITRD /boot/${config.system.boot.loader.initrdFile}
|
2015-07-25 17:03:52 +00:00
|
|
|
|
'';
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
2015-01-21 13:00:18 +00:00
|
|
|
|
isolinuxMemtest86Entry = ''
|
|
|
|
|
LABEL memtest
|
|
|
|
|
MENU LABEL Memtest86+
|
|
|
|
|
LINUX /boot/memtest.bin
|
|
|
|
|
APPEND ${toString config.boot.loader.grub.memtest86.params}
|
|
|
|
|
'';
|
|
|
|
|
|
2018-04-25 00:17:31 +00:00
|
|
|
|
isolinuxCfg = concatStringsSep "\n"
|
|
|
|
|
([ baseIsolinuxCfg ] ++ optional config.boot.loader.grub.memtest86.enable isolinuxMemtest86Entry);
|
2014-11-08 12:09:08 +00:00
|
|
|
|
|
2021-04-20 21:03:15 +00:00
|
|
|
|
refindBinary = if targetArch == "x64" || targetArch == "aa64" then "refind_${targetArch}.efi" else null;
|
|
|
|
|
|
2018-01-11 02:14:52 +00:00
|
|
|
|
# Setup instructions for rEFInd.
|
|
|
|
|
refind =
|
2021-04-20 21:03:15 +00:00
|
|
|
|
if refindBinary != null then
|
2018-01-11 02:14:52 +00:00
|
|
|
|
''
|
|
|
|
|
# Adds rEFInd to the ISO.
|
2021-04-20 21:03:15 +00:00
|
|
|
|
cp -v ${pkgs.refind}/share/refind/${refindBinary} $out/EFI/boot/
|
2018-01-11 02:14:52 +00:00
|
|
|
|
''
|
|
|
|
|
else
|
2018-12-02 05:34:58 +00:00
|
|
|
|
"# No refind for ${targetArch}"
|
2018-01-11 02:14:52 +00:00
|
|
|
|
;
|
2019-08-22 22:10:03 +00:00
|
|
|
|
|
|
|
|
|
grubPkgs = if config.boot.loader.grub.forcei686 then pkgs.pkgsi686Linux else pkgs;
|
2018-01-11 02:14:52 +00:00
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
grubMenuCfg = ''
|
|
|
|
|
#
|
|
|
|
|
# Menu configuration
|
|
|
|
|
#
|
|
|
|
|
|
2021-05-23 00:01:07 +00:00
|
|
|
|
# Search using a "marker file"
|
|
|
|
|
search --set=root --file /EFI/nixos-installer-image
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
insmod gfxterm
|
|
|
|
|
insmod png
|
|
|
|
|
set gfxpayload=keep
|
2021-05-22 22:16:42 +00:00
|
|
|
|
set gfxmode=${concatStringsSep "," [
|
|
|
|
|
# GRUB will use the first valid mode listed here.
|
|
|
|
|
# `auto` will sometimes choose the smallest valid mode it detects.
|
|
|
|
|
# So instead we'll list a lot of possibly valid modes :/
|
|
|
|
|
#"3840x2160"
|
|
|
|
|
#"2560x1440"
|
2023-08-14 21:01:40 +00:00
|
|
|
|
"1920x1200"
|
2021-05-22 22:16:42 +00:00
|
|
|
|
"1920x1080"
|
|
|
|
|
"1366x768"
|
2023-08-14 21:01:40 +00:00
|
|
|
|
"1280x800"
|
2021-05-22 22:16:42 +00:00
|
|
|
|
"1280x720"
|
2023-08-14 21:01:40 +00:00
|
|
|
|
"1200x1920"
|
2021-05-22 22:16:42 +00:00
|
|
|
|
"1024x768"
|
2023-08-14 21:01:40 +00:00
|
|
|
|
"800x1280"
|
2021-05-22 22:16:42 +00:00
|
|
|
|
"800x600"
|
|
|
|
|
"auto"
|
|
|
|
|
]}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
|
2023-08-14 23:43:20 +00:00
|
|
|
|
if [ "\$textmode" == "false" ]; then
|
|
|
|
|
terminal_output gfxterm
|
|
|
|
|
terminal_input console
|
2018-01-12 04:32:56 +00:00
|
|
|
|
else
|
2023-08-14 23:43:20 +00:00
|
|
|
|
terminal_output console
|
|
|
|
|
terminal_input console
|
|
|
|
|
# Sets colors for console term.
|
2018-01-12 04:32:56 +00:00
|
|
|
|
set menu_color_normal=cyan/blue
|
|
|
|
|
set menu_color_highlight=white/blue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
${ # When there is a theme configured, use it, otherwise use the background image.
|
2019-04-24 03:48:22 +00:00
|
|
|
|
if config.isoImage.grubTheme != null then ''
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Sets theme.
|
2021-05-22 21:07:36 +00:00
|
|
|
|
set theme=(\$root)/EFI/boot/grub-theme/theme.txt
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Load theme fonts
|
2021-05-22 21:07:36 +00:00
|
|
|
|
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n")
|
2018-01-12 04:32:56 +00:00
|
|
|
|
'' else ''
|
2021-05-22 21:07:36 +00:00
|
|
|
|
if background_image (\$root)/EFI/boot/efi-background.png; then
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Black background means transparent background when there
|
|
|
|
|
# is a background image set... This seems undocumented :(
|
|
|
|
|
set color_normal=black/black
|
|
|
|
|
set color_highlight=white/blue
|
|
|
|
|
else
|
|
|
|
|
# Falls back again to proper colors.
|
|
|
|
|
set menu_color_normal=cyan/blue
|
|
|
|
|
set menu_color_highlight=white/blue
|
|
|
|
|
fi
|
|
|
|
|
''}
|
|
|
|
|
'';
|
|
|
|
|
|
2015-07-25 17:03:52 +00:00
|
|
|
|
# The EFI boot image.
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Notes about grub:
|
|
|
|
|
# * Yes, the grubMenuCfg has to be repeated in all submenus. Otherwise you
|
|
|
|
|
# will get white-on-black console-like text on sub-menus. *sigh*
|
2021-05-03 19:52:22 +00:00
|
|
|
|
efiDir = pkgs.runCommand "efi-directory" {
|
|
|
|
|
nativeBuildInputs = [ pkgs.buildPackages.grub2_efi ];
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
} ''
|
2018-01-12 04:32:56 +00:00
|
|
|
|
mkdir -p $out/EFI/boot/
|
|
|
|
|
|
2021-05-23 00:01:07 +00:00
|
|
|
|
# Add a marker so GRUB can find the filesystem.
|
|
|
|
|
touch $out/EFI/nixos-installer-image
|
|
|
|
|
|
2018-12-02 05:34:58 +00:00
|
|
|
|
# ALWAYS required modules.
|
2023-08-14 20:49:47 +00:00
|
|
|
|
MODULES=(
|
|
|
|
|
# Basic modules for filesystems and partition schemes
|
|
|
|
|
"fat"
|
|
|
|
|
"iso9660"
|
|
|
|
|
"part_gpt"
|
|
|
|
|
"part_msdos"
|
|
|
|
|
|
|
|
|
|
# Basic stuff
|
|
|
|
|
"normal"
|
|
|
|
|
"boot"
|
|
|
|
|
"linux"
|
|
|
|
|
"configfile"
|
|
|
|
|
"loopback"
|
|
|
|
|
"chain"
|
|
|
|
|
"halt"
|
|
|
|
|
|
|
|
|
|
# Allows rebooting into firmware setup interface
|
|
|
|
|
"efifwsetup"
|
|
|
|
|
|
|
|
|
|
# EFI Graphics Output Protocol
|
|
|
|
|
"efi_gop"
|
|
|
|
|
|
|
|
|
|
# User commands
|
|
|
|
|
"ls"
|
|
|
|
|
|
|
|
|
|
# System commands
|
|
|
|
|
"search"
|
|
|
|
|
"search_label"
|
|
|
|
|
"search_fs_uuid"
|
|
|
|
|
"search_fs_file"
|
|
|
|
|
"echo"
|
2023-08-14 23:43:20 +00:00
|
|
|
|
|
|
|
|
|
# We're not using it anymore, but we'll leave it in so it can be used
|
|
|
|
|
# by user, with the console using "C"
|
2023-08-14 20:49:47 +00:00
|
|
|
|
"serial"
|
|
|
|
|
|
|
|
|
|
# Graphical mode stuff
|
|
|
|
|
"gfxmenu"
|
|
|
|
|
"gfxterm"
|
|
|
|
|
"gfxterm_background"
|
|
|
|
|
"gfxterm_menu"
|
|
|
|
|
"test"
|
|
|
|
|
"loadenv"
|
|
|
|
|
"all_video"
|
|
|
|
|
"videoinfo"
|
|
|
|
|
|
|
|
|
|
# File types for graphical mode
|
|
|
|
|
"png"
|
|
|
|
|
)
|
2018-12-02 05:34:58 +00:00
|
|
|
|
|
|
|
|
|
echo "Building GRUB with modules:"
|
2023-08-14 20:49:47 +00:00
|
|
|
|
for mod in ''${MODULES[@]}; do
|
2018-12-02 05:34:58 +00:00
|
|
|
|
echo " - $mod"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Modules that may or may not be available per-platform.
|
|
|
|
|
echo "Adding additional modules:"
|
|
|
|
|
for mod in efi_uga; do
|
2019-01-28 11:00:58 +00:00
|
|
|
|
if [ -f ${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget}/$mod.mod ]; then
|
2018-12-02 05:34:58 +00:00
|
|
|
|
echo " - $mod"
|
2023-08-14 20:49:47 +00:00
|
|
|
|
MODULES+=("$mod")
|
2018-12-02 05:34:58 +00:00
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Make our own efi program, we can't rely on "grub-install" since it seems to
|
|
|
|
|
# probe for devices, even with --skip-fs-probe.
|
2023-08-14 20:49:47 +00:00
|
|
|
|
grub-mkimage \
|
|
|
|
|
--directory=${grubPkgs.grub2_efi}/lib/grub/${grubPkgs.grub2_efi.grubTarget} \
|
|
|
|
|
-o $out/EFI/boot/boot${targetArch}.efi \
|
|
|
|
|
-p /EFI/boot \
|
|
|
|
|
-O ${grubPkgs.grub2_efi.grubTarget} \
|
|
|
|
|
''${MODULES[@]}
|
2019-01-28 11:00:58 +00:00
|
|
|
|
cp ${grubPkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/
|
2018-01-12 04:32:56 +00:00
|
|
|
|
|
|
|
|
|
cat <<EOF > $out/EFI/boot/grub.cfg
|
|
|
|
|
|
2023-08-14 22:11:31 +00:00
|
|
|
|
set textmode=${boolToString (config.isoImage.forceTextMode)}
|
2022-12-05 18:46:59 +00:00
|
|
|
|
set timeout=${toString grubEfiTimeout}
|
2021-04-20 05:34:15 +00:00
|
|
|
|
|
2023-08-14 23:43:20 +00:00
|
|
|
|
clear
|
2023-08-14 21:00:34 +00:00
|
|
|
|
# This message will only be viewable on the default (UEFI) console.
|
2021-04-20 05:34:15 +00:00
|
|
|
|
echo ""
|
|
|
|
|
echo "Loading graphical boot menu..."
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Press 't' to use the text boot menu on this console..."
|
|
|
|
|
echo ""
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
|
2021-04-20 05:34:15 +00:00
|
|
|
|
hiddenentry 'Text mode' --hotkey 't' {
|
2021-05-22 21:07:36 +00:00
|
|
|
|
loadfont (\$root)/EFI/boot/unicode.pf2
|
2021-04-20 05:34:15 +00:00
|
|
|
|
set textmode=true
|
2023-08-14 21:00:34 +00:00
|
|
|
|
terminal_output console
|
2021-04-20 05:34:15 +00:00
|
|
|
|
}
|
|
|
|
|
hiddenentry 'GUI mode' --hotkey 'g' {
|
2021-05-22 21:07:36 +00:00
|
|
|
|
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (\$root)/EFI/boot/grub-theme/%P\n")
|
2021-04-20 05:34:15 +00:00
|
|
|
|
set textmode=false
|
|
|
|
|
terminal_output gfxterm
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-09-21 15:08:00 +00:00
|
|
|
|
# If the parameter iso_path is set, append the findiso parameter to the kernel
|
|
|
|
|
# line. We need this to allow the nixos iso to be booted from grub directly.
|
|
|
|
|
if [ \''${iso_path} ] ; then
|
|
|
|
|
set isoboot="findiso=\''${iso_path}"
|
|
|
|
|
fi
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
#
|
|
|
|
|
# Menu entries
|
|
|
|
|
#
|
|
|
|
|
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuGrub2}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
submenu "HiDPI, Quirks and Accessibility" --class hidpi --class submenu {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
submenu "Suggests resolution @720p" --class hidpi-720p {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "video=1280x720@60"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
submenu "Suggests resolution @1080p" --class hidpi-1080p {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "video=1920x1080@60"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-28 21:21:57 +00:00
|
|
|
|
# If we boot into a graphical environment where X is autoran
|
|
|
|
|
# and always crashes, it makes the media unusable. Allow the user
|
|
|
|
|
# to disable this.
|
|
|
|
|
submenu "Disable display-manager" --class quirk-disable-displaymanager {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "systemd.mask=display-manager.service"}
|
2019-09-28 21:21:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
# Some laptop and convertibles have the panel installed in an
|
|
|
|
|
# inconvenient way, rotated away from the keyboard.
|
|
|
|
|
# Those entries makes it easier to use the installer.
|
|
|
|
|
submenu "" {return}
|
|
|
|
|
submenu "Rotate framebuffer Clockwise" --class rotate-90cw {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:1"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
submenu "Rotate framebuffer Upside-Down" --class rotate-180 {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:2"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
submenu "Rotate framebuffer Counter-Clockwise" --class rotate-90ccw {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "fbcon=rotate:3"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# As a proof of concept, mainly. (Not sure it has accessibility merits.)
|
|
|
|
|
submenu "" {return}
|
|
|
|
|
submenu "Use black on white" --class accessibility-blakconwhite {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "vt.default_red=0xFF,0xBC,0x4F,0xB4,0x56,0xBC,0x4F,0x00,0xA1,0xCF,0x84,0xCA,0x8D,0xB4,0x84,0x68 vt.default_grn=0xFF,0x55,0xBA,0xBA,0x4D,0x4D,0xB3,0x00,0xA0,0x8F,0xB3,0xCA,0x88,0x93,0xA4,0x68 vt.default_blu=0xFF,0x58,0x5F,0x58,0xC5,0xBD,0xC5,0x00,0xA8,0xBB,0xAB,0x97,0xBD,0xC7,0xC5,0x68"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Serial access is a must!
|
|
|
|
|
submenu "" {return}
|
|
|
|
|
submenu "Serial console=ttyS0,115200n8" --class serial {
|
|
|
|
|
${grubMenuCfg}
|
2022-09-29 10:22:51 +00:00
|
|
|
|
${buildMenuAdditionalParamsGrub2 "console=ttyS0,115200n8"}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 21:03:15 +00:00
|
|
|
|
${lib.optionalString (refindBinary != null) ''
|
2021-04-20 21:11:21 +00:00
|
|
|
|
# GRUB apparently cannot do "chainloader" operations on "CD".
|
|
|
|
|
if [ "\$root" != "cd0" ]; then
|
|
|
|
|
menuentry 'rEFInd' --class refind {
|
2022-03-26 19:45:12 +00:00
|
|
|
|
# Force root to be the FAT partition
|
|
|
|
|
# Otherwise it breaks rEFInd's boot
|
|
|
|
|
search --set=root --no-floppy --fs-uuid 1234-5678
|
2021-04-20 21:11:21 +00:00
|
|
|
|
chainloader (\$root)/EFI/boot/${refindBinary}
|
|
|
|
|
}
|
|
|
|
|
fi
|
2021-04-20 21:03:15 +00:00
|
|
|
|
''}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
menuentry 'Firmware Setup' --class settings {
|
|
|
|
|
fwsetup
|
|
|
|
|
clear
|
|
|
|
|
echo ""
|
|
|
|
|
echo "If you see this message, your EFI system doesn't support this feature."
|
|
|
|
|
echo ""
|
|
|
|
|
}
|
|
|
|
|
menuentry 'Shutdown' --class shutdown {
|
|
|
|
|
halt
|
|
|
|
|
}
|
2017-09-23 17:46:45 +00:00
|
|
|
|
EOF
|
2018-01-11 02:14:52 +00:00
|
|
|
|
|
2023-08-14 21:02:23 +00:00
|
|
|
|
grub-script-check $out/EFI/boot/grub.cfg
|
|
|
|
|
|
2018-01-11 02:14:52 +00:00
|
|
|
|
${refind}
|
2013-11-14 23:18:27 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2021-05-03 19:52:22 +00:00
|
|
|
|
efiImg = pkgs.runCommand "efi-image_eltorito" {
|
|
|
|
|
nativeBuildInputs = [ pkgs.buildPackages.mtools pkgs.buildPackages.libfaketime pkgs.buildPackages.dosfstools ];
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
}
|
2015-03-24 21:34:28 +00:00
|
|
|
|
# Be careful about determinism: du --apparent-size,
|
2019-04-01 16:17:42 +00:00
|
|
|
|
# dates (cp -p, touch, mcopy -m, faketime for label), IDs (mkfs.vfat -i)
|
2013-09-04 11:05:09 +00:00
|
|
|
|
''
|
2015-03-24 21:34:28 +00:00
|
|
|
|
mkdir ./contents && cd ./contents
|
2022-03-26 19:45:12 +00:00
|
|
|
|
mkdir -p ./EFI/boot
|
|
|
|
|
cp -rp "${efiDir}"/EFI/boot/{grub.cfg,*.efi} ./EFI/boot
|
2021-05-22 22:38:31 +00:00
|
|
|
|
|
|
|
|
|
# Rewrite dates for everything in the FS
|
|
|
|
|
find . -exec touch --date=2000-01-01 {} +
|
2015-03-24 21:34:28 +00:00
|
|
|
|
|
2021-05-20 18:01:17 +00:00
|
|
|
|
# Round up to the nearest multiple of 1MB, for more deterministic du output
|
|
|
|
|
usage_size=$(( $(du -s --block-size=1M --apparent-size . | tr -cd '[:digit:]') * 1024 * 1024 ))
|
2015-03-24 21:34:28 +00:00
|
|
|
|
# Make the image 110% as big as the files need to make up for FAT overhead
|
|
|
|
|
image_size=$(( ($usage_size * 110) / 100 ))
|
|
|
|
|
# Make the image fit blocks of 1M
|
|
|
|
|
block_size=$((1024*1024))
|
|
|
|
|
image_size=$(( ($image_size / $block_size + 1) * $block_size ))
|
|
|
|
|
echo "Usage size: $usage_size"
|
|
|
|
|
echo "Image size: $image_size"
|
|
|
|
|
truncate --size=$image_size "$out"
|
2021-12-05 23:13:53 +00:00
|
|
|
|
mkfs.vfat --invariant -i 12345678 -n EFIBOOT "$out"
|
2021-04-16 17:15:25 +00:00
|
|
|
|
|
|
|
|
|
# Force a fixed order in mcopy for better determinism, and avoid file globbing
|
2022-03-26 19:45:12 +00:00
|
|
|
|
for d in $(find EFI -type d | sort); do
|
2021-04-16 17:15:25 +00:00
|
|
|
|
faketime "2000-01-01 00:00:00" mmd -i "$out" "::/$d"
|
|
|
|
|
done
|
|
|
|
|
|
2022-03-26 19:45:12 +00:00
|
|
|
|
for f in $(find EFI -type f | sort); do
|
2021-04-16 17:15:25 +00:00
|
|
|
|
mcopy -pvm -i "$out" "$f" "::/$f"
|
|
|
|
|
done
|
|
|
|
|
|
2018-11-29 00:09:02 +00:00
|
|
|
|
# Verify the FAT partition.
|
2021-04-22 19:55:44 +00:00
|
|
|
|
fsck.vfat -vn "$out"
|
2014-05-21 12:06:31 +00:00
|
|
|
|
''; # */
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
2009-06-09 12:01:31 +00:00
|
|
|
|
options = {
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.isoName = mkOption {
|
2015-04-28 03:10:53 +00:00
|
|
|
|
default = "${config.isoImage.isoBaseName}.iso";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.str;
|
2009-06-09 15:23:03 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Name of the generated ISO image file.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-20 10:48:52 +00:00
|
|
|
|
isoImage.isoBaseName = mkOption {
|
2022-12-17 23:00:58 +00:00
|
|
|
|
default = config.system.nixos.distroId;
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.str;
|
2011-04-20 10:48:52 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Prefix of the name of the generated ISO image file.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.compressImage = mkOption {
|
2009-06-09 15:23:03 +00:00
|
|
|
|
default = false;
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.bool;
|
2009-06-09 15:23:03 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Whether the ISO image should be compressed using
|
2020-04-24 16:12:42 +00:00
|
|
|
|
{command}`zstd`.
|
2009-06-09 15:23:03 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-04 13:22:40 +00:00
|
|
|
|
isoImage.squashfsCompression = mkOption {
|
2023-05-08 11:50:06 +00:00
|
|
|
|
default = with pkgs.stdenv.hostPlatform; "xz -Xdict-size 100% "
|
2022-07-30 16:21:10 +00:00
|
|
|
|
+ lib.optionalString isx86 "-Xbcj x86"
|
2021-01-10 09:03:50 +00:00
|
|
|
|
# Untested but should also reduce size for these platforms
|
2022-07-30 16:18:27 +00:00
|
|
|
|
+ lib.optionalString isAarch "-Xbcj arm"
|
2022-04-10 08:59:20 +00:00
|
|
|
|
+ lib.optionalString (isPower && is32bit && isBigEndian) "-Xbcj powerpc"
|
2021-01-10 09:03:50 +00:00
|
|
|
|
+ lib.optionalString (isSparc) "-Xbcj sparc";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.str;
|
2020-08-04 13:22:40 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Compression settings to use for the squashfs nix store.
|
|
|
|
|
'';
|
|
|
|
|
example = "zstd -Xcompression-level 6";
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-10 00:06:32 +00:00
|
|
|
|
isoImage.edition = mkOption {
|
|
|
|
|
default = "";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.str;
|
2020-04-10 00:06:32 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Specifies which edition string to use in the volume ID of the generated
|
|
|
|
|
ISO image.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.volumeID = mkOption {
|
2020-04-10 00:06:32 +00:00
|
|
|
|
# nixos-$EDITION-$RELEASE-$ARCH
|
2020-04-10 00:10:01 +00:00
|
|
|
|
default = "nixos${optionalString (config.isoImage.edition != "") "-${config.isoImage.edition}"}-${config.system.nixos.release}-${pkgs.stdenv.hostPlatform.uname.processor}";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.str;
|
2009-06-09 15:23:03 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Specifies the label or volume ID of the generated ISO image.
|
|
|
|
|
Note that the label is used by stage 1 of the boot process to
|
|
|
|
|
mount the CD, so it should be reasonably distinctive.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.contents = mkOption {
|
2021-10-03 16:06:03 +00:00
|
|
|
|
example = literalExpression ''
|
2009-06-09 12:01:31 +00:00
|
|
|
|
[ { source = pkgs.memtest86 + "/memtest.bin";
|
|
|
|
|
target = "boot/memtest.bin";
|
|
|
|
|
}
|
2014-08-27 21:41:15 +00:00
|
|
|
|
]
|
|
|
|
|
'';
|
2009-06-09 12:01:31 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2009-06-09 13:27:50 +00:00
|
|
|
|
This option lists files to be copied to fixed locations in the
|
|
|
|
|
generated ISO image.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.storeContents = mkOption {
|
2021-10-03 16:06:03 +00:00
|
|
|
|
example = literalExpression "[ pkgs.stdenv ]";
|
2009-06-09 13:27:50 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
This option lists additional derivations to be included in the
|
|
|
|
|
Nix store in the generated ISO image.
|
2009-06-09 12:01:31 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2010-08-29 12:11:31 +00:00
|
|
|
|
isoImage.includeSystemBuildDependencies = mkOption {
|
|
|
|
|
default = false;
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.bool;
|
2010-08-29 12:11:31 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Set this option to include all the needed sources etc in the
|
|
|
|
|
image. It significantly increases image size. Use that when
|
|
|
|
|
you want to be able to keep all the sources needed to build your
|
|
|
|
|
system or when you are going to install the system on a computer
|
2016-12-30 11:29:43 +00:00
|
|
|
|
with slow or non-existent network connection.
|
2010-08-29 12:11:31 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-02 23:31:38 +00:00
|
|
|
|
isoImage.makeBiosBootable = mkOption {
|
2023-05-22 21:51:21 +00:00
|
|
|
|
# Before this option was introduced, images were BIOS-bootable if the
|
|
|
|
|
# hostPlatform was x86-based. This option is enabled by default for
|
|
|
|
|
# backwards compatibility.
|
|
|
|
|
#
|
|
|
|
|
# Also note that syslinux package currently cannot be cross-compiled from
|
|
|
|
|
# non-x86 platforms, so the default is false on non-x86 build platforms.
|
|
|
|
|
default = pkgs.stdenv.buildPlatform.isx86 && pkgs.stdenv.hostPlatform.isx86;
|
|
|
|
|
defaultText = lib.literalMD ''
|
|
|
|
|
`true` if both build and host platforms are x86-based architectures,
|
|
|
|
|
e.g. i686 and x86_64.
|
|
|
|
|
'';
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.bool;
|
2023-03-02 23:31:38 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Whether the ISO image should be a BIOS-bootable disk.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-16 05:37:24 +00:00
|
|
|
|
isoImage.makeEfiBootable = mkOption {
|
|
|
|
|
default = false;
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.bool;
|
2012-03-16 05:37:24 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2023-03-09 16:05:51 +00:00
|
|
|
|
Whether the ISO image should be an EFI-bootable volume.
|
2012-03-16 05:37:24 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-26 20:29:04 +00:00
|
|
|
|
isoImage.makeUsbBootable = mkOption {
|
|
|
|
|
default = false;
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = lib.types.bool;
|
2014-10-26 20:29:04 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Whether the ISO image should be bootable from CD as well as USB.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
isoImage.efiSplashImage = mkOption {
|
|
|
|
|
default = pkgs.fetchurl {
|
2020-04-01 01:11:51 +00:00
|
|
|
|
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/efi-background.png";
|
2018-01-12 04:32:56 +00:00
|
|
|
|
sha256 = "18lfwmp8yq923322nlb9gxrh5qikj1wsk6g5qvdh31c4h5b1538x";
|
|
|
|
|
};
|
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
The splash image to use in the EFI bootloader.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-26 20:29:04 +00:00
|
|
|
|
isoImage.splashImage = mkOption {
|
|
|
|
|
default = pkgs.fetchurl {
|
2020-04-01 01:11:51 +00:00
|
|
|
|
url = "https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/isolinux/bios-boot.png";
|
2018-01-08 03:09:42 +00:00
|
|
|
|
sha256 = "1wp822zrhbg4fgfbwkr7cbkr4labx477209agzc0hr6k62fr6rxd";
|
2014-10-26 20:29:04 +00:00
|
|
|
|
};
|
|
|
|
|
description = lib.mdDoc ''
|
2018-01-12 04:32:56 +00:00
|
|
|
|
The splash image to use in the legacy-boot bootloader.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isoImage.grubTheme = mkOption {
|
|
|
|
|
default = pkgs.nixos-grub2-theme;
|
|
|
|
|
type = types.nullOr (types.either types.path types.package);
|
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
The grub2 theme used for UEFI boot.
|
2014-10-26 20:29:04 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-03-16 05:37:24 +00:00
|
|
|
|
|
2022-02-15 15:02:23 +00:00
|
|
|
|
isoImage.syslinuxTheme = mkOption {
|
|
|
|
|
default = ''
|
2022-12-17 23:00:58 +00:00
|
|
|
|
MENU TITLE ${config.system.nixos.distroName}
|
2022-02-15 15:02:23 +00:00
|
|
|
|
MENU RESOLUTION 800 600
|
|
|
|
|
MENU CLEAR
|
|
|
|
|
MENU ROWS 6
|
|
|
|
|
MENU CMDLINEROW -4
|
|
|
|
|
MENU TIMEOUTROW -3
|
|
|
|
|
MENU TABMSGROW -2
|
|
|
|
|
MENU HELPMSGROW -1
|
|
|
|
|
MENU HELPMSGENDROW -1
|
|
|
|
|
MENU MARGIN 0
|
|
|
|
|
|
|
|
|
|
# FG:AARRGGBB BG:AARRGGBB shadow
|
|
|
|
|
MENU COLOR BORDER 30;44 #00000000 #00000000 none
|
|
|
|
|
MENU COLOR SCREEN 37;40 #FF000000 #00E2E8FF none
|
|
|
|
|
MENU COLOR TABMSG 31;40 #80000000 #00000000 none
|
|
|
|
|
MENU COLOR TIMEOUT 1;37;40 #FF000000 #00000000 none
|
|
|
|
|
MENU COLOR TIMEOUT_MSG 37;40 #FF000000 #00000000 none
|
|
|
|
|
MENU COLOR CMDMARK 1;36;40 #FF000000 #00000000 none
|
|
|
|
|
MENU COLOR CMDLINE 37;40 #FF000000 #00000000 none
|
|
|
|
|
MENU COLOR TITLE 1;36;44 #00000000 #00000000 none
|
|
|
|
|
MENU COLOR UNSEL 37;44 #FF000000 #00000000 none
|
|
|
|
|
MENU COLOR SEL 7;37;40 #FFFFFFFF #FF5277C3 std
|
|
|
|
|
'';
|
|
|
|
|
type = types.str;
|
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
The syslinux theme used for BIOS boot.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-28 18:35:58 +00:00
|
|
|
|
isoImage.prependToMenuLabel = mkOption {
|
|
|
|
|
default = "";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = types.str;
|
2023-03-28 18:35:58 +00:00
|
|
|
|
example = "Install ";
|
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
The string to prepend before the menu label for the NixOS system.
|
|
|
|
|
This will be directly prepended (without whitespace) to the NixOS version
|
|
|
|
|
string, like for example if it is set to `XXX`:
|
|
|
|
|
|
|
|
|
|
`XXXNixOS 99.99-pre666`
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-28 21:26:54 +00:00
|
|
|
|
isoImage.appendToMenuLabel = mkOption {
|
|
|
|
|
default = " Installer";
|
2023-04-07 09:30:28 +00:00
|
|
|
|
type = types.str;
|
2015-06-28 21:26:54 +00:00
|
|
|
|
example = " Live System";
|
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
The string to append after the menu label for the NixOS system.
|
|
|
|
|
This will be directly appended (without whitespace) to the NixOS version
|
|
|
|
|
string, like for example if it is set to `XXX`:
|
|
|
|
|
|
|
|
|
|
`NixOS 99.99-pre666XXX`
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-14 22:11:31 +00:00
|
|
|
|
isoImage.forceTextMode = mkOption {
|
|
|
|
|
default = false;
|
2023-06-23 14:57:03 +00:00
|
|
|
|
type = types.bool;
|
|
|
|
|
example = true;
|
|
|
|
|
description = lib.mdDoc ''
|
2023-08-14 22:11:31 +00:00
|
|
|
|
Whether to use text mode instead of graphical grub.
|
|
|
|
|
A value of `true` means graphical mode is not tried to be used.
|
|
|
|
|
|
|
|
|
|
This is useful for validating that graphics mode usage is not at the root cause of a problem with the iso image.
|
|
|
|
|
|
|
|
|
|
If text mode is required off-handedly (e.g. for serial use) you can use the `T` key, after being prompted, to use text mode for the current boot.
|
2023-06-23 14:57:03 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-09 12:01:31 +00:00
|
|
|
|
};
|
2021-08-03 22:12:03 +00:00
|
|
|
|
|
|
|
|
|
# store them in lib so we can mkImageMediaOverride the
|
|
|
|
|
# entire file system layout in installation media (only)
|
2021-08-03 19:36:07 +00:00
|
|
|
|
config.lib.isoFileSystems = {
|
2021-08-03 22:12:03 +00:00
|
|
|
|
"/" = mkImageMediaOverride
|
2021-08-03 19:36:07 +00:00
|
|
|
|
{
|
|
|
|
|
fsType = "tmpfs";
|
|
|
|
|
options = [ "mode=0755" ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Note that /dev/root is a symlink to the actual root device
|
|
|
|
|
# specified on the kernel command line, created in the stage 1
|
|
|
|
|
# init script.
|
2021-08-03 22:12:03 +00:00
|
|
|
|
"/iso" = mkImageMediaOverride
|
2021-08-03 19:36:07 +00:00
|
|
|
|
{ device = "/dev/root";
|
|
|
|
|
neededForBoot = true;
|
|
|
|
|
noCheck = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs
|
|
|
|
|
# image) to make this a live CD.
|
2021-08-03 22:12:03 +00:00
|
|
|
|
"/nix/.ro-store" = mkImageMediaOverride
|
2021-08-03 19:36:07 +00:00
|
|
|
|
{ fsType = "squashfs";
|
|
|
|
|
device = "/iso/nix-store.squashfs";
|
|
|
|
|
options = [ "loop" ];
|
|
|
|
|
neededForBoot = true;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-03 22:12:03 +00:00
|
|
|
|
"/nix/.rw-store" = mkImageMediaOverride
|
2021-08-03 19:36:07 +00:00
|
|
|
|
{ fsType = "tmpfs";
|
|
|
|
|
options = [ "mode=0755" ];
|
|
|
|
|
neededForBoot = true;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-03 22:12:03 +00:00
|
|
|
|
"/nix/store" = mkImageMediaOverride
|
2021-08-03 19:36:07 +00:00
|
|
|
|
{ fsType = "overlay";
|
|
|
|
|
device = "overlay";
|
|
|
|
|
options = [
|
|
|
|
|
"lowerdir=/nix/.ro-store"
|
|
|
|
|
"upperdir=/nix/.rw-store/store"
|
|
|
|
|
"workdir=/nix/.rw-store/work"
|
|
|
|
|
];
|
|
|
|
|
depends = [
|
|
|
|
|
"/nix/.ro-store"
|
|
|
|
|
"/nix/.rw-store/store"
|
|
|
|
|
"/nix/.rw-store/work"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
2009-06-09 12:01:31 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
config = {
|
2020-04-10 00:06:32 +00:00
|
|
|
|
assertions = [
|
2023-05-22 21:51:21 +00:00
|
|
|
|
{
|
|
|
|
|
# Syslinux (and isolinux) only supports x86-based architectures.
|
|
|
|
|
assertion = config.isoImage.makeBiosBootable -> pkgs.stdenv.hostPlatform.isx86;
|
|
|
|
|
message = "BIOS boot is only supported on x86-based architectures.";
|
|
|
|
|
}
|
2020-04-10 00:06:32 +00:00
|
|
|
|
{
|
|
|
|
|
assertion = !(stringLength config.isoImage.volumeID > 32);
|
|
|
|
|
# https://wiki.osdev.org/ISO_9660#The_Primary_Volume_Descriptor
|
|
|
|
|
# Volume Identifier can only be 32 bytes
|
|
|
|
|
message = let
|
|
|
|
|
length = stringLength config.isoImage.volumeID;
|
|
|
|
|
howmany = toString length;
|
|
|
|
|
toomany = toString (length - 32);
|
|
|
|
|
in
|
|
|
|
|
"isoImage.volumeID ${config.isoImage.volumeID} is ${howmany} characters. That is ${toomany} characters longer than the limit of 32.";
|
|
|
|
|
}
|
|
|
|
|
];
|
2009-11-10 21:42:38 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Don't build the GRUB menu builder script, since we don't need it
|
|
|
|
|
# here and it causes a cyclic dependency.
|
|
|
|
|
boot.loader.grub.enable = false;
|
2009-11-13 16:45:41 +00:00
|
|
|
|
|
2019-01-28 11:00:58 +00:00
|
|
|
|
environment.systemPackages = [ grubPkgs.grub2 grubPkgs.grub2_efi ]
|
2023-05-22 21:51:21 +00:00
|
|
|
|
++ optional (config.isoImage.makeBiosBootable) pkgs.syslinux
|
2018-12-02 05:34:58 +00:00
|
|
|
|
;
|
2009-11-13 16:45:41 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# In stage 1 of the boot, mount the CD as the root FS by label so
|
|
|
|
|
# that we don't need to know its device. We pass the label of the
|
|
|
|
|
# root filesystem on the kernel command line, rather than in
|
|
|
|
|
# `fileSystems' below. This allows CD-to-USB converters such as
|
|
|
|
|
# UNetbootin to rewrite the kernel command line to pass the label or
|
|
|
|
|
# UUID of the USB stick. It would be nicer to write
|
|
|
|
|
# `root=/dev/disk/by-label/...' here, but UNetbootin doesn't
|
|
|
|
|
# recognise that.
|
2014-11-14 23:14:26 +00:00
|
|
|
|
boot.kernelParams =
|
|
|
|
|
[ "root=LABEL=${config.isoImage.volumeID}"
|
|
|
|
|
"boot.shell_on_fail"
|
|
|
|
|
];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
|
2021-08-03 19:36:07 +00:00
|
|
|
|
fileSystems = config.lib.isoFileSystems;
|
2014-07-30 13:44:47 +00:00
|
|
|
|
|
2020-02-05 18:27:16 +00:00
|
|
|
|
boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "uas" "overlay" ];
|
2012-03-16 05:37:24 +00:00
|
|
|
|
|
2020-02-05 18:27:16 +00:00
|
|
|
|
boot.initrd.kernelModules = [ "loop" "overlay" ];
|
2012-03-16 05:37:24 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Closures to be copied to the Nix store on the CD, namely the init
|
|
|
|
|
# script and the top-level system configuration directory.
|
|
|
|
|
isoImage.storeContents =
|
|
|
|
|
[ config.system.build.toplevel ] ++
|
|
|
|
|
optional config.isoImage.includeSystemBuildDependencies
|
|
|
|
|
config.system.build.toplevel.drvPath;
|
|
|
|
|
|
|
|
|
|
# Create the squashfs image that contains the Nix store.
|
2018-02-07 15:50:47 +00:00
|
|
|
|
system.build.squashfsStore = pkgs.callPackage ../../../lib/make-squashfs.nix {
|
2013-09-04 11:05:09 +00:00
|
|
|
|
storeContents = config.isoImage.storeContents;
|
2020-08-04 13:22:40 +00:00
|
|
|
|
comp = config.isoImage.squashfsCompression;
|
2013-09-04 11:05:09 +00:00
|
|
|
|
};
|
2010-01-09 15:13:06 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Individual files to be included on the CD, outside of the Nix
|
|
|
|
|
# store on the CD.
|
|
|
|
|
isoImage.contents =
|
2018-12-02 05:34:58 +00:00
|
|
|
|
[
|
2015-11-15 00:00:00 +00:00
|
|
|
|
{ source = config.boot.kernelPackages.kernel + "/" + config.system.boot.loader.kernelFile;
|
|
|
|
|
target = "/boot/" + config.system.boot.loader.kernelFile;
|
2013-09-04 11:05:09 +00:00
|
|
|
|
}
|
2015-11-15 00:00:00 +00:00
|
|
|
|
{ source = config.system.build.initialRamdisk + "/" + config.system.boot.loader.initrdFile;
|
|
|
|
|
target = "/boot/" + config.system.boot.loader.initrdFile;
|
2013-09-04 11:05:09 +00:00
|
|
|
|
}
|
2014-11-08 12:09:08 +00:00
|
|
|
|
{ source = config.system.build.squashfsStore;
|
|
|
|
|
target = "/nix-store.squashfs";
|
2014-10-26 20:29:04 +00:00
|
|
|
|
}
|
2017-04-01 00:00:00 +00:00
|
|
|
|
{ source = pkgs.writeText "version" config.system.nixos.label;
|
2017-09-26 20:17:01 +00:00
|
|
|
|
target = "/version.txt";
|
|
|
|
|
}
|
2023-05-22 21:51:21 +00:00
|
|
|
|
] ++ optionals (config.isoImage.makeBiosBootable) [
|
2022-01-03 22:20:00 +00:00
|
|
|
|
{ source = config.isoImage.splashImage;
|
|
|
|
|
target = "/isolinux/background.png";
|
|
|
|
|
}
|
2018-12-02 05:34:58 +00:00
|
|
|
|
{ source = pkgs.substituteAll {
|
|
|
|
|
name = "isolinux.cfg";
|
|
|
|
|
src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg;
|
|
|
|
|
bootRoot = "/boot";
|
|
|
|
|
};
|
|
|
|
|
target = "/isolinux/isolinux.cfg";
|
|
|
|
|
}
|
|
|
|
|
{ source = "${pkgs.syslinux}/share/syslinux";
|
|
|
|
|
target = "/isolinux";
|
|
|
|
|
}
|
2013-10-02 10:29:07 +00:00
|
|
|
|
] ++ optionals config.isoImage.makeEfiBootable [
|
2013-09-04 11:05:09 +00:00
|
|
|
|
{ source = efiImg;
|
|
|
|
|
target = "/boot/efi.img";
|
|
|
|
|
}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
{ source = "${efiDir}/EFI";
|
|
|
|
|
target = "/EFI";
|
2013-11-14 23:18:27 +00:00
|
|
|
|
}
|
2019-12-10 22:02:07 +00:00
|
|
|
|
{ source = (pkgs.writeTextDir "grub/loopback.cfg" "source /EFI/boot/grub.cfg") + "/grub";
|
|
|
|
|
target = "/boot/grub";
|
2019-09-21 15:08:00 +00:00
|
|
|
|
}
|
2022-01-03 22:20:00 +00:00
|
|
|
|
{ source = config.isoImage.efiSplashImage;
|
|
|
|
|
target = "/EFI/boot/efi-background.png";
|
|
|
|
|
}
|
2023-05-22 21:51:21 +00:00
|
|
|
|
] ++ optionals (config.boot.loader.grub.memtest86.enable && config.isoImage.makeBiosBootable) [
|
2015-01-21 13:00:18 +00:00
|
|
|
|
{ source = "${pkgs.memtest86plus}/memtest.bin";
|
|
|
|
|
target = "/boot/memtest.bin";
|
2014-11-08 12:09:08 +00:00
|
|
|
|
}
|
2019-04-24 03:48:22 +00:00
|
|
|
|
] ++ optionals (config.isoImage.grubTheme != null) [
|
2018-01-12 04:32:56 +00:00
|
|
|
|
{ source = config.isoImage.grubTheme;
|
|
|
|
|
target = "/EFI/boot/grub-theme";
|
|
|
|
|
}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
];
|
2014-11-08 12:09:08 +00:00
|
|
|
|
|
2014-11-16 19:11:56 +00:00
|
|
|
|
boot.loader.timeout = 10;
|
2009-06-05 13:35:27 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Create the ISO image.
|
2018-02-07 15:50:47 +00:00
|
|
|
|
system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({
|
2013-09-04 11:05:09 +00:00
|
|
|
|
inherit (config.isoImage) isoName compressImage volumeID contents;
|
2023-05-22 21:51:21 +00:00
|
|
|
|
bootable = config.isoImage.makeBiosBootable;
|
2014-10-26 20:29:04 +00:00
|
|
|
|
bootImage = "/isolinux/isolinux.bin";
|
2023-05-22 21:51:21 +00:00
|
|
|
|
syslinux = if config.isoImage.makeBiosBootable then pkgs.syslinux else null;
|
|
|
|
|
} // optionalAttrs (config.isoImage.makeUsbBootable && config.isoImage.makeBiosBootable) {
|
2014-10-26 20:29:04 +00:00
|
|
|
|
usbBootable = true;
|
|
|
|
|
isohybridMbrImage = "${pkgs.syslinux}/share/syslinux/isohdpfx.bin";
|
2013-10-02 10:29:07 +00:00
|
|
|
|
} // optionalAttrs config.isoImage.makeEfiBootable {
|
2013-09-04 11:05:09 +00:00
|
|
|
|
efiBootable = true;
|
|
|
|
|
efiBootImage = "boot/efi.img";
|
|
|
|
|
});
|
2009-06-09 12:01:31 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
boot.postBootCommands =
|
|
|
|
|
''
|
|
|
|
|
# After booting, register the contents of the Nix store on the
|
|
|
|
|
# CD in the Nix database in the tmpfs.
|
2016-04-24 10:57:19 +00:00
|
|
|
|
${config.nix.package.out}/bin/nix-store --load-db < /nix/store/nix-path-registration
|
2011-09-14 18:20:50 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# nixos-rebuild also requires a "system" profile and an
|
|
|
|
|
# /etc/NIXOS tag.
|
|
|
|
|
touch /etc/NIXOS
|
2016-04-24 10:57:19 +00:00
|
|
|
|
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system
|
2013-09-04 11:05:09 +00:00
|
|
|
|
'';
|
2009-06-05 13:35:27 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Add vfat support to the initrd to enable people to copy the
|
2014-07-30 13:44:47 +00:00
|
|
|
|
# contents of the CD to a bootable USB stick.
|
|
|
|
|
boot.initrd.supportedFilesystems = [ "vfat" ];
|
2009-06-05 16:02:58 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
};
|
2012-03-09 16:17:37 +00:00
|
|
|
|
|
2009-06-05 13:35:27 +00:00
|
|
|
|
}
|