@ -8,45 +8,39 @@ with lib;
let
# The Grub image .
grubImage = pkgs . runCommand " g r u b _ e l t o r i t o " { }
# The configuration file for syslinux .
baseIsolinuxCfg =
''
$ { pkgs . grub2 } /bin/grub-mkimage - p /boot/grub - O i386-pc - o tmp biosdisk iso9660 help linux linux16 chain png jpeg echo gfxmenu reboot
cat $ { pkgs . grub2 } /lib/grub /* / c d b o o t . i m g t m p > $ o u t
'' ; # * /
# The configuration file for Grub.
grubCfg =
''
set default = $ { builtins . toString config . boot . loader . grub . default }
set timeout = $ { builtins . toString config . boot . loader . grub . timeout }
if loadfont /boot/grub/unicode.pf2 ; then
set gfxmode = 6 4 0 x480
insmod gfxterm
insmod vbe
terminal_output gfxterm
insmod png
if background_image /boot/grub/splash.png ; then
set color_normal = white/black
set color_highlight = black/white
else
set menu_color_normal = cyan/blue
set menu_color_highlight = white/blue
fi
fi
$ { config . boot . loader . grub . extraEntries }
SERIAL 0 38400
UI vesamenu . c32
MENU TITLE NixOS
MENU BACKGROUND /isolinux/background.png
LABEL boot
MENU LABEL Boot NixOS
LINUX /boot/bzImage init = $ { config . system . build . toplevel } /init $ { toString config . boot . kernelParams }
INITRD /boot/initrd
LABEL chain
MENU LABEL Boot existing OS
COM32 chain . c32
APPEND hd0 0
LABEL reboot
MENU LABEL Reboot
COM32 reboot . c32
LABEL poweroff
MENU LABEL Power Off
COM32 poweroff . c32
'' ;
isolinuxCfg = baseIsolinuxCfg + ( optionalString config . boot . loader . grub . memtest86 . enable isolinuxMemtest86Entry ) ;
# The efi boot image
efiDir = pkgs . runCommand " e f i - d i r e c t o r y " { } ''
mkdir - p $ out/efi /boot
cp - v $ { pkgs . gummiboot } /lib/gummiboot/gummiboot $ { targetArch } . efi $ out/efi /boot/boot $ { targetArch } . efi
mkdir - p $ out/EFI/boot
cp - v $ { pkgs . gummiboot } /lib/gummiboot/gummiboot $ { targetArch } . efi $ out/EFI /boot/boot $ { targetArch } . efi
mkdir - p $ out/loader/entries
echo " t i t l e N i x O S L i v e C D " > $ out/loader/entries/nixos-livecd.conf
echo " l i n u x / b o o t / b z I m a g e " > > $ out/loader/entries/nixos-livecd.conf
@ -152,6 +146,22 @@ in
'' ;
} ;
isoImage . makeUsbBootable = mkOption {
default = false ;
description = ''
Whether the ISO image should be bootable from CD as well as USB .
'' ;
} ;
isoImage . splashImage = mkOption {
default = pkgs . fetchurl {
url = https://raw.githubusercontent.com/NixOS/nixos-artwork/5729ab16c6a5793c10a2913b5a1b3f59b91c36ee/ideas/grub-splash/grub-nixos-1.png ;
sha256 = " 4 3 f d 8 a d 5 d e c f 6 c 2 3 c 8 7 e 9 0 2 6 1 7 0 a 1 3 5 8 8 c 2 e b a 2 4 9 d 9 0 1 3 c b 9 f 8 8 8 d a 5 e 2 0 0 2 2 1 7 " ;
} ;
description = ''
The splash image to use in the bootloader .
'' ;
} ;
} ;
@ -166,7 +176,7 @@ in
# !!! Hack - attributes expected by other modules.
system . boot . loader . kernelFile = " b z I m a g e " ;
environment . systemPackages = [ pkgs . grub2 ] ;
environment . systemPackages = [ pkgs . grub2 pkgs . syslinux ] ;
# 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
@ -216,7 +226,7 @@ in
options = " a l l o w _ o t h e r , c o w , n o n e m p t y , c h r o o t = / m n t - r o o t , m a x _ f i l e s = 3 2 7 6 8 , h i d e _ m e t a _ f i l e s , d i r s = / n i x / . r w - s t o r e = r w : / n i x / . r o - s t o r e = r o " ;
} ;
boot . initrd . availableKernelModules = [ " s q u a s h f s " " i s o 9 6 6 0 " ] ;
boot . initrd . availableKernelModules = [ " s q u a s h f s " " i s o 9 6 6 0 " " u s b - s t o r a g e " ] ;
boot . initrd . kernelModules = [ " l o o p " ] ;
@ -236,15 +246,12 @@ in
# Individual files to be included on the CD, outside of the Nix
# store on the CD.
isoImage . contents =
[ { source = grubImage ;
target = " / b o o t / g r u b / g r u b _ e l t o r i t o " ;
}
{ source = pkgs . substituteAll {
name = " g r u b . c f g " ;
src = pkgs . writeText " g r u b . c f g - i n " grubCfg ;
[ { source = pkgs . substituteAll {
name = " i s o l i n u x . c f g " ;
src = pkgs . writeText " i s o l i n u x . c f g - i n " isolinuxCfg ;
bootRoot = " / b o o t " ;
} ;
target = " / b o o t / g r u b / g r u b . c f g " ;
target = " / i s o l i n u x / i s o l i n u x . c f g " ;
}
{ source = config . boot . kernelPackages . kernel + " / b z I m a g e " ;
target = " / b o o t / b z I m a g e " ;
@ -252,51 +259,38 @@ in
{ source = config . system . build . initialRamdisk + " / i n i t r d " ;
target = " / b o o t / i n i t r d " ;
}
{ source = " ${ pkgs . grub2 } / s h a r e / g r u b / u n i c o d e . p f 2 " ;
target = " / b o o t / g r u b / u n i c o d e . p f 2 " ;
}
{ source = config . boot . loader . grub . splashImage ;
target = " / b o o t / g r u b / s p l a s h . p n g " ;
}
{ source = config . system . build . squashfsStore ;
target = " / n i x - s t o r e . s q u a s h f s " ;
}
{ source = " ${ pkgs . syslinux } / s h a r e / s y s l i n u x " ;
target = " / i s o l i n u x " ;
}
{ source = config . isoImage . splashImage ;
target = " / i s o l i n u x / b a c k g r o u n d . p n g " ;
}
] ++ optionals config . isoImage . makeEfiBootable [
{ source = efiImg ;
target = " / b o o t / e f i . i m g " ;
}
{ source = " ${ efiDir } / e f i " ;
target = " / e f i " ;
{ source = " ${ efiDir } / E F I " ;
target = " / E F I " ;
}
{ source = " ${ efiDir } / l o a d e r " ;
target = " / l o a d e r " ;
}
] ++ mapAttrsToList ( n : v : { source = v ; target = " / b o o t / ${ n } " ; } ) config . boot . loader . grub . extraFiles ;
# The Grub menu.
boot . loader . grub . extraEntries =
''
menuentry " N i x O S ${ config . system . nixosVersion } I n s t a l l e r " {
linux /boot/bzImage init = $ { config . system . build . toplevel } /init $ { toString config . boot . kernelParams }
initrd /boot/initrd
}
menuentry " B o o t f r o m h a r d d i s k " {
set root = ( hd0 )
chainloader + 1
}
'' ;
boot . loader . grub . timeout = 10 ;
] ;
# Create the ISO image.
system . build . isoImage = import ../../../lib/make-iso9660-image.nix ( {
inherit ( pkgs ) stdenv perl cdrkit pathsFromGraph ;
inherit ( pkgs ) stdenv perl pathsFromGraph xorriso syslinux ;
inherit ( config . isoImage ) isoName compressImage volumeID contents ;
bootable = true ;
bootImage = " / b o o t / g r u b / g r u b _ e l t o r i t o " ;
bootImage = " / i s o l i n u x / i s o l i n u x . b i n " ;
} // optionalAttrs config . isoImage . makeUsbBootable {
usbBootable = true ;
isohybridMbrImage = " ${ pkgs . syslinux } / s h a r e / s y s l i n u x / i s o h d p f x . b i n " ;
} // optionalAttrs config . isoImage . makeEfiBootable {
efiBootable = true ;
efiBootImage = " b o o t / e f i . i m g " ;