fluffychat: 1.22.1 -> 1.23.0 (#364091)
[NixPkgs.git] / pkgs / by-name / ed / edk2 / package.nix
blobb552a7675fe129ad5b458a6d9174ddc439002269
2   stdenv,
3   fetchFromGitHub,
4   fetchpatch,
5   applyPatches,
6   libuuid,
7   bc,
8   lib,
9   buildPackages,
10   nixosTests,
11   writeScript,
14 let
15   pythonEnv = buildPackages.python3.withPackages (ps: [ ps.tkinter ]);
17   targetArch =
18     if stdenv.hostPlatform.isi686 then
19       "IA32"
20     else if stdenv.hostPlatform.isx86_64 then
21       "X64"
22     else if stdenv.hostPlatform.isAarch32 then
23       "ARM"
24     else if stdenv.hostPlatform.isAarch64 then
25       "AARCH64"
26     else if stdenv.hostPlatform.isRiscV64 then
27       "RISCV64"
28     else if stdenv.hostPlatform.isLoongArch64 then
29       "LOONGARCH64"
30     else
31       throw "Unsupported architecture";
33   buildType = if stdenv.hostPlatform.isDarwin then "CLANGPDB" else "GCC5";
35   edk2 = stdenv.mkDerivation {
36     pname = "edk2";
37     version = "202411";
39     srcWithVendoring = fetchFromGitHub {
40       owner = "tianocore";
41       repo = "edk2";
42       rev = "edk2-stable${edk2.version}";
43       fetchSubmodules = true;
44       hash = "sha256-KYaTGJ3DHtWbPEbP+n8MTk/WwzLv5Vugty/tvzuEUf0=";
45     };
47     src = applyPatches {
48       name = "edk2-${edk2.version}-unvendored-src";
49       src = edk2.srcWithVendoring;
51       patches = [
52         # pass targetPrefix as an env var
53         (fetchpatch {
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=";
56         })
57         # https://github.com/tianocore/edk2/pull/5658
58         (fetchpatch {
59           name = "fix-cross-compilation-antlr-dlg.patch";
60           url = "https://github.com/tianocore/edk2/commit/a34ff4a8f69a7b8a52b9b299153a8fac702c7df1.patch";
61           hash = "sha256-u+niqwjuLV5tNPykW4xhb7PW2XvUmXhx5uvftG1UIbU=";
62         })
63       ];
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.
67       postPatch = ''
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
71         (
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 [
77           (builtins.filter (
78             patch:
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"
85             ]
86           ))
87           (map (patch: "patch -p1 < ${patch}\n"))
88           lib.concatStrings
89         ]}
90         )
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 '
97       '';
98     };
100     nativeBuildInputs = [ pythonEnv ];
101     depsBuildBuild = [
102       buildPackages.stdenv.cc
103       buildPackages.bash
104     ];
105     depsHostHost = [ libuuid ];
106     strictDeps = true;
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 =
114       "-Wno-return-type"
115       + lib.optionalString (stdenv.cc.isGNU) " -Wno-error=stringop-truncation"
116       + lib.optionalString (stdenv.hostPlatform.isDarwin) " -Wno-error=macro-redefined";
118     hardeningDisable = [
119       "format"
120       "fortify"
121     ];
123     installPhase = ''
124       mkdir -vp $out
125       mv -v BaseTools $out
126       mv -v edksetup.sh $out
127       # patchShebangs fails to see these when cross compiling
128       for i in $out/BaseTools/BinWrappers/PosixLike/*; do
129         chmod +x "$i"
130         patchShebangs --build "$i"
131       done
132     '';
134     enableParallelBuilding = true;
136     meta = {
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 ];
143     };
145     passthru = {
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
152         set -eu -o pipefail
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 |
156                    head -n 1)"
157         if [[ "x$UPDATE_NIX_OLD_VERSION" != "x$version" ]]; then
158             update-source-version --source-key=srcWithVendoring \
159                 "$UPDATE_NIX_ATTR_PATH" "$version"
160         fi
161       '';
163       mkDerivation =
164         projectDscPath: attrsOrFun:
165         stdenv.mkDerivation (
166           finalAttrs:
167           let
168             attrs = lib.toFunction attrsOrFun finalAttrs;
169           in
170           {
171             inherit (edk2) src;
173             depsBuildBuild = [ buildPackages.stdenv.cc ] ++ attrs.depsBuildBuild or [ ];
174             nativeBuildInputs = [
175               bc
176               pythonEnv
177             ] ++ attrs.nativeBuildInputs or [ ];
178             strictDeps = true;
180             ${"GCC5_${targetArch}_PREFIX"} = stdenv.cc.targetPrefix;
182             prePatch = ''
183               rm -rf BaseTools
184               ln -sv ${buildPackages.edk2}/BaseTools BaseTools
185             '';
187             configurePhase = ''
188               runHook preConfigure
189               export WORKSPACE="$PWD"
190               . ${buildPackages.edk2}/edksetup.sh BaseTools
191               runHook postConfigure
192             '';
194             buildPhase = ''
195               runHook preBuild
196               build -a ${targetArch} -b ${attrs.buildConfig or "RELEASE"} -t ${buildType} -p ${projectDscPath} -n $NIX_BUILD_CORES $buildFlags
197               runHook postBuild
198             '';
200             installPhase = ''
201               runHook preInstall
202               mv -v Build/*/* $out
203               runHook postInstall
204             '';
205           }
206           // removeAttrs attrs [
207             "nativeBuildInputs"
208             "depsBuildBuild"
209           ]
210         );
211     };
212   };
216 edk2