at 23.11-beta 143 lines 3.7 kB view raw
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.2"; 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 = "e3acf245"; 37 hash = "sha256-tDc2iGxIV68Yi4RL8ES4yglJNlu8yH6FlpVvZoWjoXk="; 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 hash = "sha256-1k0jbYMwfYuHmM/Cm76sbo3+mN6WypALMQBwlZ+9d+c="; 50 fetchSubmodules = true; 51 leaveDotGit = true; 52 postFetch = '' 53 # Workaround for https://github.com/NixOS/nixpkgs/issues/8567 54 cd $out 55 rm -rf .git 56 ''; 57 }; 58 59 patches = [ 60 ./lxd_socket_path.patch 61 ./cmake_no_fetch.patch 62 ./cmake_warning.patch 63 ]; 64 65 postPatch = '' 66 # Make sure the version is reported correctly in the compiled binary. 67 substituteInPlace ./CMakeLists.txt \ 68 --replace "determine_version(MULTIPASS_VERSION)" "" \ 69 --replace 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")' 70 71 # Patch the patch of the OVMF binaries to use paths from the nix store. 72 substituteInPlace ./src/platform/backends/qemu/linux/qemu_platform_detail_linux.cpp \ 73 --replace "OVMF.fd" "${OVMF.fd}/FV/OVMF.fd" \ 74 --replace "QEMU_EFI.fd" "${OVMF.fd}/FV/QEMU_EFI.fd" 75 76 # Copy the grpc submodule we fetched into the source code. 77 cp -r --no-preserve=mode ${grpc_src} 3rd-party/grpc 78 79 # Configure CMake to use gtest from the nix store since we disabled fetching from the internet. 80 cat >> tests/CMakeLists.txt <<'EOF' 81 add_library(gtest INTERFACE) 82 target_include_directories(gtest INTERFACE ${gtest.dev}/include) 83 target_link_libraries(gtest INTERFACE ${gtest}/lib/libgtest.so ''${CMAKE_THREAD_LIBS_INIT}) 84 add_dependencies(gtest GMock) 85 86 add_library(gtest_main INTERFACE) 87 target_include_directories(gtest_main INTERFACE ${gtest.dev}/include) 88 target_link_libraries(gtest_main INTERFACE ${gtest}/lib/libgtest_main.so gtest) 89 90 add_library(gmock INTERFACE) 91 target_include_directories(gmock INTERFACE ${gtest.dev}/include) 92 target_link_libraries(gmock INTERFACE ${gtest}/lib/libgmock.so gtest) 93 94 add_library(gmock_main INTERFACE) 95 target_include_directories(gmock_main INTERFACE ${gtest.dev}/include) 96 target_link_libraries(gmock_main INTERFACE ${gtest}/lib/libgmock_main.so gmock gtest_main) 97 EOF 98 ''; 99 100 buildInputs = [ 101 gtest 102 libapparmor 103 libvirt 104 libxml2 105 openssl 106 qtbase 107 qtx11extras 108 ]; 109 110 nativeBuildInputs = [ 111 cmake 112 git 113 pkg-config 114 slang 115 wrapQtAppsHook 116 ]; 117 118 nativeCheckInputs = [ gtest ]; 119 120 postInstall = '' 121 wrapProgram $out/bin/multipassd --prefix PATH : ${lib.makeBinPath [ 122 dnsmasq 123 iproute2 124 iptables 125 OVMF.fd 126 qemu 127 qemu-utils 128 xterm 129 ]} 130 ''; 131 132 passthru.tests = { 133 multipass = nixosTests.multipass; 134 }; 135 136 meta = with lib; { 137 description = "Ubuntu VMs on demand for any workstation."; 138 homepage = "https://multipass.run"; 139 license = licenses.gpl3Plus; 140 maintainers = with maintainers; [ jnsgruk ]; 141 platforms = [ "x86_64-linux" ]; 142 }; 143}