From 9e5e340fb8e44cb1aa409c7f3e44c4b6077747cc Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Mon, 8 Jul 2024 14:04:19 +0100 Subject: [PATCH 1/4] multipass: reformat with nixfmt-rfc-style --- .../virtualization/multipass/default.nix | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/pkgs/tools/virtualization/multipass/default.nix b/pkgs/tools/virtualization/multipass/default.nix index e7875f00bb6a..e2fea0689c8f 100644 --- a/pkgs/tools/virtualization/multipass/default.nix +++ b/pkgs/tools/virtualization/multipass/default.nix @@ -1,26 +1,27 @@ -{ cmake -, dnsmasq -, fetchFromGitHub -, git -, gtest -, iproute2 -, iptables -, lib -, libapparmor -, libvirt -, libxml2 -, nixosTests -, openssl -, OVMF -, pkg-config -, qemu -, qemu-utils -, qtbase -, qtwayland -, wrapQtAppsHook -, slang -, stdenv -, xterm +{ + cmake, + dnsmasq, + fetchFromGitHub, + git, + gtest, + iproute2, + iptables, + lib, + libapparmor, + libvirt, + libxml2, + nixosTests, + openssl, + OVMF, + pkg-config, + qemu, + qemu-utils, + qtbase, + qtwayland, + wrapQtAppsHook, + slang, + stdenv, + xterm, }: let @@ -38,8 +39,7 @@ let fetchSubmodules = true; }; in -stdenv.mkDerivation -{ +stdenv.mkDerivation { inherit pname version; src = fetchFromGitHub { @@ -118,15 +118,17 @@ stdenv.mkDerivation nativeCheckInputs = [ gtest ]; postInstall = '' - wrapProgram $out/bin/multipassd --prefix PATH : ${lib.makeBinPath [ - dnsmasq - iproute2 - iptables - OVMF.fd - qemu - qemu-utils - xterm - ]} + wrapProgram $out/bin/multipassd --prefix PATH : ${ + lib.makeBinPath [ + dnsmasq + iproute2 + iptables + OVMF.fd + qemu + qemu-utils + xterm + ] + } ''; passthru.tests = { From 816ff1ce7518e2df87f824d0839774bc1a7d5ab7 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Mon, 8 Jul 2024 14:24:26 +0100 Subject: [PATCH 2/4] multipass: use `--replace-fail` in calls to `substituteInPlace` --- pkgs/tools/virtualization/multipass/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/tools/virtualization/multipass/default.nix b/pkgs/tools/virtualization/multipass/default.nix index e2fea0689c8f..851ee7cfd69d 100644 --- a/pkgs/tools/virtualization/multipass/default.nix +++ b/pkgs/tools/virtualization/multipass/default.nix @@ -65,13 +65,13 @@ stdenv.mkDerivation { postPatch = '' # Make sure the version is reported correctly in the compiled binary. substituteInPlace ./CMakeLists.txt \ - --replace "determine_version(MULTIPASS_VERSION)" "" \ - --replace 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")' + --replace-fail "determine_version(MULTIPASS_VERSION)" "" \ + --replace-fail 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")' # Patch the patch of the OVMF binaries to use paths from the nix store. substituteInPlace ./src/platform/backends/qemu/linux/qemu_platform_detail_linux.cpp \ - --replace "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \ - --replace "QEMU_EFI.fd" "${OVMF.fd}/FV/QEMU_EFI.fd" + --replace-fail "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \ + --replace-fail "QEMU_EFI.fd" "${OVMF.fd}/FV/QEMU_EFI.fd" # Copy the grpc submodule we fetched into the source code. cp -r --no-preserve=mode ${grpc_src} 3rd-party/grpc From c24efe53ac3000f2ecf388e0027c4d143bc25cd4 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 9 Jul 2024 11:57:07 +0200 Subject: [PATCH 3/4] multipass: 1.13.1 -> 1.14.0 --- .../multipass/cmake_no_fetch.patch | 19 ----- .../virtualization/multipass/default.nix | 16 +++- .../multipass/test_unreachable_call.patch | 12 +++ .../multipass/vcpkg_no_install.patch | 83 +++++++++++++++++++ 4 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 pkgs/tools/virtualization/multipass/test_unreachable_call.patch create mode 100644 pkgs/tools/virtualization/multipass/vcpkg_no_install.patch diff --git a/pkgs/tools/virtualization/multipass/cmake_no_fetch.patch b/pkgs/tools/virtualization/multipass/cmake_no_fetch.patch index bde1792d4002..6981a0dd33f7 100644 --- a/pkgs/tools/virtualization/multipass/cmake_no_fetch.patch +++ b/pkgs/tools/virtualization/multipass/cmake_no_fetch.patch @@ -1,22 +1,3 @@ -diff --git a/3rd-party/CMakeLists.txt b/3rd-party/CMakeLists.txt -index 188ebfc6..4a34a922 100644 ---- a/3rd-party/CMakeLists.txt -+++ b/3rd-party/CMakeLists.txt -@@ -2,12 +2,8 @@ include(FetchContent) - set(FETCHCONTENT_QUIET FALSE) - - FetchContent_Declare(gRPC -- GIT_REPOSITORY https://github.com/CanonicalLtd/grpc.git -- GIT_TAG e3acf245 -- GIT_SHALLOW TRUE -- GIT_SUBMODULES "third_party/abseil-cpp third_party/cares/cares third_party/protobuf third_party/re2 third_party/zlib" -- GIT_SUBMODULES_RECURSE false -- GIT_PROGRESS TRUE -+ DOWNLOAD_COMMAND true -+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/grpc - ) - set(gRPC_SSL_PROVIDER "package" CACHE STRING "Provider of ssl library") - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 52bd407f..a1100112 100644 --- a/tests/CMakeLists.txt diff --git a/pkgs/tools/virtualization/multipass/default.nix b/pkgs/tools/virtualization/multipass/default.nix index 851ee7cfd69d..c756ff94b5da 100644 --- a/pkgs/tools/virtualization/multipass/default.nix +++ b/pkgs/tools/virtualization/multipass/default.nix @@ -15,6 +15,8 @@ OVMF, pkg-config, qemu, + poco, + protobuf, qemu-utils, qtbase, qtwayland, @@ -26,7 +28,7 @@ let pname = "multipass"; - version = "1.13.1"; + version = "1.14.0"; # This is done here because a CMakeLists.txt from one of it's submodules tries # to modify a file, so we grab the source for the submodule here, copy it into @@ -46,7 +48,7 @@ stdenv.mkDerivation { owner = "canonical"; repo = "multipass"; rev = "refs/tags/v${version}"; - hash = "sha256-QttgWSuhxcuOyMNF9Ve1w0ftT41+hNz3WW5Vag/88X4="; + hash = "sha256-1g5Og4LkNujjT4KCXHmXaiTK58Bgb2KyYLKwTFFVEHE="; fetchSubmodules = true; leaveDotGit = true; postFetch = '' @@ -60,6 +62,8 @@ stdenv.mkDerivation { ./lxd_socket_path.patch ./cmake_no_fetch.patch ./cmake_warning.patch + ./vcpkg_no_install.patch + ./test_unreachable_call.patch ]; postPatch = '' @@ -68,6 +72,9 @@ stdenv.mkDerivation { --replace-fail "determine_version(MULTIPASS_VERSION)" "" \ --replace-fail 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")' + # Don't build/use vcpkg + rm -rf 3rd-party/vcpkg + # Patch the patch of the OVMF binaries to use paths from the nix store. substituteInPlace ./src/platform/backends/qemu/linux/qemu_platform_detail_linux.cpp \ --replace-fail "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \ @@ -97,6 +104,9 @@ stdenv.mkDerivation { EOF ''; + # We'll build the flutter application seperately using buildFlutterApplication + cmakeFlags = [ "-DMULTIPASS_ENABLE_FLUTTER_GUI=false" ]; + buildInputs = [ gtest libapparmor @@ -105,6 +115,8 @@ stdenv.mkDerivation { openssl qtbase qtwayland + poco.dev + protobuf ]; nativeBuildInputs = [ diff --git a/pkgs/tools/virtualization/multipass/test_unreachable_call.patch b/pkgs/tools/virtualization/multipass/test_unreachable_call.patch new file mode 100644 index 000000000000..a692362df8ef --- /dev/null +++ b/pkgs/tools/virtualization/multipass/test_unreachable_call.patch @@ -0,0 +1,12 @@ +diff --git a/tests/test_common_callbacks.cpp b/tests/test_common_callbacks.cpp +index ccae78e0..f9ab4423 100644 +--- a/tests/test_common_callbacks.cpp ++++ b/tests/test_common_callbacks.cpp +@@ -73,6 +73,7 @@ struct TestLoggingSpinnerCallbacks : public TestSpinnerCallbacks, public WithPar + default: + assert(false && "shouldn't be here"); + } ++ __builtin_unreachable(); + } + }; + diff --git a/pkgs/tools/virtualization/multipass/vcpkg_no_install.patch b/pkgs/tools/virtualization/multipass/vcpkg_no_install.patch new file mode 100644 index 000000000000..434cfbce31f3 --- /dev/null +++ b/pkgs/tools/virtualization/multipass/vcpkg_no_install.patch @@ -0,0 +1,83 @@ +diff --git a/3rd-party/CMakeLists.txt b/3rd-party/CMakeLists.txt +index 73291f6c..c1a38198 100644 +--- a/3rd-party/CMakeLists.txt ++++ b/3rd-party/CMakeLists.txt +@@ -4,6 +4,24 @@ if (MSVC) + add_compile_options(-wd5045) #Disable warning about Spectre mitigation + endif() + ++include(FetchContent) ++set(FETCHCONTENT_QUIET FALSE) ++ ++FetchContent_Declare(gRPC ++ DOWNLOAD_COMMAND true ++ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/grpc ++) ++ ++set(gRPC_SSL_PROVIDER "package" CACHE STRING "Provider of ssl library") ++ ++FetchContent_MakeAvailable(gRPC) ++ ++# Workaround for zlib placing its generated zconf.h file in the build dir, ++# and protobuf not knowing so finding the system version instead ++include_directories(${grpc_SOURCE_DIR}/third_party/zlib) ++ ++set_property(DIRECTORY ${grpc_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES) ++ + # Generates gRPC and protobuf C++ sources and headers from the given .proto files + # + # generate_grpc_cpp ( [...]) +@@ -34,9 +52,9 @@ function(generate_grpc_cpp SRCS DEST) + "${DEST}/${FIL_WE}.grpc.pb.h" + "${DEST}/${FIL_WE}.pb.cc" + "${DEST}/${FIL_WE}.pb.h" +- COMMAND $ +- ARGS --grpc_out=${DEST} --cpp_out=${DEST} --proto_path=${FIL_DIR} --proto_path=${grpc_SOURCE_DIR}/third_party/protobuf/src --plugin=protoc-gen-grpc=$ ${ABS_FIL} +- DEPENDS ${ABS_FIL} ++ COMMAND $ ++ ARGS --grpc_out=${DEST} --cpp_out=${DEST} --proto_path=${FIL_DIR} --proto_path=${grpc_SOURCE_DIR}/third_party/protobuf/src --plugin=protoc-gen-grpc=$ ${ABS_FIL} ++ DEPENDS ${ABS_FIL} protoc grpc_cpp_plugin + COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}" + VERBATIM) + endforeach () +@@ -47,9 +65,14 @@ endfunction() + + add_library(gRPC INTERFACE) + ++target_include_directories(gRPC INTERFACE ++ ${CMAKE_CURRENT_SOURCE_DIR}/grpc/include ++ ${CMAKE_CURRENT_SOURCE_DIR}/grpc/third_party/protobuf/src) ++ + target_link_libraries(gRPC INTERFACE +- gRPC::grpc++ +- protobuf::libprotobuf) ++ grpc++ ++ libprotobuf ++ zlibstatic) + + if (NOT MSVC) + target_compile_options(gRPC INTERFACE "-Wno-unused-parameter" "-Wno-non-virtual-dtor" "-Wno-pedantic") +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 18e47b74..d5bf5dea 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -49,9 +49,6 @@ if(NOT DEFINED VCPKG_BUILD_DEFAULT) + set(VCPKG_TARGET_TRIPLET "${VCPKG_HOST_ARCH}-${VCPKG_HOST_OS}-release") + endif() + +-set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/3rd-party/vcpkg/scripts/buildsystems/vcpkg.cmake" +- CACHE STRING "Vcpkg toolchain file") +- + project(Multipass) + + option(MULTIPASS_ENABLE_TESTS "Build tests" ON) +@@ -125,9 +122,6 @@ endif() + # OpenSSL config + find_package(OpenSSL REQUIRED) + +-# gRPC config +-find_package(gRPC CONFIG REQUIRED) +- + # Needs to be here before we set further compilation options + add_subdirectory(3rd-party) + From 3b3ed6c66909b4ee5eb7092a941025c1eafe9d12 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Wed, 24 Jul 2024 18:46:01 +0100 Subject: [PATCH 4/4] multipass: add comments to explain patches --- pkgs/tools/virtualization/multipass/default.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkgs/tools/virtualization/multipass/default.nix b/pkgs/tools/virtualization/multipass/default.nix index c756ff94b5da..053aad4edba4 100644 --- a/pkgs/tools/virtualization/multipass/default.nix +++ b/pkgs/tools/virtualization/multipass/default.nix @@ -59,10 +59,24 @@ stdenv.mkDerivation { }; patches = [ + # Multipass is usually only delivered as a snap package on Linux, and it expects that + # the LXD backend will also be delivered via a snap - in which cases the LXD socket + # is available at '/var/snap/lxd/...'. Here we patch to ensure that Multipass uses the + # LXD socket location on NixOS in '/var/lib/...' ./lxd_socket_path.patch + # The upstream cmake file attempts to fetch googletest using FetchContent, which fails + # in the Nix build environment. This patch disables the fetch in favour of providing + # the googletest library from nixpkgs. ./cmake_no_fetch.patch + # Ensures '-Wno-ignored-attributes' is supported by the compiler before attempting to build. ./cmake_warning.patch + # As of Multipass 1.14.0, the upstream started using vcpkg for grabbing C++ dependencies, + # which doesn't work in the nix build environment. This patch reverts that change, in favour + # of providing those dependencies manually in this derivation. ./vcpkg_no_install.patch + # The compiler flags used in nixpkgs surface an error in the test suite where an + # unreachable path was not annotated as such - this patch adds the annotation to ensure + # that the test suite passes in the nix build process. ./test_unreachable_call.patch ];