31 # This is done here because a CMakeLists.txt from one of it's submodules tries
32 # to modify a file, so we grab the source for the submodule here, copy it into
33 # the source of the Multipass project which allows the modification to happen.
34 grpc_src = fetchFromGitHub {
37 rev = "ba8e7f72a57b9e0b25783a4d3cea58c79379f194";
38 hash = "sha256-DS1UNLCUdbipn5w4p2aVa8LgHHhdJiAfzfEdIXNO69o=";
39 fetchSubmodules = true;
48 # Multipass is usually only delivered as a snap package on Linux, and it expects that
49 # the LXD backend will also be delivered via a snap - in which cases the LXD socket
50 # is available at '/var/snap/lxd/...'. Here we patch to ensure that Multipass uses the
51 # LXD socket location on NixOS in '/var/lib/...'
52 ./lxd_socket_path.patch
53 # The upstream cmake file attempts to fetch googletest using FetchContent, which fails
54 # in the Nix build environment. This patch disables the fetch in favour of providing
55 # the googletest library from nixpkgs.
56 ./cmake_no_fetch.patch
57 # Ensures '-Wno-ignored-attributes' is supported by the compiler before attempting to build.
59 # As of Multipass 1.14.0, the upstream started using vcpkg for grabbing C++ dependencies,
60 # which doesn't work in the nix build environment. This patch reverts that change, in favour
61 # of providing those dependencies manually in this derivation.
62 ./vcpkg_no_install.patch
63 # The compiler flags used in nixpkgs surface an error in the test suite where an
64 # unreachable path was not annotated as such - this patch adds the annotation to ensure
65 # that the test suite passes in the nix build process.
66 ./test_unreachable_call.patch
70 # Make sure the version is reported correctly in the compiled binary.
71 substituteInPlace ./CMakeLists.txt \
72 --replace-fail "determine_version(MULTIPASS_VERSION)" "" \
73 --replace-fail 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")'
75 # Don't build the GUI .desktop file, do that in the gui derivation instead
76 substituteInPlace ./CMakeLists.txt --replace-fail "add_subdirectory(data)" ""
78 # Don't build/use vcpkg
79 rm -rf 3rd-party/vcpkg
81 # Patch the patch of the OVMF binaries to use paths from the nix store.
82 substituteInPlace ./src/platform/backends/qemu/linux/qemu_platform_detail_linux.cpp \
83 --replace-fail "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \
84 --replace-fail "QEMU_EFI.fd" "${OVMF.fd}/FV/QEMU_EFI.fd"
86 # Copy the grpc submodule we fetched into the source code.
87 cp -r --no-preserve=mode ${grpc_src} 3rd-party/grpc
89 # Configure CMake to use gtest from the nix store since we disabled fetching from the internet.
90 cat >> tests/CMakeLists.txt <<'EOF'
91 add_library(gtest INTERFACE)
92 target_include_directories(gtest INTERFACE ${gtest.dev}/include)
93 target_link_libraries(gtest INTERFACE ${gtest}/lib/libgtest.so ''${CMAKE_THREAD_LIBS_INIT})
94 add_dependencies(gtest GMock)
96 add_library(gtest_main INTERFACE)
97 target_include_directories(gtest_main INTERFACE ${gtest.dev}/include)
98 target_link_libraries(gtest_main INTERFACE ${gtest}/lib/libgtest_main.so gtest)
100 add_library(gmock INTERFACE)
101 target_include_directories(gmock INTERFACE ${gtest.dev}/include)
102 target_link_libraries(gmock INTERFACE ${gtest}/lib/libgmock.so gtest)
104 add_library(gmock_main INTERFACE)
105 target_include_directories(gmock_main INTERFACE ${gtest.dev}/include)
106 target_link_libraries(gmock_main INTERFACE ${gtest}/lib/libgmock_main.so gmock gtest_main)
110 # We'll build the flutter application separately using buildFlutterApplication
111 cmakeFlags = [ "-DMULTIPASS_ENABLE_FLUTTER_GUI=false" ];
125 nativeBuildInputs = [
133 nativeCheckInputs = [ gtest ];
136 wrapProgram $out/bin/multipassd --prefix PATH : ${
149 meta = commonMeta // {
150 description = "Backend server & client for managing on-demand Ubuntu VMs";