From f5f53288ccd32e7f37d2b27652399a93d940491c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Partheym=C3=BCller?= Date: Fri, 17 Apr 2020 15:15:57 +0200 Subject: [PATCH 1/4] edk2/OVMF: Support build on macOS In order to use OVMF firmware with e.g. qemu on macOS, these packages needed to be made macOS ready. This meant choosing the clang build in this case, because it is the only one working on macOS. Unfortunately, just using clang on all platforms doesn't work because there are hardcoded assumptions in the edk2 build system. --- .../virtualization/OVMF/default.nix | 8 +++-- pkgs/development/compilers/edk2/default.nix | 36 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pkgs/applications/virtualization/OVMF/default.nix b/pkgs/applications/virtualization/OVMF/default.nix index e475c4ed78a..e203106587b 100644 --- a/pkgs/applications/virtualization/OVMF/default.nix +++ b/pkgs/applications/virtualization/OVMF/default.nix @@ -17,9 +17,13 @@ let throw "Unsupported architecture"; version = lib.getVersion edk2; + buildType = if stdenv.isDarwin then + "CLANGPDB" + else + "GCC5"; in -edk2.mkDerivation projectDscPath { +edk2.mkDerivation projectDscPath buildType { name = "OVMF-${version}"; outputs = [ "out" "fd" ]; @@ -57,6 +61,6 @@ edk2.mkDerivation projectDscPath { description = "Sample UEFI firmware for QEMU and KVM"; homepage = https://github.com/tianocore/tianocore.github.io/wiki/OVMF; license = stdenv.lib.licenses.bsd2; - platforms = ["x86_64-linux" "i686-linux" "aarch64-linux"]; + platforms = ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]; }; } diff --git a/pkgs/development/compilers/edk2/default.nix b/pkgs/development/compilers/edk2/default.nix index 47aa8e249f8..2ba02a29488 100644 --- a/pkgs/development/compilers/edk2/default.nix +++ b/pkgs/development/compilers/edk2/default.nix @@ -1,4 +1,17 @@ -{ stdenv, fetchgit, fetchpatch, libuuid, python3, iasl, bc }: +{ + stdenv, + clangStdenv, + fetchgit, + fetchpatch, + libuuid, + python3, + iasl, + bc, + clang_9, + llvmPackages_9, + overrideCC, + lib, +}: let pythonEnv = python3.withPackages (ps: [ps.tkinter]); @@ -12,7 +25,12 @@ else if stdenv.isAarch64 then else throw "Unsupported architecture"; -edk2 = stdenv.mkDerivation { +buildStdenv = if stdenv.isDarwin then + overrideCC clangStdenv [ clang_9 llvmPackages_9.llvm llvmPackages_9.lld ] +else + stdenv; + +edk2 = buildStdenv.mkDerivation { pname = "edk2"; version = "201911"; @@ -25,8 +43,10 @@ edk2 = stdenv.mkDerivation { buildInputs = [ libuuid pythonEnv ]; - makeFlags = [ "-C BaseTools" ]; - NIX_CFLAGS_COMPILE = "-Wno-return-type -Wno-error=stringop-truncation"; + makeFlags = [ "-C BaseTools" ] + ++ lib.optional (stdenv.isDarwin) [ "BUILD_CC=clang BUILD_CXX=clang++ BUILD_AS=clang" ]; + + NIX_CFLAGS_COMPILE = "-Wno-return-type" + lib.optionalString (!stdenv.isDarwin) " -Wno-error=stringop-truncation"; hardeningDisable = [ "format" "fortify" ]; @@ -38,15 +58,15 @@ edk2 = stdenv.mkDerivation { enableParallelBuilding = true; - meta = with stdenv.lib; { + meta = with lib; { description = "Intel EFI development kit"; homepage = https://sourceforge.net/projects/edk2/; license = licenses.bsd2; - platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; + platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" ]; }; passthru = { - mkDerivation = projectDscPath: attrs: stdenv.mkDerivation ({ + mkDerivation = projectDscPath: buildType: attrs: buildStdenv.mkDerivation ({ inherit (edk2) src; buildInputs = [ bc pythonEnv ] ++ attrs.buildInputs or []; @@ -65,7 +85,7 @@ edk2 = stdenv.mkDerivation { buildPhase = '' runHook preBuild - build -a ${targetArch} -b RELEASE -t GCC5 -p ${projectDscPath} -n $NIX_BUILD_CORES $buildFlags + build -a ${targetArch} -b RELEASE -t ${buildType} -p ${projectDscPath} -n $NIX_BUILD_CORES $buildFlags runHook postBuild ''; From fe8afcb993845505042b41f09a9c98f6748d7af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Partheym=C3=BCller?= Date: Mon, 20 Apr 2020 13:19:38 +0200 Subject: [PATCH 2/4] edk2: Fix style --- pkgs/development/compilers/edk2/default.nix | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkgs/development/compilers/edk2/default.nix b/pkgs/development/compilers/edk2/default.nix index 2ba02a29488..eb658431c92 100644 --- a/pkgs/development/compilers/edk2/default.nix +++ b/pkgs/development/compilers/edk2/default.nix @@ -1,16 +1,16 @@ { - stdenv, - clangStdenv, - fetchgit, - fetchpatch, - libuuid, - python3, - iasl, - bc, - clang_9, - llvmPackages_9, - overrideCC, - lib, + stdenv, + clangStdenv, + fetchgit, + fetchpatch, + libuuid, + python3, + iasl, + bc, + clang_9, + llvmPackages_9, + overrideCC, + lib, }: let From 94d114dc2a9619843af8ea6b322ef2b4f44b982f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Partheym=C3=BCller?= Date: Mon, 20 Apr 2020 13:30:35 +0200 Subject: [PATCH 3/4] edk2/OVMF: Determine build type from CC setting --- pkgs/applications/virtualization/OVMF/default.nix | 6 +----- pkgs/development/compilers/edk2/default.nix | 11 ++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/virtualization/OVMF/default.nix b/pkgs/applications/virtualization/OVMF/default.nix index e203106587b..cd30be88991 100644 --- a/pkgs/applications/virtualization/OVMF/default.nix +++ b/pkgs/applications/virtualization/OVMF/default.nix @@ -17,13 +17,9 @@ let throw "Unsupported architecture"; version = lib.getVersion edk2; - buildType = if stdenv.isDarwin then - "CLANGPDB" - else - "GCC5"; in -edk2.mkDerivation projectDscPath buildType { +edk2.mkDerivation projectDscPath { name = "OVMF-${version}"; outputs = [ "out" "fd" ]; diff --git a/pkgs/development/compilers/edk2/default.nix b/pkgs/development/compilers/edk2/default.nix index eb658431c92..1050119be53 100644 --- a/pkgs/development/compilers/edk2/default.nix +++ b/pkgs/development/compilers/edk2/default.nix @@ -30,6 +30,11 @@ buildStdenv = if stdenv.isDarwin then else stdenv; +buildType = if stdenv.isDarwin then + "CLANGPDB" + else + "GCC5"; + edk2 = buildStdenv.mkDerivation { pname = "edk2"; version = "201911"; @@ -44,9 +49,9 @@ edk2 = buildStdenv.mkDerivation { buildInputs = [ libuuid pythonEnv ]; makeFlags = [ "-C BaseTools" ] - ++ lib.optional (stdenv.isDarwin) [ "BUILD_CC=clang BUILD_CXX=clang++ BUILD_AS=clang" ]; + ++ lib.optional (stdenv.cc.isClang) [ "BUILD_CC=clang BUILD_CXX=clang++ BUILD_AS=clang" ]; - NIX_CFLAGS_COMPILE = "-Wno-return-type" + lib.optionalString (!stdenv.isDarwin) " -Wno-error=stringop-truncation"; + NIX_CFLAGS_COMPILE = "-Wno-return-type" + lib.optionalString (stdenv.cc.isGNU) " -Wno-error=stringop-truncation"; hardeningDisable = [ "format" "fortify" ]; @@ -66,7 +71,7 @@ edk2 = buildStdenv.mkDerivation { }; passthru = { - mkDerivation = projectDscPath: buildType: attrs: buildStdenv.mkDerivation ({ + mkDerivation = projectDscPath: attrs: buildStdenv.mkDerivation ({ inherit (edk2) src; buildInputs = [ bc pythonEnv ] ++ attrs.buildInputs or []; From faf984d12de03cba018fe3099a1de1d607c038da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Partheym=C3=BCller?= Date: Mon, 4 May 2020 16:00:37 +0200 Subject: [PATCH 4/4] ed2k/OVMF: Put URLs in quotes --- pkgs/applications/virtualization/OVMF/default.nix | 2 +- pkgs/development/compilers/edk2/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/virtualization/OVMF/default.nix b/pkgs/applications/virtualization/OVMF/default.nix index cd30be88991..19ba8ced497 100644 --- a/pkgs/applications/virtualization/OVMF/default.nix +++ b/pkgs/applications/virtualization/OVMF/default.nix @@ -55,7 +55,7 @@ edk2.mkDerivation projectDscPath { meta = { description = "Sample UEFI firmware for QEMU and KVM"; - homepage = https://github.com/tianocore/tianocore.github.io/wiki/OVMF; + homepage = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF"; license = stdenv.lib.licenses.bsd2; platforms = ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]; }; diff --git a/pkgs/development/compilers/edk2/default.nix b/pkgs/development/compilers/edk2/default.nix index 1050119be53..8a18b6306c2 100644 --- a/pkgs/development/compilers/edk2/default.nix +++ b/pkgs/development/compilers/edk2/default.nix @@ -65,7 +65,7 @@ edk2 = buildStdenv.mkDerivation { meta = with lib; { description = "Intel EFI development kit"; - homepage = https://sourceforge.net/projects/edk2/; + homepage = "https://sourceforge.net/projects/edk2/"; license = licenses.bsd2; platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" ]; };