Skip to content

Commit

Permalink
multipass: build and install the flutter gui
Browse files Browse the repository at this point in the history
This commit breaks down multipass into two intermediate packages,
`multipassd` and `multipass-gui`. These are then packaged up with
`symlinkJoin` to work around some intricacies in the
`buildFlutterApplication` process which would otherwise be difficult
to patch.

The multipass repo is setup upstream such that the flutter app would
be built as part of the regular cmake process, but that can't work
here due to the fetching of the flutter dependencies. The upstream
multipass project builds `libdart_ffi.so`, which is needed in the
LD_LIBRARY_PATH of the GUI. Building the two derivations seperately
enables that to be done relatively simply.
  • Loading branch information
jnsgruk committed Dec 10, 2024
1 parent 908caf7 commit 3d6dba9
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 39 deletions.
79 changes: 79 additions & 0 deletions pkgs/by-name/mu/multipass/gui.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
commonMeta,
multipass_src,
multipassd,
version,

autoPatchelfHook,
flutter327,
gtkmm3,
keybinder3,
lib,
libayatana-appindicator,
libnotify,
protobuf,
protoc-gen-dart,
qt6,
}:
flutter327.buildFlutterApplication {
inherit version;
pname = "multipass-gui";
src = multipass_src;

sourceRoot = "${multipass_src.name}/src/client/gui";

pubspecLock = lib.importJSON ./pubspec.lock.json;

gitHashes = {
dartssh2 = "sha256-2pypKwurziwGLZYuGaxlS2lzN3UvJp3bRTvvYYxEqRI=";
hotkey_manager_linux = "sha256-aO0h94YZvgV/ggVupNw8GjyZsnXrq3qTHRDtuhNv3oI=";
system_info2 = "sha256-fly7E2vG+bQ/+QGzXk+DYba73RZccltdW2LpZGDKX60=";
tray_menu = "sha256-riiAiBEms+9ARog8i+MR1fto1Yqx+gwbBWyNbNq6VTM=";
window_size = "sha256-71PqQzf+qY23hTJvcm0Oye8tng3Asr42E2vfF1nBmVA=";
xterm = "sha256-h8vIonTPUVnNqZPk/A4ZV7EYCMyM0rrErL9ZOMe4ZBE=";
};

buildInputs = [
gtkmm3
keybinder3
libayatana-appindicator
libnotify
qt6.qtbase
qt6.qtwayland
];

nativeBuildInputs = [
autoPatchelfHook
protobuf
protoc-gen-dart
qt6.wrapQtAppsHook
];

preBuild = ''
mkdir -p lib/generated
# Generate the Dart gRPC code for the Multipass GUI.
${lib.getExe protobuf} \
--plugin=protoc-gen-dart=${lib.getExe protoc-gen-dart} \
--dart_out=grpc:lib/generated \
-I ../../rpc \
../../rpc/multipass.proto \
google/protobuf/timestamp.proto
'';

runtimeDependencies = [ multipassd ];

postFixup = ''
mv $out/bin/multipass_gui $out/bin/multipass.gui
install -Dm444 $out/app/multipass-gui/data/flutter_assets/assets/icon.png \
$out/share/icons/hicolor/256x256/apps/multipass.gui.png
cp $out/share/applications/multipass.gui.autostart.desktop \
$out/share/applications/multipass.gui.desktop
'';

meta = commonMeta // {
description = "Flutter frontend application for managing Ubuntu VMs";
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
commonMeta,
multipass_src,
version,

cmake,
dnsmasq,
fetchFromGitHub,
Expand All @@ -10,26 +14,20 @@
libapparmor,
libvirt,
libxml2,
nixosTests,
openssl,
OVMF,
pkg-config,
qemu,
poco,
protobuf,
qemu-utils,
qtbase,
qtwayland,
wrapQtAppsHook,
qemu,
qt6,
slang,
stdenv,
xterm,
}:

let
pname = "multipass";
version = "1.15.0-rc4";

# This is done here because a CMakeLists.txt from one of it's submodules tries
# to modify a file, so we grab the source for the submodule here, copy it into
# the source of the Multipass project which allows the modification to happen.
Expand All @@ -42,21 +40,9 @@ let
};
in
stdenv.mkDerivation {
inherit pname version;

src = fetchFromGitHub {
owner = "canonical";
repo = "multipass";
rev = "refs/tags/v${version}";
hash = "sha256-xwEM7Zsjkyi91oNyiX0i1mIJfBOoJ/4X47JBEqP8xYY=";
fetchSubmodules = true;
leaveDotGit = true;
postFetch = ''
# Workaround for https://github.com/NixOS/nixpkgs/issues/8567
cd $out
rm -rf .git
'';
};
inherit version;
pname = "multipassd";
src = multipass_src;

patches = [
# Multipass is usually only delivered as a snap package on Linux, and it expects that
Expand Down Expand Up @@ -86,6 +72,9 @@ stdenv.mkDerivation {
--replace-fail "determine_version(MULTIPASS_VERSION)" "" \
--replace-fail 'set(MULTIPASS_VERSION ''${MULTIPASS_VERSION})' 'set(MULTIPASS_VERSION "v${version}")'
# Don't build the GUI .desktop file, do that in the gui derivation instead
substituteInPlace ./CMakeLists.txt --replace-fail "add_subdirectory(data)" ""
# Don't build/use vcpkg
rm -rf 3rd-party/vcpkg
Expand Down Expand Up @@ -118,7 +107,7 @@ stdenv.mkDerivation {
EOF
'';

# We'll build the flutter application seperately using buildFlutterApplication
# We'll build the flutter application separately using buildFlutterApplication
cmakeFlags = [ "-DMULTIPASS_ENABLE_FLUTTER_GUI=false" ];

buildInputs = [
Expand All @@ -127,18 +116,18 @@ stdenv.mkDerivation {
libvirt
libxml2
openssl
qtbase
qtwayland
poco.dev
protobuf
qt6.qtbase
qt6.qtwayland
];

nativeBuildInputs = [
cmake
git
pkg-config
qt6.wrapQtAppsHook
slang
wrapQtAppsHook
];

nativeCheckInputs = [ gtest ];
Expand All @@ -157,15 +146,7 @@ stdenv.mkDerivation {
}
'';

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" ];
meta = commonMeta // {
description = "Backend server & client for managing on-demand Ubuntu VMs";
};
}
58 changes: 58 additions & 0 deletions pkgs/by-name/mu/multipass/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
callPackage,
fetchFromGitHub,
lib,
nixosTests,
stdenv,
symlinkJoin,
}:

let
name = "multipass";
version = "1.15.0-rc4";

multipass_src = fetchFromGitHub {
owner = "canonical";
repo = "multipass";
rev = "refs/tags/v${version}";
hash = "sha256-RoOCh1winDs7BZwyduZziHj6EMe3sGMYonkA757UrIU=";
fetchSubmodules = true;
};

commonMeta = {
homepage = "https://multipass.run";
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [ jnsgruk ];
platforms = [ "x86_64-linux" ];
};

multipassd = callPackage ./multipassd.nix {
inherit commonMeta multipass_src version;
};

multipass-gui = callPackage ./gui.nix {
inherit
commonMeta
multipass_src
multipassd
version
;
};
in
symlinkJoin {
inherit version;
pname = name;

paths = [
multipassd
multipass-gui
];

passthru.tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
inherit (nixosTests) multipass;
};

meta = commonMeta // {
description = "Ubuntu VMs on demand for any workstation";
};
}
1 change: 1 addition & 0 deletions pkgs/by-name/mu/multipass/pubspec.lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4431,8 +4431,6 @@ with pkgs;

mtr-gui = callPackage ../tools/networking/mtr { withGtk = true; };

multipass = qt6Packages.callPackage ../tools/virtualization/multipass { };

multitran = recurseIntoAttrs (let callPackage = newScope pkgs.multitran; in {
multitrandata = callPackage ../tools/text/multitran/data { };

Expand Down

0 comments on commit 3d6dba9

Please sign in to comment.