nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ cmake
2, dnsmasq
3, fetchFromGitHub
4, git
5, gtest
6, iproute2
7, iptables
8, lib
9, libapparmor
10, libvirt
11, libxml2
12, nixosTests
13, openssl
14, OVMF
15, pkg-config
16, qemu
17, qemu-utils
18, qtbase
19, qtx11extras
20, slang
21, stdenv
22, wrapQtAppsHook
23, xterm
24}:
25
26let
27 pname = "multipass";
28 version = "1.12.0";
29
30 # This is done here because a CMakeLists.txt from one of it's submodules tries
31 # to modify a file, so we grab the source for the submodule here, copy it into
32 # the source of the Multipass project which allows the modification to happen.
33 grpc_src = fetchFromGitHub {
34 owner = "CanonicalLtd";
35 repo = "grpc";
36 rev = "ba8e7f72a57b9e0b25783a4d3cea58c79379f194";
37 hash = "sha256-DS1UNLCUdbipn5w4p2aVa8LgHHhdJiAfzfEdIXNO69o=";
38 fetchSubmodules = true;
39 };
40in
41stdenv.mkDerivation
42{
43 inherit pname version;
44
45 src = fetchFromGitHub {
46 owner = "canonical";
47 repo = "multipass";
48 rev = "refs/tags/v${version}";
49 sha256 = "sha256-CwyiLkpyTfn4734ESnHHWwiMdy3AP0BuQv6Uc1nTAuU=";
50 fetchSubmodules = true;
51 };
52
53 patches = [
54 ./lxd_socket_path.patch
55 ./cmake_no_fetch.patch
56 ];
57
58 postPatch = ''
59 # Make sure the version is reported correctly in the compiled binary.
60 substituteInPlace ./CMakeLists.txt \
61 --replace "determine_version(MULTIPASS_VERSION)" "" \
62 --replace 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")'
63
64 # Patch the patch of the OVMF binaries to use paths from the nix store.
65 substituteInPlace ./src/platform/backends/qemu/linux/qemu_platform_detail_linux.cpp \
66 --replace "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \
67 --replace "QEMU_EFI.fd" "${OVMF.fd}/FV/QEMU_EFI.fd"
68
69 # Copy the grpc submodule we fetched into the source code.
70 cp -r --no-preserve=mode ${grpc_src} 3rd-party/grpc
71
72 # Configure CMake to use gtest from the nix store since we disabled fetching from the internet.
73 cat >> tests/CMakeLists.txt <<'EOF'
74 add_library(gtest INTERFACE)
75 target_include_directories(gtest INTERFACE ${gtest.dev}/include)
76 target_link_libraries(gtest INTERFACE ${gtest}/lib/libgtest.so ''${CMAKE_THREAD_LIBS_INIT})
77 add_dependencies(gtest GMock)
78
79 add_library(gtest_main INTERFACE)
80 target_include_directories(gtest_main INTERFACE ${gtest.dev}/include)
81 target_link_libraries(gtest_main INTERFACE ${gtest}/lib/libgtest_main.so gtest)
82
83 add_library(gmock INTERFACE)
84 target_include_directories(gmock INTERFACE ${gtest.dev}/include)
85 target_link_libraries(gmock INTERFACE ${gtest}/lib/libgmock.so gtest)
86
87 add_library(gmock_main INTERFACE)
88 target_include_directories(gmock_main INTERFACE ${gtest.dev}/include)
89 target_link_libraries(gmock_main INTERFACE ${gtest}/lib/libgmock_main.so gmock gtest_main)
90 EOF
91 '';
92
93 buildInputs = [
94 gtest
95 libapparmor
96 libvirt
97 libxml2
98 openssl
99 qtbase
100 qtx11extras
101 ];
102
103 nativeBuildInputs = [
104 cmake
105 git
106 pkg-config
107 slang
108 wrapQtAppsHook
109 ];
110
111 nativeCheckInputs = [ gtest ];
112
113 postInstall = ''
114 wrapProgram $out/bin/multipassd --prefix PATH : ${lib.makeBinPath [
115 dnsmasq
116 iproute2
117 iptables
118 OVMF.fd
119 qemu
120 qemu-utils
121 xterm
122 ]}
123 '';
124
125 passthru.tests = {
126 multipass = nixosTests.multipass;
127 };
128
129 meta = with lib; {
130 description = "Ubuntu VMs on demand for any workstation.";
131 homepage = "https://multipass.run";
132 license = licenses.gpl3Plus;
133 maintainers = with maintainers; [ jnsgruk ];
134 platforms = [ "x86_64-linux" ];
135 };
136}