2021-12-06 16:07:01 +00:00
|
|
|
{ stdenv
|
|
|
|
, clangStdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
2023-10-09 19:29:22 +00:00
|
|
|
, runCommand
|
2021-12-06 16:07:01 +00:00
|
|
|
, libuuid
|
|
|
|
, python3
|
|
|
|
, bc
|
|
|
|
, lib
|
2022-06-16 17:23:12 +00:00
|
|
|
, buildPackages
|
2020-05-15 21:57:56 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2022-06-16 17:23:12 +00:00
|
|
|
pythonEnv = buildPackages.python3.withPackages (ps: [ps.tkinter]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
targetArch = if stdenv.isi686 then
|
|
|
|
"IA32"
|
|
|
|
else if stdenv.isx86_64 then
|
|
|
|
"X64"
|
2023-01-11 07:51:40 +00:00
|
|
|
else if stdenv.isAarch32 then
|
|
|
|
"ARM"
|
2020-04-24 23:36:52 +00:00
|
|
|
else if stdenv.isAarch64 then
|
|
|
|
"AARCH64"
|
2024-01-02 11:29:13 +00:00
|
|
|
else if stdenv.hostPlatform.isRiscV64 then
|
|
|
|
"RISCV64"
|
2020-04-24 23:36:52 +00:00
|
|
|
else
|
|
|
|
throw "Unsupported architecture";
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
buildType = if stdenv.isDarwin then
|
|
|
|
"CLANGPDB"
|
|
|
|
else
|
|
|
|
"GCC5";
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
edk2 = stdenv.mkDerivation rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "edk2";
|
2024-01-02 11:29:13 +00:00
|
|
|
version = "202311";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
patches = [
|
|
|
|
# pass targetPrefix as an env var
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://src.fedoraproject.org/rpms/edk2/raw/08f2354cd280b4ce5a7888aa85cf520e042955c3/f/0021-Tweak-the-tools_def-to-support-cross-compiling.patch";
|
2023-08-10 07:59:29 +00:00
|
|
|
hash = "sha256-E1/fiFNVx0aB1kOej2DJ2DlBIs9tAAcxoedym2Zhjxw=";
|
2022-06-16 17:23:12 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
srcWithVendoring = fetchFromGitHub {
|
2021-12-06 16:07:01 +00:00
|
|
|
owner = "tianocore";
|
|
|
|
repo = "edk2";
|
2020-04-24 23:36:52 +00:00
|
|
|
rev = "edk2-stable${edk2.version}";
|
2021-12-06 16:07:01 +00:00
|
|
|
fetchSubmodules = true;
|
2024-01-02 11:29:13 +00:00
|
|
|
hash = "sha256-gC/If8U9qo70rGvNl3ld/mmZszwY0w/5Ge/K21mhzYw=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
# We don't want EDK2 to keep track of OpenSSL,
|
|
|
|
# they're frankly bad at it.
|
|
|
|
src = runCommand "edk2-unvendored-src" { } ''
|
|
|
|
cp --no-preserve=mode -r ${srcWithVendoring} $out
|
|
|
|
rm -rf $out/CryptoPkg/Library/OpensslLib/openssl
|
|
|
|
mkdir -p $out/CryptoPkg/Library/OpensslLib/openssl
|
|
|
|
tar --strip-components=1 -xf ${buildPackages.openssl.src} -C $out/CryptoPkg/Library/OpensslLib/openssl
|
|
|
|
chmod -R +w $out/
|
|
|
|
'';
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
nativeBuildInputs = [ pythonEnv ];
|
2024-01-02 11:29:13 +00:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc buildPackages.bash ];
|
|
|
|
depsHostHost = [ libuuid ];
|
2022-06-16 17:23:12 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
# trick taken from https://src.fedoraproject.org/rpms/edk2/blob/08f2354cd280b4ce5a7888aa85cf520e042955c3/f/edk2.spec#_319
|
2024-01-02 11:29:13 +00:00
|
|
|
${"GCC5_${targetArch}_PREFIX"} = stdenv.cc.targetPrefix;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
makeFlags = [ "-C BaseTools" ];
|
2020-05-15 21:57:56 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = "-Wno-return-type"
|
|
|
|
+ lib.optionalString (stdenv.cc.isGNU) " -Wno-error=stringop-truncation"
|
|
|
|
+ lib.optionalString (stdenv.isDarwin) " -Wno-error=macro-redefined";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "format" "fortify" ];
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -vp $out
|
|
|
|
mv -v BaseTools $out
|
|
|
|
mv -v edksetup.sh $out
|
2022-06-16 17:23:12 +00:00
|
|
|
# patchShebangs fails to see these when cross compiling
|
|
|
|
for i in $out/BaseTools/BinWrappers/PosixLike/*; do
|
|
|
|
substituteInPlace $i --replace '/usr/bin/env bash' ${buildPackages.bash}/bin/bash
|
2023-10-09 19:29:22 +00:00
|
|
|
chmod +x "$i"
|
2022-06-16 17:23:12 +00:00
|
|
|
done
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Intel EFI development kit";
|
2022-03-10 19:12:11 +00:00
|
|
|
homepage = "https://github.com/tianocore/tianocore.github.io/wiki/EDK-II/";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.bsd2;
|
2024-01-02 11:29:13 +00:00
|
|
|
platforms = with platforms; aarch64 ++ arm ++ i686 ++ x86_64 ++ riscv64;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru = {
|
2023-08-10 07:59:29 +00:00
|
|
|
mkDerivation = projectDscPath: attrsOrFun: stdenv.mkDerivation (finalAttrs:
|
2022-09-09 14:08:57 +00:00
|
|
|
let
|
|
|
|
attrs = lib.toFunction attrsOrFun finalAttrs;
|
|
|
|
in
|
|
|
|
{
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit (edk2) src;
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ] ++ attrs.depsBuildBuild or [];
|
|
|
|
nativeBuildInputs = [ bc pythonEnv ] ++ attrs.nativeBuildInputs or [];
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
${"GCC5_${targetArch}_PREFIX"}=stdenv.cc.targetPrefix;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
prePatch = ''
|
|
|
|
rm -rf BaseTools
|
|
|
|
ln -sv ${edk2}/BaseTools BaseTools
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
export WORKSPACE="$PWD"
|
|
|
|
. ${edk2}/edksetup.sh BaseTools
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2023-05-24 13:37:59 +00:00
|
|
|
build -a ${targetArch} -b ${attrs.buildConfig or "RELEASE"} -t ${buildType} -p ${projectDscPath} -n $NIX_BUILD_CORES $buildFlags
|
2020-04-24 23:36:52 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mv -v Build/*/* $out
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
} // removeAttrs attrs [ "nativeBuildInputs" "depsBuildBuild" ]);
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
edk2
|