snac2: 2.68 -> 2.70 (#379043)
[NixPkgs.git] / pkgs / by-name / mu / multipass / multipassd.nix
blob2cc6f9b6fb06cf6f9ac0fee4718d1e190448b780
2   commonMeta,
3   multipass_src,
4   version,
6   cmake,
7   dnsmasq,
8   fetchFromGitHub,
9   git,
10   gtest,
11   iproute2,
12   iptables,
13   lib,
14   libapparmor,
15   libvirt,
16   libxml2,
17   openssl,
18   OVMF,
19   pkg-config,
20   poco,
21   protobuf,
22   qemu-utils,
23   qemu,
24   qt6,
25   slang,
26   stdenv,
27   xterm,
30 let
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 {
35     owner = "canonical";
36     repo = "grpc";
37     rev = "ba8e7f72a57b9e0b25783a4d3cea58c79379f194";
38     hash = "sha256-DS1UNLCUdbipn5w4p2aVa8LgHHhdJiAfzfEdIXNO69o=";
39     fetchSubmodules = true;
40   };
42 stdenv.mkDerivation {
43   inherit version;
44   pname = "multipassd";
45   src = multipass_src;
47   patches = [
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.
58     ./cmake_warning.patch
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
67   ];
69   postPatch = ''
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)
107     EOF
108   '';
110   # We'll build the flutter application separately using buildFlutterApplication
111   cmakeFlags = [ "-DMULTIPASS_ENABLE_FLUTTER_GUI=false" ];
113   buildInputs = [
114     gtest
115     libapparmor
116     libvirt
117     libxml2
118     openssl
119     poco.dev
120     protobuf
121     qt6.qtbase
122     qt6.qtwayland
123   ];
125   nativeBuildInputs = [
126     cmake
127     git
128     pkg-config
129     qt6.wrapQtAppsHook
130     slang
131   ];
133   nativeCheckInputs = [ gtest ];
135   postInstall = ''
136     wrapProgram $out/bin/multipassd --prefix PATH : ${
137       lib.makeBinPath [
138         dnsmasq
139         iproute2
140         iptables
141         OVMF.fd
142         qemu
143         qemu-utils
144         xterm
145       ]
146     }
147   '';
149   meta = commonMeta // {
150     description = "Backend server & client for managing on-demand Ubuntu VMs";
151   };