15 pythonEnv = buildPackages.python3.withPackages (ps: [ ps.tkinter ]);
18 if stdenv.hostPlatform.isi686 then
20 else if stdenv.hostPlatform.isx86_64 then
22 else if stdenv.hostPlatform.isAarch32 then
24 else if stdenv.hostPlatform.isAarch64 then
26 else if stdenv.hostPlatform.isRiscV64 then
28 else if stdenv.hostPlatform.isLoongArch64 then
31 throw "Unsupported architecture";
33 buildType = if stdenv.hostPlatform.isDarwin then "CLANGPDB" else "GCC5";
35 edk2 = stdenv.mkDerivation {
39 srcWithVendoring = fetchFromGitHub {
42 rev = "edk2-stable${edk2.version}";
43 fetchSubmodules = true;
44 hash = "sha256-KYaTGJ3DHtWbPEbP+n8MTk/WwzLv5Vugty/tvzuEUf0=";
48 name = "edk2-${edk2.version}-unvendored-src";
49 src = edk2.srcWithVendoring;
52 # pass targetPrefix as an env var
54 url = "https://src.fedoraproject.org/rpms/edk2/raw/08f2354cd280b4ce5a7888aa85cf520e042955c3/f/0021-Tweak-the-tools_def-to-support-cross-compiling.patch";
55 hash = "sha256-E1/fiFNVx0aB1kOej2DJ2DlBIs9tAAcxoedym2Zhjxw=";
57 # https://github.com/tianocore/edk2/pull/5658
59 name = "fix-cross-compilation-antlr-dlg.patch";
60 url = "https://github.com/tianocore/edk2/commit/a34ff4a8f69a7b8a52b9b299153a8fac702c7df1.patch";
61 hash = "sha256-u+niqwjuLV5tNPykW4xhb7PW2XvUmXhx5uvftG1UIbU=";
65 # EDK2 is currently working on OpenSSL 3.3.x support. Use buildpackages.openssl again,
66 # when "https://github.com/tianocore/edk2/pull/6167" is merged.
68 # We don't want EDK2 to keep track of OpenSSL, they're frankly bad at it.
69 rm -r CryptoPkg/Library/OpensslLib/openssl
70 mkdir -p CryptoPkg/Library/OpensslLib/openssl
72 cd CryptoPkg/Library/OpensslLib/openssl
73 tar --strip-components=1 -xf ${buildPackages.openssl_3.src}
75 # Apply OpenSSL patches.
76 ${lib.pipe buildPackages.openssl_3.patches [
79 !builtins.elem (baseNameOf patch) [
80 # Exclude patches not required in this context.
81 "nix-ssl-cert-file.patch"
82 "openssl-disable-kernel-detection.patch"
83 "use-etc-ssl-certs-darwin.patch"
84 "use-etc-ssl-certs.patch"
87 (map (patch: "patch -p1 < ${patch}\n"))
92 # enable compilation using Clang
93 # https://bugzilla.tianocore.org/show_bug.cgi?id=4620
94 substituteInPlace BaseTools/Conf/tools_def.template --replace-fail \
95 'DEFINE CLANGPDB_WARNING_OVERRIDES = ' \
96 'DEFINE CLANGPDB_WARNING_OVERRIDES = -Wno-unneeded-internal-declaration '
100 nativeBuildInputs = [ pythonEnv ];
102 buildPackages.stdenv.cc
105 depsHostHost = [ libuuid ];
108 # trick taken from https://src.fedoraproject.org/rpms/edk2/blob/08f2354cd280b4ce5a7888aa85cf520e042955c3/f/edk2.spec#_319
109 ${"GCC5_${targetArch}_PREFIX"} = stdenv.cc.targetPrefix;
111 makeFlags = [ "-C BaseTools" ];
113 env.NIX_CFLAGS_COMPILE =
115 + lib.optionalString (stdenv.cc.isGNU) " -Wno-error=stringop-truncation"
116 + lib.optionalString (stdenv.hostPlatform.isDarwin) " -Wno-error=macro-redefined";
126 mv -v edksetup.sh $out
127 # patchShebangs fails to see these when cross compiling
128 for i in $out/BaseTools/BinWrappers/PosixLike/*; do
130 patchShebangs --build "$i"
134 enableParallelBuilding = true;
137 description = "Intel EFI development kit";
138 homepage = "https://github.com/tianocore/tianocore.github.io/wiki/EDK-II/";
139 changelog = "https://github.com/tianocore/edk2/releases/tag/edk2-stable${edk2.version}";
140 license = lib.licenses.bsd2;
141 platforms = with lib.platforms; aarch64 ++ arm ++ i686 ++ x86_64 ++ loongarch64 ++ riscv64;
142 maintainers = [ lib.maintainers.mjoerg ];
146 # exercise a channel blocker
147 tests.uefiUsb = nixosTests.boot.uefiCdrom;
149 updateScript = writeScript "update-edk2" ''
150 #!/usr/bin/env nix-shell
151 #!nix-shell -i bash -p common-updater-scripts coreutils gnused
153 version="$(list-git-tags --url="${edk2.srcWithVendoring.url}" |
154 sed -E --quiet 's/^edk2-stable([0-9]{6})$/\1/p' |
155 sort --reverse --numeric-sort |
157 if [[ "x$UPDATE_NIX_OLD_VERSION" != "x$version" ]]; then
158 update-source-version --source-key=srcWithVendoring \
159 "$UPDATE_NIX_ATTR_PATH" "$version"
164 projectDscPath: attrsOrFun:
165 stdenv.mkDerivation (
168 attrs = lib.toFunction attrsOrFun finalAttrs;
173 depsBuildBuild = [ buildPackages.stdenv.cc ] ++ attrs.depsBuildBuild or [ ];
174 nativeBuildInputs = [
177 ] ++ attrs.nativeBuildInputs or [ ];
180 ${"GCC5_${targetArch}_PREFIX"} = stdenv.cc.targetPrefix;
184 ln -sv ${buildPackages.edk2}/BaseTools BaseTools
189 export WORKSPACE="$PWD"
190 . ${buildPackages.edk2}/edksetup.sh BaseTools
191 runHook postConfigure
196 build -a ${targetArch} -b ${attrs.buildConfig or "RELEASE"} -t ${buildType} -p ${projectDscPath} -n $NIX_BUILD_CORES $buildFlags
206 // removeAttrs attrs [