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.
|
|
|
|
|
option.name or (if option ? params then "(${option.params})" else "")
|
|
|
|
|
}' ${if option ? class then " --class ${option.class}" else ""} {
|
|
|
|
|
linux ${defaults.image} ${defaults.params} ${
|
|
|
|
|
option.params or ""
|
|
|
|
|
}
|
|
|
|
|
initrd ${defaults.initrd}
|
|
|
|
|
}
|
|
|
|
|
'')
|
|
|
|
|
options
|
|
|
|
|
)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given a `config`, builds the default options.
|
|
|
|
|
*/
|
|
|
|
|
buildMenuGrub2 = config:
|
|
|
|
|
buildMenuAdditionalParamsGrub2 config ""
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given a `config` and params to add to `params`, build a set of default options.
|
|
|
|
|
* Use this one when creating a variant (e.g. hidpi)
|
|
|
|
|
*/
|
|
|
|
|
buildMenuAdditionalParamsGrub2 = config: additional:
|
|
|
|
|
let
|
|
|
|
|
finalCfg = {
|
|
|
|
|
name = "NixOS ${config.system.nixos.label}${config.isoImage.appendToMenuLabel}";
|
|
|
|
|
params = "init=${config.system.build.toplevel}/init ${additional} ${toString config.boot.kernelParams}";
|
|
|
|
|
image = "/boot/bzImage";
|
|
|
|
|
initrd = "/boot/initrd";
|
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
|
# 0 is used to disable timeouts.
|
|
|
|
|
syslinuxTimeout = if config.boot.loader.timeout == null then
|
|
|
|
|
0
|
|
|
|
|
else
|
|
|
|
|
max (config.boot.loader.timeout * 10) 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
max = x: y: if x > y then x else y;
|
2009-06-09 12:01:31 +00:00
|
|
|
|
|
2014-10-26 20:29:04 +00:00
|
|
|
|
# The configuration file for syslinux.
|
2014-11-16 19:13:11 +00:00
|
|
|
|
|
|
|
|
|
# Notes on syslinux configuration and UNetbootin compatiblity:
|
|
|
|
|
# * 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 = ''
|
2014-10-26 20:29:04 +00:00
|
|
|
|
SERIAL 0 38400
|
2014-11-16 19:11:56 +00:00
|
|
|
|
TIMEOUT ${builtins.toString syslinuxTimeout}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
UI vesamenu.c32
|
|
|
|
|
MENU TITLE NixOS
|
|
|
|
|
MENU BACKGROUND /isolinux/background.png
|
2018-01-08 03:09:42 +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
|
|
|
|
|
|
2014-11-16 19:11:56 +00:00
|
|
|
|
DEFAULT boot
|
2014-10-26 20:29:04 +00:00
|
|
|
|
|
|
|
|
|
LABEL boot
|
2017-04-01 00:00:00 +00:00
|
|
|
|
MENU LABEL NixOS ${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
|
2017-04-01 00:00:00 +00:00
|
|
|
|
MENU LABEL NixOS ${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
|
2017-04-01 00:00:00 +00:00
|
|
|
|
MENU LABEL NixOS ${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
|
2017-04-01 00:00:00 +00:00
|
|
|
|
MENU LABEL NixOS ${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}
|
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
|
|
|
|
|
2018-01-11 02:14:52 +00:00
|
|
|
|
# Setup instructions for rEFInd.
|
|
|
|
|
refind =
|
|
|
|
|
if targetArch == "x64" then
|
|
|
|
|
''
|
|
|
|
|
# Adds rEFInd to the ISO.
|
|
|
|
|
cp -v ${pkgs.refind}/share/refind/refind_x64.efi $out/EFI/boot/
|
|
|
|
|
''
|
|
|
|
|
else
|
|
|
|
|
"# No refind for ia32"
|
|
|
|
|
;
|
|
|
|
|
|
2018-01-12 04:32:56 +00:00
|
|
|
|
grubMenuCfg = ''
|
|
|
|
|
#
|
|
|
|
|
# Menu configuration
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
insmod gfxterm
|
|
|
|
|
insmod png
|
|
|
|
|
set gfxpayload=keep
|
|
|
|
|
|
|
|
|
|
# Fonts can be loaded?
|
|
|
|
|
# (This font is assumed to always be provided as a fallback by NixOS)
|
|
|
|
|
if loadfont (hd0)/EFI/boot/unicode.pf2; then
|
|
|
|
|
# Use graphical term, it can be either with background image or a theme.
|
|
|
|
|
# input is "console", while output is "gfxterm".
|
|
|
|
|
# This enables "serial" input and output only when possible.
|
|
|
|
|
# Otherwise the failure mode is to not even enable gfxterm.
|
|
|
|
|
if test "\$with_serial" == "yes"; then
|
|
|
|
|
terminal_output gfxterm serial
|
|
|
|
|
terminal_input console serial
|
|
|
|
|
else
|
|
|
|
|
terminal_output gfxterm
|
|
|
|
|
terminal_input console
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
# Sets colors for the non-graphical term.
|
|
|
|
|
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.
|
|
|
|
|
if (!isNull config.isoImage.grubTheme) then ''
|
|
|
|
|
# Sets theme.
|
|
|
|
|
set theme=(hd0)/EFI/boot/grub-theme/theme.txt
|
|
|
|
|
# Load theme fonts
|
|
|
|
|
$(find ${config.isoImage.grubTheme} -iname '*.pf2' -printf "loadfont (hd0)/EFI/boot/grub-theme/%P\n")
|
|
|
|
|
'' else ''
|
|
|
|
|
if background_image (hd0)/EFI/boot/efi-background.png; then
|
|
|
|
|
# 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*
|
2013-11-14 23:18:27 +00:00
|
|
|
|
efiDir = pkgs.runCommand "efi-directory" {} ''
|
2018-01-12 04:32:56 +00:00
|
|
|
|
mkdir -p $out/EFI/boot/
|
|
|
|
|
|
|
|
|
|
MODULES="fat iso9660 part_gpt part_msdos \
|
|
|
|
|
normal boot linux configfile loopback chain halt \
|
|
|
|
|
efifwsetup efi_gop efi_uga \
|
|
|
|
|
ls search search_label search_fs_uuid search_fs_file \
|
|
|
|
|
gfxmenu gfxterm gfxterm_background gfxterm_menu test all_video loadenv \
|
|
|
|
|
exfat ext2 ntfs btrfs hfsplus udf \
|
|
|
|
|
videoinfo png \
|
|
|
|
|
echo serial \
|
|
|
|
|
"
|
|
|
|
|
# Make our own efi program, we can't rely on "grub-install" since it seems to
|
|
|
|
|
# probe for devices, even with --skip-fs-probe.
|
2018-09-22 22:15:28 +00:00
|
|
|
|
${pkgs.grub2_efi}/bin/grub-mkimage -o $out/EFI/boot/${if targetArch == "x64" then "bootx64" else "bootia32"}.efi -p /EFI/boot -O ${if targetArch == "x64" then "x86_64" else "i386"}-efi \
|
2018-01-12 04:32:56 +00:00
|
|
|
|
$MODULES
|
|
|
|
|
cp ${pkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/
|
|
|
|
|
|
|
|
|
|
cat <<EOF > $out/EFI/boot/grub.cfg
|
|
|
|
|
|
|
|
|
|
# If you want to use serial for "terminal_*" commands, you need to set one up:
|
|
|
|
|
# Example manual configuration:
|
|
|
|
|
# → serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
|
|
|
|
|
# This uses the defaults, and makes the serial terminal available.
|
|
|
|
|
set with_serial=no
|
|
|
|
|
if serial; then set with_serial=yes ;fi
|
|
|
|
|
export with_serial
|
|
|
|
|
clear
|
|
|
|
|
set timeout=10
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Menu entries
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
${buildMenuGrub2 config}
|
|
|
|
|
submenu "HiDPI, Quirks and Accessibility" --class hidpi --class submenu {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
submenu "Suggests resolution @720p" --class hidpi-720p {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "video=1280x720@60"}
|
|
|
|
|
}
|
|
|
|
|
submenu "Suggests resolution @1080p" --class hidpi-1080p {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "video=1920x1080@60"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "fbcon=rotate:1"}
|
|
|
|
|
}
|
|
|
|
|
submenu "Rotate framebuffer Upside-Down" --class rotate-180 {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "fbcon=rotate:2"}
|
|
|
|
|
}
|
|
|
|
|
submenu "Rotate framebuffer Counter-Clockwise" --class rotate-90ccw {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "fbcon=rotate:3"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# As a proof of concept, mainly. (Not sure it has accessibility merits.)
|
|
|
|
|
submenu "" {return}
|
|
|
|
|
submenu "Use black on white" --class accessibility-blakconwhite {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "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"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Serial access is a must!
|
|
|
|
|
submenu "" {return}
|
|
|
|
|
submenu "Serial console=ttyS0,115200n8" --class serial {
|
|
|
|
|
${grubMenuCfg}
|
|
|
|
|
${buildMenuAdditionalParamsGrub2 config "console=ttyS0,115200n8"}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menuentry 'rEFInd' --class refind {
|
|
|
|
|
# UUID is hard-coded in the derivation.
|
|
|
|
|
search --set=root --no-floppy --fs-uuid 1234-5678
|
|
|
|
|
chainloader (\$root)/EFI/boot/refind_x64.efi
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
${refind}
|
2013-11-14 23:18:27 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2015-03-24 21:34:28 +00:00
|
|
|
|
efiImg = pkgs.runCommand "efi-image_eltorito" { buildInputs = [ pkgs.mtools pkgs.libfaketime ]; }
|
|
|
|
|
# Be careful about determinism: du --apparent-size,
|
|
|
|
|
# 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
|
|
|
|
|
cp -rp "${efiDir}"/* .
|
|
|
|
|
mkdir ./boot
|
2015-11-15 00:00:00 +00:00
|
|
|
|
cp -p "${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}" \
|
|
|
|
|
"${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}" ./boot/
|
2015-03-24 21:34:28 +00:00
|
|
|
|
touch --date=@0 ./*
|
|
|
|
|
|
|
|
|
|
usage_size=$(du -sb --apparent-size . | tr -cd '[:digit:]')
|
|
|
|
|
# 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"
|
|
|
|
|
${pkgs.libfaketime}/bin/faketime "2000-01-01 00:00:00" ${pkgs.dosfstools}/sbin/mkfs.vfat -i 12345678 -n EFIBOOT "$out"
|
|
|
|
|
mcopy -bpsvm -i "$out" ./* ::
|
2014-05-21 12:06:31 +00:00
|
|
|
|
''; # */
|
2013-09-04 11:05:09 +00:00
|
|
|
|
|
|
|
|
|
targetArch = if pkgs.stdenv.isi686 then
|
|
|
|
|
"ia32"
|
|
|
|
|
else if pkgs.stdenv.isx86_64 then
|
|
|
|
|
"x64"
|
|
|
|
|
else
|
|
|
|
|
throw "Unsupported architecture";
|
|
|
|
|
|
|
|
|
|
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";
|
2009-06-09 15:23:03 +00:00
|
|
|
|
description = ''
|
|
|
|
|
Name of the generated ISO image file.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-20 10:48:52 +00:00
|
|
|
|
isoImage.isoBaseName = mkOption {
|
|
|
|
|
default = "nixos";
|
|
|
|
|
description = ''
|
|
|
|
|
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;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether the ISO image should be compressed using
|
|
|
|
|
<command>bzip2</command>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-14 16:12:02 +00:00
|
|
|
|
isoImage.volumeID = mkOption {
|
2009-06-09 15:23:03 +00:00
|
|
|
|
default = "NIXOS_BOOT_CD";
|
|
|
|
|
description = ''
|
|
|
|
|
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 {
|
2014-08-27 21:41:15 +00:00
|
|
|
|
example = literalExample ''
|
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 = ''
|
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 {
|
2014-08-27 21:41:15 +00:00
|
|
|
|
example = literalExample "[ pkgs.stdenv ]";
|
2009-06-09 13:27:50 +00:00
|
|
|
|
description = ''
|
|
|
|
|
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;
|
|
|
|
|
description = ''
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-16 05:37:24 +00:00
|
|
|
|
isoImage.makeEfiBootable = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
2012-03-16 11:31:33 +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;
|
|
|
|
|
description = ''
|
|
|
|
|
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 {
|
|
|
|
|
url = https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/efi-background.png;
|
|
|
|
|
sha256 = "18lfwmp8yq923322nlb9gxrh5qikj1wsk6g5qvdh31c4h5b1538x";
|
|
|
|
|
};
|
|
|
|
|
description = ''
|
|
|
|
|
The splash image to use in the EFI bootloader.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-26 20:29:04 +00:00
|
|
|
|
isoImage.splashImage = mkOption {
|
|
|
|
|
default = pkgs.fetchurl {
|
2018-01-08 03:09:42 +00:00
|
|
|
|
url = https://raw.githubusercontent.com/NixOS/nixos-artwork/a9e05d7deb38a8e005a2b52575a3f59a63a4dba0/bootloader/isolinux/bios-boot.png;
|
|
|
|
|
sha256 = "1wp822zrhbg4fgfbwkr7cbkr4labx477209agzc0hr6k62fr6rxd";
|
2014-10-26 20:29:04 +00:00
|
|
|
|
};
|
|
|
|
|
description = ''
|
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 = ''
|
|
|
|
|
The grub2 theme used for UEFI boot.
|
2014-10-26 20:29:04 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-03-16 05:37:24 +00:00
|
|
|
|
|
2015-06-28 21:26:54 +00:00
|
|
|
|
isoImage.appendToMenuLabel = mkOption {
|
|
|
|
|
default = " Installer";
|
|
|
|
|
example = " Live System";
|
|
|
|
|
description = ''
|
|
|
|
|
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 <literal>XXX</literal>:
|
|
|
|
|
|
|
|
|
|
<para><literal>NixOS 99.99-pre666XXX</literal></para>
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-09 12:01:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
config = {
|
2009-11-10 21:42:38 +00:00
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
boot.loader.grub.version = 2;
|
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
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# !!! Hack - attributes expected by other modules.
|
|
|
|
|
system.boot.loader.kernelFile = "bzImage";
|
2015-07-06 02:11:56 +00:00
|
|
|
|
environment.systemPackages = [ pkgs.grub2 pkgs.grub2_efi pkgs.syslinux ];
|
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
|
|
|
|
|
2014-05-21 12:06:31 +00:00
|
|
|
|
fileSystems."/" =
|
|
|
|
|
{ fsType = "tmpfs";
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = [ "mode=0755" ];
|
2014-05-21 12:06:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
# Note that /dev/root is a symlink to the actual root device
|
2014-05-21 12:06:31 +00:00
|
|
|
|
# specified on the kernel command line, created in the stage 1
|
|
|
|
|
# init script.
|
|
|
|
|
fileSystems."/iso" =
|
|
|
|
|
{ device = "/dev/root";
|
|
|
|
|
neededForBoot = true;
|
|
|
|
|
noCheck = true;
|
|
|
|
|
};
|
2009-11-13 16:45:41 +00:00
|
|
|
|
|
2014-07-30 13:44:47 +00:00
|
|
|
|
# In stage 1, mount a tmpfs on top of /nix/store (the squashfs
|
|
|
|
|
# image) to make this a live CD.
|
2014-05-21 12:06:31 +00:00
|
|
|
|
fileSystems."/nix/.ro-store" =
|
2013-09-04 11:05:09 +00:00
|
|
|
|
{ fsType = "squashfs";
|
2014-05-21 12:06:31 +00:00
|
|
|
|
device = "/iso/nix-store.squashfs";
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = [ "loop" ];
|
2014-05-21 12:06:31 +00:00
|
|
|
|
neededForBoot = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fileSystems."/nix/.rw-store" =
|
|
|
|
|
{ fsType = "tmpfs";
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = [ "mode=0755" ];
|
2014-05-21 12:06:31 +00:00
|
|
|
|
neededForBoot = true;
|
2013-09-04 11:05:09 +00:00
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
|
2014-07-30 13:44:47 +00:00
|
|
|
|
fileSystems."/nix/store" =
|
|
|
|
|
{ fsType = "unionfs-fuse";
|
|
|
|
|
device = "unionfs";
|
2015-10-21 17:37:14 +00:00
|
|
|
|
options = [ "allow_other" "cow" "nonempty" "chroot=/mnt-root" "max_files=32768" "hide_meta_files" "dirs=/nix/.rw-store=rw:/nix/.ro-store=ro" ];
|
2014-07-30 13:44:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-08-23 01:42:21 +00:00
|
|
|
|
boot.initrd.availableKernelModules = [ "squashfs" "iso9660" "uas" ];
|
2012-03-16 05:37:24 +00:00
|
|
|
|
|
2015-07-25 17:03:52 +00:00
|
|
|
|
boot.blacklistedKernelModules = [ "nouveau" ];
|
|
|
|
|
|
2013-09-04 11:05:09 +00:00
|
|
|
|
boot.initrd.kernelModules = [ "loop" ];
|
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;
|
|
|
|
|
};
|
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 =
|
2014-10-26 20:29:04 +00:00
|
|
|
|
[ { source = pkgs.substituteAll {
|
|
|
|
|
name = "isolinux.cfg";
|
|
|
|
|
src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg;
|
2013-10-02 10:29:07 +00:00
|
|
|
|
bootRoot = "/boot";
|
|
|
|
|
};
|
2014-10-26 20:29:04 +00:00
|
|
|
|
target = "/isolinux/isolinux.cfg";
|
2013-09-04 11:05:09 +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
|
|
|
|
}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
{ source = "${pkgs.syslinux}/share/syslinux";
|
|
|
|
|
target = "/isolinux";
|
|
|
|
|
}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
{ source = config.isoImage.efiSplashImage;
|
|
|
|
|
target = "/EFI/boot/efi-background.png";
|
|
|
|
|
}
|
2014-10-26 20:29:04 +00:00
|
|
|
|
{ source = config.isoImage.splashImage;
|
|
|
|
|
target = "/isolinux/background.png";
|
|
|
|
|
}
|
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";
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2015-01-21 13:00:18 +00:00
|
|
|
|
] ++ optionals config.boot.loader.grub.memtest86.enable [
|
|
|
|
|
{ source = "${pkgs.memtest86plus}/memtest.bin";
|
|
|
|
|
target = "/boot/memtest.bin";
|
2014-11-08 12:09:08 +00:00
|
|
|
|
}
|
2018-01-12 04:32:56 +00:00
|
|
|
|
] ++ optionals (!isNull config.isoImage.grubTheme) [
|
|
|
|
|
{ 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;
|
|
|
|
|
bootable = true;
|
2014-10-26 20:29:04 +00:00
|
|
|
|
bootImage = "/isolinux/isolinux.bin";
|
|
|
|
|
} // optionalAttrs config.isoImage.makeUsbBootable {
|
|
|
|
|
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
|
|
|
|
}
|