From c792c60b8a97daa7efe41a6e4954497ae410e0c1 Mon Sep 17 00:00:00 2001 From: Friedrich Altheide <11352905+FriedrichAltheide@users.noreply.github.com> Date: Wed, 25 Dec 2024 22:09:11 +0100 Subject: [PATCH] virtualboxGuestAdditions: Additional 7.1.4 fixes (#366080) * virtualboxGuestAddtitions: Load required dynamic libs * virtualboxGuestAdditions: Remove unused code * virtualboxGuestAdditions: introduce verbose logging option * virtualboxGuestAdditions: only load vboxsf if enabled in module options --- .../virtualisation/virtualbox-guest.nix | 45 ++++++++++++++----- .../virtualbox/guest-additions/default.nix | 18 ++++++-- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/nixos/modules/virtualisation/virtualbox-guest.nix b/nixos/modules/virtualisation/virtualbox-guest.nix index 48eb4528a232f..68731ddc17832 100644 --- a/nixos/modules/virtualisation/virtualbox-guest.nix +++ b/nixos/modules/virtualisation/virtualbox-guest.nix @@ -9,7 +9,7 @@ let cfg = config.virtualisation.virtualbox.guest; kernel = config.boot.kernelPackages; - mkVirtualBoxUserService = serviceArgs: { + mkVirtualBoxUserService = serviceArgs: verbose: { description = "VirtualBox Guest User Services ${serviceArgs}"; wantedBy = [ "graphical-session.target" ]; @@ -24,12 +24,22 @@ let # Check if the display environment is ready, otherwise fail preStart = "${pkgs.bash}/bin/bash -c \"if [ -z $DISPLAY ]; then exit 1; fi\""; serviceConfig = { - ExecStart = "@${kernel.virtualboxGuestAdditions}/bin/VBoxClient --foreground ${serviceArgs}"; + ExecStart = + "@${kernel.virtualboxGuestAdditions}/bin/VBoxClient" + + (lib.strings.optionalString verbose " --verbose") + + " --foreground ${serviceArgs}"; # Wait after a failure, hoping that the display environment is ready after waiting RestartSec = 2; Restart = "always"; }; }; + + mkVirtualBoxUserX11OnlyService = + serviceArgs: verbose: + (mkVirtualBoxUserService serviceArgs verbose) + // { + unitConfig.ConditionEnvironment = "XDG_SESSION_TYPE=x11"; + }; in { imports = [ @@ -73,6 +83,18 @@ in type = lib.types.bool; description = "Whether to enable drag and drop support."; }; + + verbose = lib.mkOption { + default = false; + type = lib.types.bool; + description = "Whether to verbose logging for guest services."; + }; + + vboxsf = lib.mkOption { + default = true; + type = lib.types.bool; + description = "Whether to load vboxsf"; + }; }; ###### implementation @@ -91,11 +113,6 @@ in boot.extraModulePackages = [ kernel.virtualboxGuestAdditions ]; - boot.supportedFilesystems = [ "vboxsf" ]; - boot.initrd.supportedFilesystems = [ "vboxsf" ]; - - users.groups.vboxsf.gid = config.ids.gids.vboxsf; - systemd.services.virtualbox = { description = "VirtualBox Guest Services"; @@ -117,16 +134,22 @@ in SUBSYSTEM=="misc", KERNEL=="vboxguest", TAG+="systemd" ''; - systemd.user.services.virtualboxClientVmsvga = mkVirtualBoxUserService "--vmsvga-session"; + systemd.user.services.virtualboxClientVmsvga = mkVirtualBoxUserService "--vmsvga-session" cfg.verbose; } + (lib.mkIf cfg.vboxsf { + boot.supportedFilesystems = [ "vboxsf" ]; + boot.initrd.supportedFilesystems = [ "vboxsf" ]; + + users.groups.vboxsf.gid = config.ids.gids.vboxsf; + }) (lib.mkIf cfg.clipboard { - systemd.user.services.virtualboxClientClipboard = mkVirtualBoxUserService "--clipboard"; + systemd.user.services.virtualboxClientClipboard = mkVirtualBoxUserService "--clipboard" cfg.verbose; }) (lib.mkIf cfg.seamless { - systemd.user.services.virtualboxClientSeamless = mkVirtualBoxUserService "--seamless"; + systemd.user.services.virtualboxClientSeamless = mkVirtualBoxUserX11OnlyService "--seamless" cfg.verbose; }) (lib.mkIf cfg.dragAndDrop { - systemd.user.services.virtualboxClientDragAndDrop = mkVirtualBoxUserService "--draganddrop"; + systemd.user.services.virtualboxClientDragAndDrop = mkVirtualBoxUserService "--draganddrop" cfg.verbose; }) ] ); diff --git a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix index e213860a75849..547b6ac551720 100644 --- a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix +++ b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix @@ -8,14 +8,12 @@ zlib, patchelf, makeWrapper, + wayland, + libX11, }: let virtualBoxNixGuestAdditionsBuilder = callPackage ./builder.nix { }; - # Forced to 1.18; vboxvideo doesn't seem to provide any newer ABI, - # and nixpkgs doesn't support older ABIs anymore. - xserverABI = "118"; - # Specifies how to patch binaries to make sure that libraries loaded using # dlopen are found. We grep binaries for specific library names and patch # RUNPATH in matching binaries to contain the needed library paths. @@ -32,6 +30,18 @@ let name = "libXrandr.so"; pkg = xorg.libXrandr; } + { + name = "libwayland-client.so"; + pkg = wayland; + } + { + name = "libX11.so"; + pkg = libX11; + } + { + name = "libXt.so"; + pkg = xorg.libXt; + } ]; in stdenv.mkDerivation {