diff options
author | Anderson Torres <torres.anderson.85@protonmail.com> | 2023-02-04 09:03:54 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-04 09:03:54 -0300 |
commit | bc0944c06f75a65817a0640bdb67f3b1b4bb0af2 (patch) | |
tree | 4f869e3ae88e98c51e9fe0413ef6255c6939a4bb | |
parent | 199753fafc26559be5375525f45aca02cd245513 (diff) | |
parent | 978259361b723ffe808a0c4a35dd45b9f9c4b402 (diff) |
Merge pull request #214193 from jnsgruk/add-multipass-pkg
multipass: init at 1.11.0
-rw-r--r-- | maintainers/maintainer-list.nix | 6 | ||||
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/virtualisation/multipass.nix | 61 | ||||
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/multipass.nix | 37 | ||||
-rw-r--r-- | pkgs/tools/virtualization/multipass/default.nix | 128 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 2 |
7 files changed, 236 insertions, 0 deletions
diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index b8df8e1616b5..07ce857381b4 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -7015,6 +7015,12 @@ githubId = 2308444; name = "Joshua Gilman"; }; + jnsgruk = { + email = "jon@sgrs.uk"; + github = "jnsgruk"; + githubId = 668505; + name = "Jon Seager"; + }; jo1gi = { email = "joakimholm@protonmail.com"; github = "jo1gi"; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2757a196555e..111eee47480f 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1365,6 +1365,7 @@ ./virtualisation/lxc.nix ./virtualisation/lxcfs.nix ./virtualisation/lxd.nix + ./virtualisation/multipass.nix ./virtualisation/nixos-containers.nix ./virtualisation/oci-containers.nix ./virtualisation/openstack-options.nix diff --git a/nixos/modules/virtualisation/multipass.nix b/nixos/modules/virtualisation/multipass.nix new file mode 100644 index 000000000000..d066932b6120 --- /dev/null +++ b/nixos/modules/virtualisation/multipass.nix @@ -0,0 +1,61 @@ +{ config +, lib +, pkgs +, ... +}: + +let + cfg = config.virtualisation.multipass; +in +{ + options = { + virtualisation.multipass = { + enable = lib.mkEnableOption (lib.mdDoc '' + Multipass, a simple manager for virtualised Ubuntu instances. + ''); + + logLevel = lib.mkOption { + type = lib.types.enum [ "error" "warning" "info" "debug" "trace" ]; + default = "debug"; + description = lib.mdDoc '' + The logging verbosity of the multipassd binary. + ''; + }; + + package = lib.mkPackageOptionMD pkgs "multipass" { }; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + + systemd.services.multipass = { + description = "Multipass orchestrates virtual Ubuntu instances."; + + wantedBy = [ "multi-user.target" ]; + wants = [ "network.target" ]; + after = [ "network.target" ]; + + environment = { + "XDG_DATA_HOME" = "/var/lib/multipass/data"; + "XDG_CACHE_HOME" = "/var/lib/multipass/cache"; + "XDG_CONFIG_HOME" = "/var/lib/multipass/config"; + }; + + serviceConfig = { + ExecStart = "${cfg.package}/bin/multipassd --logger platform --verbosity ${cfg.logLevel}"; + SyslogIdentifer = "multipassd"; + Restart = "on-failure"; + TimeoutStopSec = 300; + Type = "simple"; + + WorkingDirectory = "/var/lib/multipass"; + + StateDirectory = "multipass"; + StateDirectoryMode = "0750"; + CacheDirectory = "multipass"; + CacheDirectoryMode = "0750"; + }; + }; + }; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 1fc8bb777db0..a23a0413160e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -412,6 +412,7 @@ in { mpd = handleTest ./mpd.nix {}; mpv = handleTest ./mpv.nix {}; mtp = handleTest ./mtp.nix {}; + multipass = handleTest ./multipass.nix {}; mumble = handleTest ./mumble.nix {}; musescore = handleTest ./musescore.nix {}; munin = handleTest ./munin.nix {}; diff --git a/nixos/tests/multipass.nix b/nixos/tests/multipass.nix new file mode 100644 index 000000000000..0980e9195f5a --- /dev/null +++ b/nixos/tests/multipass.nix @@ -0,0 +1,37 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: + +let + multipass-image = import ../release.nix { + configuration = { + # Building documentation makes the test unnecessarily take a longer time: + documentation.enable = lib.mkForce false; + }; + }; + +in +{ + name = "multipass"; + + meta.maintainers = [ lib.maintainers.jnsgruk ]; + + nodes.machine = { lib, ... }: { + virtualisation = { + cores = 1; + memorySize = 1024; + diskSize = 4096; + + multipass.enable = true; + }; + }; + + testScript = '' + machine.wait_for_unit("sockets.target") + machine.wait_for_unit("multipass.service") + machine.wait_for_file("/var/lib/multipass/data/multipassd/network/multipass_subnet") + + # Wait for Multipass to settle + machine.sleep(1) + + machine.succeed("multipass list") + ''; +}) diff --git a/pkgs/tools/virtualization/multipass/default.nix b/pkgs/tools/virtualization/multipass/default.nix new file mode 100644 index 000000000000..d8d003b2064f --- /dev/null +++ b/pkgs/tools/virtualization/multipass/default.nix @@ -0,0 +1,128 @@ +{ cmake +, dnsmasq +, fetchFromGitHub +, git +, gtest +, iproute2 +, iptables +, lib +, libapparmor +, libvirt +, libxml2 +, nixosTests +, openssl +, OVMF +, pkg-config +, qemu +, qemu-utils +, qtbase +, qtx11extras +, slang +, stdenv +, wrapQtAppsHook +, xterm +}: + +let + pname = "multipass"; + version = "1.11.0"; +in +stdenv.mkDerivation { + inherit pname version; + + src = fetchFromGitHub { + owner = "canonical"; + repo = "multipass"; + rev = "refs/tags/v${version}"; + sha256 = "sha256-2d8piIIecoSI3BfOgAVlXl5P2UYDaNlxUgHXWbnSdkg="; + fetchSubmodules = true; + }; + + preConfigure = '' + substituteInPlace ./CMakeLists.txt \ + --replace "determine_version(MULTIPASS_VERSION)" "" \ + --replace 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")' + + 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" + ''; + + postPatch = '' + # Patch all of the places where Multipass expects the LXD socket to be provided by a snap + substituteInPlace ./src/network/network_access_manager.cpp \ + --replace "/var/snap/lxd/common/lxd/unix.socket" "/var/lib/lxd/unix.socket" + + substituteInPlace ./src/platform/backends/lxd/lxd_virtual_machine.cpp \ + --replace "/var/snap/lxd/common/lxd/unix.socket" "/var/lib/lxd/unix.socket" + + substituteInPlace ./src/platform/backends/lxd/lxd_request.h \ + --replace "/var/snap/lxd/common/lxd/unix.socket" "/var/lib/lxd/unix.socket" + + substituteInPlace ./tests/CMakeLists.txt \ + --replace "FetchContent_MakeAvailable(googletest)" "" + + cat >> tests/CMakeLists.txt <<'EOF' + add_library(gtest INTERFACE) + target_include_directories(gtest INTERFACE ${gtest.dev}/include) + target_link_libraries(gtest INTERFACE ${gtest}/lib/libgtest.so ''${CMAKE_THREAD_LIBS_INIT}) + add_dependencies(gtest GMock) + + add_library(gtest_main INTERFACE) + target_include_directories(gtest_main INTERFACE ${gtest.dev}/include) + target_link_libraries(gtest_main INTERFACE ${gtest}/lib/libgtest_main.so gtest) + + add_library(gmock INTERFACE) + target_include_directories(gmock INTERFACE ${gtest.dev}/include) + target_link_libraries(gmock INTERFACE ${gtest}/lib/libgmock.so gtest) + + add_library(gmock_main INTERFACE) + target_include_directories(gmock_main INTERFACE ${gtest.dev}/include) + target_link_libraries(gmock_main INTERFACE ${gtest}/lib/libgmock_main.so gmock gtest_main) + EOF + ''; + + buildInputs = [ + gtest + libapparmor + libvirt + libxml2 + openssl + qtbase + qtx11extras + ]; + + nativeBuildInputs = [ + cmake + git + pkg-config + slang + wrapQtAppsHook + ]; + + nativeCheckInputs = [ gtest ]; + + postInstall = '' + wrapProgram $out/bin/multipassd --prefix PATH : ${lib.makeBinPath [ + dnsmasq + iproute2 + iptables + OVMF.fd + qemu + qemu-utils + xterm + ]} + ''; + + passthru.tests = { + multipass = nixosTests.multipass; + }; + + meta = with lib; { + description = "Ubuntu VMs on demand for any workstation."; + homepage = "https://multipass.run"; + license = licenses.gpl3Plus; + maintainers = with maintainers; [ jnsgruk ]; + platforms = [ "x86_64-linux" ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e1e93ff15b16..63e848cd8ab7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -9870,6 +9870,8 @@ with pkgs; mubeng = callPackage ../tools/networking/mubeng { }; + multipass = libsForQt5.callPackage ../tools/virtualization/multipass { }; + multitime = callPackage ../tools/misc/multitime { }; sta = callPackage ../tools/misc/sta {}; |