# OpenCore boot disk for build-time boots, derived from an image's ESP # (makeOpenCore output) with build-only settings: extra boot-args (serial # console, verbose) and optionally an OpenCore ScanPolicy so that only the PE # (an HFS+ volume on SATA) is bootable — the build never lands on the wrong OS. { pkgs, lib, ... }: { esp, bootArgs ? null, scanPolicy ? null, name ? "boot" }: pkgs.runCommand "${name}-bootdisk" { nativeBuildInputs = with pkgs; [ python3 mtools dosfstools gptfdisk ]; } '' cp -r ${esp}/EFI EFI chmod -R u+w EFI python3 - <<'PY' import plistlib p = 'EFI/OC/config.plist' cfg = plistlib.load(open(p, 'rb')) nv = cfg['NVRAM']['Add']['7C436110-AB2A-4BBB-A880-FE41995C9F82'] ${lib.optionalString (bootArgs != null) ''nv['boot-args'] = ${builtins.toJSON bootArgs}''} ${lib.optionalString (scanPolicy != null) ''cfg['Misc']['Security']['ScanPolicy'] = ${toString scanPolicy}''} plistlib.dump(cfg, open(p, 'wb')) print('boot-args:', nv['boot-args'], 'ScanPolicy:', cfg['Misc']['Security']['ScanPolicy']) PY mkdir -p $out truncate -s 64M $out/boot.img sgdisk -n 1:2048:0 -t 1:EF00 -c 1:EFI $out/boot.img >/dev/null SECTORS=$(( 64*1024*1024/512 - 2048 - 34 )) mkfs.vfat -F 32 -n OPENCORE --offset 2048 $out/boot.img $(( SECTORS / 2 )) >/dev/null mcopy -i $out/boot.img@@1M -s EFI :: mdir -i $out/boot.img@@1M ::EFI/OC >/dev/null ''