Files
nix-config/packages/edk2/default.nix
mjallen18 70002a19e2 hmm
2026-04-07 18:39:42 -05:00

128 lines
3.0 KiB
Nix
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
stdenv,
lib,
MODEL ? "5",
RELEASE_TYPE ? "RELEASE",
EDK2_FLAGS ? "",
nasm,
perl,
python3,
python3Packages,
openssl,
git,
libuuid,
acpica-tools,
pkgs,
namespace,
}:
let
inherit (lib.trivial) importJSON;
inherit (lib.${namespace}) selectVariant mkAllSources;
pname = "edk2";
version = "stable202511";
versionSpec = importJSON ./version.json;
selected = selectVariant versionSpec (if MODEL == "5" then "mjallen" else null) null;
sources = mkAllSources pkgs selected;
edk2Src = sources.edk2;
edk2NonOsiSrc = sources."edk2-non-osi";
edk2PlatformsSrc = sources."edk2-platforms";
baseTools = pkgs.${namespace}.edk2-basetools.override {
version = "stable202511";
srcOverride = edk2Src;
};
armTrustedFirmware = pkgs.${namespace}.arm-trusted-firmware.override { inherit MODEL; };
pythonEnv = python3.withPackages (
_ps: with python3Packages; [
libfdt
]
);
in
stdenv.mkDerivation rec {
inherit pname version;
# Add required host tools if needed:
nativeBuildInputs = [
openssl
nasm
perl
pythonEnv
git
libuuid
baseTools
acpica-tools
];
env = {
NIX_CFLAGS_COMPILE =
"-Wno-return-type -Wno-error"
+ lib.optionalString stdenv.cc.isGNU " -Wno-error=stringop-truncation"
+ lib.optionalString stdenv.hostPlatform.isDarwin " -Wno-error=macro-redefined";
PYTHON_COMMAND = lib.getExe pythonEnv;
# trick taken from https://src.fedoraproject.org/rpms/edk2/blob/08f2354cd280b4ce5a7888aa85cf520e042955c3/f/edk2.spec#_319
${"GCC5_AARCH64_PREFIX"} = stdenv.cc.targetPrefix;
};
# Dont force a single root; we keep both dirs side by side
sourceRoot = ".";
unpackPhase = ''
runHook preUnpack
cp -r ${edk2Src} ./edk2
cp -r ${edk2NonOsiSrc} ./edk2-non-osi
cp -r ${edk2PlatformsSrc} ./edk2-platforms
chmod -R u+w .
patchShebangs ./edk2
runHook postUnpack
'';
prePatch = ''
rm -rf ./edk2/BaseTools
ln -sv ${baseTools}/BaseTools ./edk2/BaseTools
'';
configurePhase = ''
runHook preConfigure
export WORKSPACE=$PWD
export PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-non-osi:$WORKSPACE/edk2-platforms
export EDK_TOOLS_PATH=${baseTools}/BaseTools
export ATF_BUILD_DIR="${armTrustedFirmware}/rpi${MODEL}/${lib.toLower RELEASE_TYPE}"
. ${baseTools}/edksetup.sh BaseTools
runHook postConfigure
'';
buildPhase = ''
build \
-a AARCH64 \
-t GCC \
-b ${RELEASE_TYPE} \
-p edk2-platforms/Platform/RaspberryPi/RPi${MODEL}/RPi${MODEL}.dsc \
-D TFA_BUILD_ARTIFACTS=$ATF_BUILD_DIR \
--pcd gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString=L${version} \
${EDK2_FLAGS}
'';
installPhase = ''
mkdir -p $out
cp -r /build/Build/RPi${MODEL}/${RELEASE_TYPE}_GCC/FV/RPI_EFI.fd $out/RPI_EFI.fd
'';
meta = with lib; {
description = "ARM Trusted Firmware-A for Raspberry Pi";
license = licenses.bsd3;
platforms = [ "aarch64-linux" ];
maintainers = with maintainers; [ kazenyuk ];
};
}