From ad27b068d7fe11536a34abc074ff1f77d537843a Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Sun, 2 Dec 2018 00:34:58 -0500 Subject: installer: Adds AArch64 UEFI installer support. --- nixos/modules/installer/cd-dvd/iso-image.nix | 78 ++++++++++++++++++---------- 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'nixos/modules/installer') diff --git a/nixos/modules/installer/cd-dvd/iso-image.nix b/nixos/modules/installer/cd-dvd/iso-image.nix index aa8003fef2c9..9475da23b1ff 100644 --- a/nixos/modules/installer/cd-dvd/iso-image.nix +++ b/nixos/modules/installer/cd-dvd/iso-image.nix @@ -50,7 +50,7 @@ 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"; + image = "/boot/${config.system.boot.loader.kernelFile}"; initrd = "/boot/initrd"; }; in @@ -163,7 +163,7 @@ let cp -v ${pkgs.refind}/share/refind/refind_x64.efi $out/EFI/boot/ '' else - "# No refind for ia32" + "# No refind for ${targetArch}" ; grubMenuCfg = '' @@ -222,18 +222,34 @@ let efiDir = pkgs.runCommand "efi-directory" {} '' mkdir -p $out/EFI/boot/ + # ALWAYS required modules. MODULES="fat iso9660 part_gpt part_msdos \ normal boot linux configfile loopback chain halt \ - efifwsetup efi_gop efi_uga \ + efifwsetup efi_gop \ 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 \ " + + echo "Building GRUB with modules:" + for mod in $MODULES; do + echo " - $mod" + done + + # Modules that may or may not be available per-platform. + echo "Adding additional modules:" + for mod in efi_uga; do + if [ -f ${pkgs.grub2_efi}/lib/grub/${pkgs.grub2_efi.grubTarget}/$mod.mod ]; then + echo " - $mod" + MODULES+=" $mod" + fi + done + # Make our own efi program, we can't rely on "grub-install" since it seems to # probe for devices, even with --skip-fs-probe. - ${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 \ + ${pkgs.grub2_efi}/bin/grub-mkimage -o $out/EFI/boot/boot${targetArch}.efi -p /EFI/boot -O ${pkgs.grub2_efi.grubTarget} \ $MODULES cp ${pkgs.grub2_efi}/share/grub/unicode.pf2 $out/EFI/boot/ @@ -344,12 +360,19 @@ let ${pkgs.dosfstools}/sbin/fsck.vfat -vn "$out" ''; # */ - targetArch = if pkgs.stdenv.isi686 then - "ia32" - else if pkgs.stdenv.isx86_64 then - "x64" - else - throw "Unsupported architecture"; + # Name used by UEFI for architectures. + targetArch = + if pkgs.stdenv.isi686 then + "ia32" + else if pkgs.stdenv.isx86_64 then + "x64" + else if pkgs.stdenv.isAarch64 then + "aa64" + else + throw "Unsupported architecture"; + + # Syslinux (and isolinux) only supports x86-based architectures. + canx86BiosBoot = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64; in @@ -483,9 +506,9 @@ in # here and it causes a cyclic dependency. boot.loader.grub.enable = false; - # !!! Hack - attributes expected by other modules. - system.boot.loader.kernelFile = "bzImage"; - environment.systemPackages = [ pkgs.grub2 pkgs.grub2_efi pkgs.syslinux ]; + environment.systemPackages = [ pkgs.grub2 pkgs.grub2_efi ] + ++ optional canx86BiosBoot 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 @@ -556,13 +579,7 @@ in # Individual files to be included on the CD, outside of the Nix # store on the CD. isoImage.contents = - [ { source = pkgs.substituteAll { - name = "isolinux.cfg"; - src = pkgs.writeText "isolinux.cfg-in" isolinuxCfg; - bootRoot = "/boot"; - }; - target = "/isolinux/isolinux.cfg"; - } + [ { source = config.boot.kernelPackages.kernel + "/" + config.system.boot.loader.kernelFile; target = "/boot/" + config.system.boot.loader.kernelFile; } @@ -572,9 +589,6 @@ in { source = config.system.build.squashfsStore; target = "/nix-store.squashfs"; } - { source = "${pkgs.syslinux}/share/syslinux"; - target = "/isolinux"; - } { source = config.isoImage.efiSplashImage; target = "/EFI/boot/efi-background.png"; } @@ -584,6 +598,17 @@ in { source = pkgs.writeText "version" config.system.nixos.label; target = "/version.txt"; } + ] ++ optionals canx86BiosBoot [ + { 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"; + } ] ++ optionals config.isoImage.makeEfiBootable [ { source = efiImg; target = "/boot/efi.img"; @@ -591,7 +616,7 @@ in { source = "${efiDir}/EFI"; target = "/EFI"; } - ] ++ optionals config.boot.loader.grub.memtest86.enable [ + ] ++ optionals (config.boot.loader.grub.memtest86.enable && canx86BiosBoot) [ { source = "${pkgs.memtest86plus}/memtest.bin"; target = "/boot/memtest.bin"; } @@ -606,9 +631,10 @@ in # Create the ISO image. system.build.isoImage = pkgs.callPackage ../../../lib/make-iso9660-image.nix ({ inherit (config.isoImage) isoName compressImage volumeID contents; - bootable = true; + bootable = canx86BiosBoot; bootImage = "/isolinux/isolinux.bin"; - } // optionalAttrs config.isoImage.makeUsbBootable { + syslinux = if canx86BiosBoot then pkgs.syslinux else null; + } // optionalAttrs (config.isoImage.makeUsbBootable && canx86BiosBoot) { usbBootable = true; isohybridMbrImage = "${pkgs.syslinux}/share/syslinux/isohdpfx.bin"; } // optionalAttrs config.isoImage.makeEfiBootable { -- cgit 1.4.1