{ lib }: { overlays = [( final: prev: { hostPlatform = if prev.hostPlatform != null then prev.hostPlatform else lib.systems.examples.gnu64; flashrom = prev.flashrom.override { # AMD hardware expects to see an FMAP region called "BIOS" # which covers the entire ROM image; flashrom doesn't like # this overlapping so we have to patch it overlappingFmapRegionSupport = true; }; scripts = let layoutFlags = # Using `flashrom --fmap-file` is undesirable because # there is no validation that the layout of the chip # we are flashing matches the `flashrom.layout` file. # If they don't match, bricking is likely. So please # use the overlappingFmapRegionSupport patch, and ask # the upstream maintainers to merge it. if final.flashrom.passthru.overlappingFmapRegionSupport then "--fmap" else "--fmap-file ${final.fmap}"; flashromScript = moreFlags: '' set -euo pipefail ${final.flashrom}/bin/flashrom -p internal $@ ${moreFlags} ''; flashromWriteScript = moreFlags: flashromScript "-w ${final.coreboot}/coreboot.rom ${moreFlags}"; nvramToolScript = moreFlags: '' set -euo pipefail ${final.nixpkgsOnBuildForHost.nvramtool}/bin/nvramtool -y ${final.coreboot}/cmos.layout ${moreFlags} ''; in prev.scripts // { flashrom = flashromScript "$@"; flash-write-fallback = flashromWriteScript "${layoutFlags} -i FALLBACK"; flash-write-normal = flashromWriteScript "${layoutFlags} -i NORMAL"; flash-write-all = flashromWriteScript ""; nextboot-use-fallback = nvramToolScript "-w boot_option=Fallback"; nextboot-use-normal = nvramToolScript "-w boot_option=Normal"; nextboot-show = nvramToolScript "-n -r boot_option"; # FIXME(amjoseph): store the cmos.layout and cmos.default in # the flash chip so we don't have to worry about # desynchronization (parallel to --fmap-file concern above). nvram-tool = nvramToolScript "$@"; nvram-all-read = nvramToolScript "-a"; nvram-all-write = nvramToolScript "-p $1"; nvram-all-defaults = nvramToolScript "-p ${final.coreboot}/cmos.default"; nvram-bootcount-show = nvramToolScript "-n -r reboot_counter"; nvram-parameter-read = nvramToolScript "-n -r $1"; nvram-parameter-choices = nvramToolScript "-e $1"; nvram-checksum-read = nvramToolScript "-c"; nvram-checksum-write = nvramToolScript "-c $1"; }; main = prev.main.overrideAttrs(previousAttrs: { # cmos nvram is an x86-ism postInstall = (previousAttrs.postInstall or "") + '' ln -s ${final.coreboot}/{cmos.layout,cmos.default} $out/etc/ ''; }); })]; }